1 /** 2 ****************************************************************************** 3 * @file lib_i2c.c 4 * @author Application Team 5 * @version V4.5.0 6 * @date 2019-05-14 7 * @brief IIC library. 8 ****************************************************************************** 9 * @attention 10 * 11 ****************************************************************************** 12 */ 13 #include "lib_i2c.h" 14 15 //registers default reset values 16 #define I2C_ADDR_RSTValue 0 17 #define I2C_CTRL_RSTValue 0 18 #define I2C_CTRL2_RSTValue 0 19 20 /* Private Functions -------------------------------------------------------- */ 21 static uint16_t I2C_CheckState(uint8_t State); 22 static void I2C_SendStart(void); 23 static void I2C_SendRestart(void); 24 static void I2C_SendByte(uint8_t dat); 25 static void I2C_SendStop(void); 26 static uint8_t I2C_ReceiveByte(void); 27 static void I2C_ClearBus(uint32_t remap); 28 static void I2C_WaitForCrossPage(uint8_t sla); 29 30 /** 31 * @brief Check required state. 32 * @param State: 33 Required state. 34 * @retval 0: state OK 35 !0: state Error, [15:8]Required status code, [7:0] real status code. 36 */ I2C_CheckState(uint8_t State)37static uint16_t I2C_CheckState(uint8_t State) 38 { 39 uint16_t ret; 40 if (I2C_GetStatusCode() != State) 41 { 42 ret = (State<<8)|(I2C_GetStatusCode()); 43 return ret; 44 } 45 else 46 { 47 return 0; 48 } 49 } 50 51 /** 52 * @brief Send start signal. 53 * @param None 54 * @retval None 55 */ I2C_SendStart(void)56static void I2C_SendStart(void) 57 { 58 I2C_GenerateSTART(ENABLE); 59 while (I2C_GetINTStatus() == 0); 60 I2C_GenerateSTART(DISABLE); 61 } 62 63 /** 64 * @brief Send restart signal. 65 * @param None 66 * @retval None 67 */ I2C_SendRestart(void)68static void I2C_SendRestart(void) 69 { 70 I2C_GenerateSTART(ENABLE); 71 I2C_ClearINTStatus(); 72 while (I2C_GetINTStatus() == 0); 73 I2C_GenerateSTART(DISABLE); 74 } 75 76 /** 77 * @brief Send stop signal. 78 * @param None 79 * @retval None 80 */ I2C_SendStop(void)81static void I2C_SendStop(void) 82 { 83 I2C_GenerateSTOP(ENABLE); 84 I2C_ClearINTStatus(); 85 I2C_GenerateSTOP(DISABLE); 86 } 87 88 /** 89 * @brief Send data. 90 * @param dat:data to send. 91 * @retval None 92 */ I2C_SendByte(uint8_t dat)93static void I2C_SendByte(uint8_t dat) 94 { 95 I2C_SendData(dat); 96 I2C_ClearINTStatus(); 97 while (I2C_GetINTStatus() == 0); 98 } 99 100 /** 101 * @brief Receive byte. 102 * @param None 103 * @retval Byte received 104 */ I2C_ReceiveByte(void)105static uint8_t I2C_ReceiveByte(void) 106 { 107 I2C_ClearINTStatus(); 108 while (I2C_GetINTStatus() == 0); 109 return I2C_ReceiveData(); 110 } 111 112 /** 113 * @brief Wait for cross page operation done. 114 * @param None 115 * @retval None 116 */ I2C_WaitForCrossPage(uint8_t sla)117static void I2C_WaitForCrossPage(uint8_t sla) 118 { 119 do 120 { 121 I2C_SendRestart(); 122 I2C_SendByte(sla); //device address 123 }while (I2C_GetStatusCode() !=0x18); 124 I2C_SendStop(); //stop 125 } 126 I2C_ClearBus(uint32_t remap)127static void I2C_ClearBus(uint32_t remap) 128 { 129 __IO uint8_t i, j; 130 131 if (remap) // I2C remap enable, SCL IOC4 132 { 133 GPIOC->DAT &= ~BIT4; 134 GPIOC->ATT |= BIT4; 135 GPIOC->OEN &= ~BIT4; 136 for (i=0; i<9; i++) 137 { 138 GPIOC->DAT |= BIT4; 139 for (j=0; j<100; j++) 140 __NOP(); 141 GPIOC->DAT &= ~BIT4; 142 for (j=0; j<100; j++) 143 __NOP(); 144 } 145 GPIOC->DAT |= BIT4; 146 GPIOC->OEN |= BIT4; 147 GPIOC->IE &= ~BIT4; 148 } 149 else // I2C remap disable, SCL IOB13 150 { 151 GPIOB->DAT &= ~BIT13; 152 GPIOB->ATT |= BIT13; 153 GPIOB->OEN &= ~BIT13; 154 for (i=0; i<9; i++) 155 { 156 GPIOB->DAT |= BIT13; 157 for (j=0; j<100; j++) 158 __NOP(); 159 GPIOB->DAT &= ~BIT13; 160 for (j=0; j<100; j++) 161 __NOP(); 162 } 163 GPIOB->DAT |= BIT13; 164 GPIOB->OEN |= BIT13; 165 GPIOB->IE &= ~BIT13; 166 } 167 } 168 169 /* Exported Functions ------------------------------------------------------- */ 170 171 /** 172 * @brief Initializes the I2C peripheral registers to their default reset values. 173 * @param remap: I2C_REMAP_ENABLE or I2C_REMAP_DISABLE 174 * @retval None 175 */ I2C_DeInit(uint32_t remap)176void I2C_DeInit(uint32_t remap) 177 { 178 I2C->CTRL &= ~I2C_CTRL_EN; 179 180 I2C->ADDR = I2C_ADDR_RSTValue; 181 I2C->CTRL = I2C_CTRL_RSTValue; 182 I2C->CTRL2 = I2C_CTRL2_RSTValue; 183 184 I2C_ClearBus(remap); 185 } 186 187 /** 188 * @brief Fills each InitStruct member with its default value. 189 * @param InitStruct: pointer to an I2C_InitType structure which will be initialized. 190 * @retval None 191 */ I2C_StructInit(I2C_InitType * InitStruct)192void I2C_StructInit(I2C_InitType *InitStruct) 193 { 194 /*--------------- Reset I2C init structure parameters values ---------------*/ 195 /* Initialize the AssertAcknowledge member */ 196 InitStruct->AssertAcknowledge = I2C_ASSERTACKNOWLEDGE_DISABLE; 197 /* Initialize the ClockSource member */ 198 InitStruct->ClockSource = I2C_CLOCKSOURCE_APBD256; 199 /* Initialize the GeneralCallAck member */ 200 InitStruct->GeneralCallAck = I2C_GENERALCALLACK_DISABLE; 201 /* Initialize the SlaveAddr member */ 202 InitStruct->SlaveAddr = 0; 203 } 204 205 /** 206 * @brief I2C initialization. 207 * @param InitStruct: I2C configuration. 208 SlaveAddr: Own I2C slave address (7 bit) 209 GeneralCallAck: 210 I2C_GENERALCALLACK_ENABLE 211 I2C_GENERALCALLACK_DISABLE 212 AssertAcknowledge: 213 I2C_ASSERTACKNOWLEDGE_ENABLE 214 I2C_ASSERTACKNOWLEDGE_DISABLE 215 ClockSource: 216 I2C_CLOCKSOURCE_APBD256 217 I2C_CLOCKSOURCE_APBD224 218 I2C_CLOCKSOURCE_APBD192 219 I2C_CLOCKSOURCE_APBD160 220 I2C_CLOCKSOURCE_APBD960 221 I2C_CLOCKSOURCE_APBD120 222 I2C_CLOCKSOURCE_APBD60 223 I2C_CLOCKSOURCE_TIM3OFD8 224 * @retval None. 225 */ I2C_Init(I2C_InitType * InitStruct)226void I2C_Init(I2C_InitType *InitStruct) 227 { 228 uint32_t tmp; 229 230 /* Check parameters */ 231 assert_parameters(IS_I2C_GC(InitStruct->GeneralCallAck)); 232 assert_parameters(IS_I2C_AA(InitStruct->AssertAcknowledge)); 233 assert_parameters(IS_I2C_CLKSRC(InitStruct->ClockSource)); 234 235 I2C->ADDR = InitStruct->SlaveAddr\ 236 |InitStruct->GeneralCallAck; 237 tmp = I2C->CTRL; 238 tmp &= ~(I2C_CTRL_CR\ 239 |I2C_CTRL_AA); 240 tmp |= (InitStruct->ClockSource\ 241 |InitStruct->AssertAcknowledge); 242 I2C->CTRL = tmp; 243 } 244 245 /** 246 * @brief Interrupt configure. 247 * @param NewState: 248 ENABLE 249 DISABLE 250 * @retval None. 251 */ I2C_INTConfig(uint32_t NewState)252void I2C_INTConfig(uint32_t NewState) 253 { 254 /* Check parameters */ 255 assert_parameters(IS_FUNCTIONAL_STATE(NewState)); 256 257 if (NewState == ENABLE) 258 I2C->CTRL2 |= I2C_CTRL2_INTEN; 259 else 260 I2C->CTRL2 &= ~I2C_CTRL2_INTEN; 261 } 262 263 /** 264 * @brief Get interrupt status. 265 * @param None 266 * @retval Interrupt status. 267 */ I2C_GetINTStatus(void)268uint8_t I2C_GetINTStatus(void) 269 { 270 if (I2C->CTRL&I2C_CTRL_SI) 271 return 1; 272 else 273 return 0; 274 } 275 276 /** 277 * @brief Clear interrupt status. 278 * @param None 279 * @retval None. 280 */ I2C_ClearINTStatus(void)281void I2C_ClearINTStatus(void) 282 { 283 I2C->CTRL &= ~I2C_CTRL_SI; 284 } 285 286 /** 287 * @brief Read a packge of data from slave device. 288 * @param InitStruct: I2C_WRType 289 SlaveAddr : Slave device address 290 SubAddress : start of slave device sub-address 291 PageRange : maximum range of page to Read operation 292 pBuffer : Read data pointer 293 Length : sum of Read datas 294 SubAddrType: 295 I2C_SUBADDR_1BYTE (Slave device sub-address type: 1 byte) 296 I2C_SUBADDR_2BYTE (Slave device sub-address type: 2 bytes) 297 I2C_SUBADDR_OTHER (Slave device sub-address type: othres) 298 * @retval 0: true 299 ��0��status code 300 bit15~8 status code(true) 301 bit7~0 status code(false) 302 */ I2C_MasterReadBytes(I2C_WRType * InitStruct)303uint16_t I2C_MasterReadBytes(I2C_WRType *InitStruct) 304 { 305 uint32_t i; 306 uint16_t ret_val; 307 308 /* Check parameters */ 309 assert_parameters(I2C_SUBADDR_TYPE(InitStruct->SubAddrType)); 310 311 I2C_AssertAcknowledgeConfig(ENABLE); //Enable AA 312 /*-------------------------------- START -----------------------------------*/ 313 I2C_SendStart(); 314 ret_val = I2C_CheckState(0x08); 315 if (ret_val) return ret_val; 316 317 /*------------------------------ Send SLA+W --------------------------------*/ 318 /* Slave device sub-address type: 1 byte */ 319 if (InitStruct->SubAddrType == I2C_SUBADDR_1BYTE) 320 { 321 I2C_SendByte(InitStruct->SlaveAddr); 322 ret_val = I2C_CheckState(0x18); 323 if (ret_val) return ret_val; 324 325 I2C_SendByte(InitStruct->SubAddress&0xFF); 326 ret_val = I2C_CheckState(0x28); 327 if (ret_val) return ret_val; 328 } 329 /* Slave device sub-address type: 2 bytes */ 330 if (InitStruct->SubAddrType == I2C_SUBADDR_2BYTE) 331 { 332 I2C_SendByte(InitStruct->SlaveAddr); 333 ret_val = I2C_CheckState(0x18); 334 if (ret_val) return ret_val; 335 336 I2C_SendByte((InitStruct->SubAddress>>8)&0xFF); 337 ret_val = I2C_CheckState(0x28); 338 if (ret_val) return ret_val; 339 340 I2C_SendByte(InitStruct->SubAddress&0xFF); 341 ret_val = I2C_CheckState(0x28); 342 if (ret_val) return ret_val; 343 } 344 /* Slave device sub-address type: othres */ 345 if (InitStruct->SubAddrType == I2C_SUBADDR_OTHER) 346 { 347 if (InitStruct->PageRange < 256) // 8 + x 348 { 349 I2C_SendByte(InitStruct->SlaveAddr|((InitStruct->SubAddress>>7)&0xE)); 350 ret_val = I2C_CheckState(0x18); 351 if (ret_val) return ret_val; 352 353 I2C_SendByte(InitStruct->SubAddress&0xFF); 354 ret_val = I2C_CheckState(0x28); 355 if (ret_val) return ret_val; 356 } 357 else // 16 + x 358 { 359 I2C_SendByte(InitStruct->SlaveAddr|((InitStruct->SubAddress>>15)&0xE)); 360 ret_val = I2C_CheckState(0x18); 361 if (ret_val) return ret_val; 362 363 I2C_SendByte((InitStruct->SubAddress>>8)&0xFF); 364 ret_val = I2C_CheckState(0x28); 365 if (ret_val) return ret_val; 366 367 I2C_SendByte(InitStruct->SubAddress&0xFF); 368 ret_val = I2C_CheckState(0x28); 369 if (ret_val) return ret_val; 370 } 371 } 372 373 /*------------------------------- Restart ----------------------------------*/ 374 I2C_SendRestart(); //restart 375 ret_val = I2C_CheckState(0x10); 376 if (ret_val) return ret_val; 377 378 /*----------------------------- Send SLA+R ---------------------------------*/ 379 /* Slave device sub-address type: othres */ 380 if (InitStruct->SubAddrType == I2C_SUBADDR_OTHER) 381 { 382 if (InitStruct->PageRange < 256) // 8 + x 383 I2C_SendByte(InitStruct->SlaveAddr|0x01|((InitStruct->SubAddress>>7)&0xE)); 384 else // 16 + x 385 I2C_SendByte(InitStruct->SlaveAddr|0x01|((InitStruct->SubAddress>>15)&0xE)); 386 } 387 else 388 I2C_SendByte(InitStruct->SlaveAddr|0x01); 389 390 ret_val = I2C_CheckState(0x40); 391 if (ret_val) return ret_val; 392 393 /*----------------------------- Read datas ---------------------------------*/ 394 for (i=0; i<(InitStruct->Length-1); i++) 395 { 396 *InitStruct->pBuffer = I2C_ReceiveByte(); 397 InitStruct->pBuffer++; 398 ret_val = I2C_CheckState(0x50); 399 if (ret_val) return ret_val; 400 } 401 /*-------------------- Read the last data, disable AA ----------------------*/ 402 I2C_AssertAcknowledgeConfig(DISABLE); 403 *InitStruct->pBuffer = I2C_ReceiveByte(); 404 ret_val = I2C_CheckState(0x58); 405 if (ret_val) return ret_val; 406 /*--------------------------------- Stop -----------------------------------*/ 407 I2C_SendStop(); //stop 408 return 0; 409 } 410 411 /** 412 * @brief Write a packge of data to slave device. 413 * @param InitStruct: I2C_WRType 414 SlaveAddr : Slave device address 415 SubAddress : start of slave device sub-address 416 PageRange : maximum range of page to write operation 417 pBuffer : write data pointer 418 Length : sum of write datas 419 SubAddrType: 420 I2C_SUBADDR_1BYTE (Slave device sub-address type: 1 byte) 421 I2C_SUBADDR_2BYTE (Slave device sub-address type: 2 bytes) 422 I2C_SUBADDR_OTHER (Slave device sub-address type: othres) 423 * @retval 0: true 424 ��0��status code 425 bit15~8 status code(true) 426 bit7~0 status code(false) 427 */ I2C_MasterWriteBytes(I2C_WRType * InitStruct)428uint16_t I2C_MasterWriteBytes(I2C_WRType *InitStruct) 429 { 430 uint16_t ret_val; 431 uint32_t i; 432 433 /* Check parameters */ 434 assert_parameters(I2C_SUBADDR_TYPE(InitStruct->SubAddrType)); 435 436 I2C_AssertAcknowledgeConfig(ENABLE); //Enable AA 437 /*-------------------------------- START -----------------------------------*/ 438 I2C_SendStart(); 439 ret_val = I2C_CheckState(0x08); 440 if (ret_val) return ret_val; 441 442 /*------------------------------ Send SLA+W --------------------------------*/ 443 /* Slave device sub-address type: 1 byte */ 444 if (InitStruct->SubAddrType == I2C_SUBADDR_1BYTE) 445 { 446 I2C_SendByte(InitStruct->SlaveAddr); 447 ret_val = I2C_CheckState(0x18); 448 if (ret_val) return ret_val; 449 450 I2C_SendByte(InitStruct->SubAddress&0xFF); 451 ret_val = I2C_CheckState(0x28); 452 if (ret_val) return ret_val; 453 } 454 /* Slave device sub-address type: 2 bytes */ 455 else if (InitStruct->SubAddrType == I2C_SUBADDR_2BYTE) 456 { 457 I2C_SendByte(InitStruct->SlaveAddr); //device address 458 ret_val = I2C_CheckState(0x18); 459 if (ret_val) return ret_val; 460 461 I2C_SendByte((InitStruct->SubAddress>>8)&0xFF); //first word address 462 ret_val = I2C_CheckState(0x28); 463 if (ret_val) return ret_val; 464 465 I2C_SendByte(InitStruct->SubAddress&0xFF); //second word address 466 ret_val = I2C_CheckState(0x28); 467 if (ret_val) return ret_val; 468 } 469 /* Slave device sub-address type: othres */ 470 else 471 { 472 if (InitStruct->PageRange < 256) // 8 + x 473 { 474 I2C_SendByte(InitStruct->SlaveAddr|((InitStruct->SubAddress>>7)&0xE)); 475 ret_val = I2C_CheckState(0x18); 476 if (ret_val) return ret_val; 477 478 I2C_SendByte(InitStruct->SubAddress&0xFF); 479 ret_val = I2C_CheckState(0x28); 480 if (ret_val) return ret_val; 481 } 482 else // 16 + x 483 { 484 I2C_SendByte(InitStruct->SlaveAddr|((InitStruct->SubAddress>>15)&0xE)); 485 ret_val = I2C_CheckState(0x18); 486 if (ret_val) return ret_val; 487 488 I2C_SendByte((InitStruct->SubAddress>>8)&0xFF); 489 ret_val = I2C_CheckState(0x28); 490 if (ret_val) return ret_val; 491 492 I2C_SendByte(InitStruct->SubAddress&0xFF); 493 ret_val = I2C_CheckState(0x28); 494 if (ret_val) return ret_val; 495 } 496 } 497 498 /*----------------------------- Write datas --------------------------------*/ 499 for (i=0; i<(InitStruct->Length); i++) 500 { 501 /* Reach the page boundary */ 502 if ((i > 0) && ((InitStruct->SubAddress+i)%InitStruct->PageRange == 0)) 503 { 504 I2C_SendStop(); 505 I2C_WaitForCrossPage(InitStruct->SlaveAddr); 506 I2C_SendStart(); //start 507 ret_val = I2C_CheckState(0x08); 508 if (ret_val) return ret_val; 509 /* WriteAddr: 1 byte */ 510 if (InitStruct->SubAddrType == I2C_SUBADDR_1BYTE) 511 { 512 I2C_SendByte(InitStruct->SlaveAddr); 513 ret_val = I2C_CheckState(0x18); 514 if (ret_val) return ret_val; 515 516 I2C_SendByte((InitStruct->SubAddress+i)&0xFF); 517 ret_val = I2C_CheckState(0x28); 518 if (ret_val) return ret_val; 519 } 520 /* WriteAddr: 2 byte */ 521 if (InitStruct->SubAddrType == I2C_SUBADDR_2BYTE) 522 { 523 I2C_SendByte(InitStruct->SlaveAddr); //device address 524 ret_val = I2C_CheckState(0x18); 525 if (ret_val) return ret_val; 526 527 I2C_SendByte(((InitStruct->SubAddress+i)>>8)&0xFF); //first word address 528 ret_val = I2C_CheckState(0x28); 529 if (ret_val) return ret_val; 530 531 I2C_SendByte((InitStruct->SubAddress+i)&0xFF); //second word address 532 ret_val = I2C_CheckState(0x28); 533 if (ret_val) return ret_val; 534 } 535 /* WriteAddr: (16 or 8)+x*/ 536 if (InitStruct->SubAddrType == I2C_SUBADDR_OTHER) 537 { 538 if (InitStruct->PageRange < 256) // 8 + x 539 { 540 I2C_SendByte(InitStruct->SlaveAddr|(((InitStruct->SubAddress+i)>>7)&0xE)); 541 ret_val = I2C_CheckState(0x18); 542 if (ret_val) return ret_val; 543 544 I2C_SendByte((InitStruct->SubAddress+i)&0xFF); 545 ret_val = I2C_CheckState(0x28); 546 if (ret_val) return ret_val; 547 } 548 else // 16 + x 549 { 550 I2C_SendByte(InitStruct->SlaveAddr|(((InitStruct->SubAddress+i)>>15)&0xE)); 551 ret_val = I2C_CheckState(0x18); 552 if (ret_val) return ret_val; 553 554 I2C_SendByte(((InitStruct->SubAddress+i)>>8)&0xFF); 555 ret_val = I2C_CheckState(0x28); 556 if (ret_val) return ret_val; 557 558 I2C_SendByte((InitStruct->SubAddress+i)&0xFF); 559 ret_val = I2C_CheckState(0x28); 560 if (ret_val) return ret_val; 561 } 562 } 563 564 I2C_SendByte(*InitStruct->pBuffer); 565 InitStruct->pBuffer++; 566 ret_val = I2C_CheckState(0x28); 567 if (ret_val) return ret_val; 568 } 569 /* Not reaching the page boundary */ 570 else 571 { 572 I2C_SendByte(*InitStruct->pBuffer); 573 InitStruct->pBuffer++; 574 ret_val = I2C_CheckState(0x28); 575 if (ret_val) return ret_val; 576 } 577 } 578 579 I2C_SendStop(); 580 I2C_WaitForCrossPage(InitStruct->SlaveAddr); 581 return 0; 582 } 583 584 /** 585 * @brief I2C enable. 586 * @param NewState: 587 ENABLE 588 DISABLE 589 * @retval None. 590 */ I2C_Cmd(uint32_t NewState)591void I2C_Cmd(uint32_t NewState) 592 { 593 /* Check parameters */ 594 assert_parameters(IS_FUNCTIONAL_STATE(NewState)); 595 596 if (NewState == ENABLE) 597 I2C->CTRL |= I2C_CTRL_EN; 598 else 599 I2C->CTRL &= ~I2C_CTRL_EN; 600 } 601 602 /* I2C Exported Functions Group5: 603 Others ------------------------------------*/ 604 605 /** 606 * @brief Assert acknowledge configure. 607 * @param NewState: 608 ENABLE 609 DISABLE 610 * @retval None. 611 */ I2C_AssertAcknowledgeConfig(uint32_t NewState)612void I2C_AssertAcknowledgeConfig(uint32_t NewState) 613 { 614 /* Check parameters */ 615 assert_parameters(IS_FUNCTIONAL_STATE(NewState)); 616 617 if (NewState == ENABLE) 618 I2C->CTRL |= I2C_CTRL_AA; 619 else 620 I2C->CTRL &= ~I2C_CTRL_AA; 621 } 622 623 /** 624 * @brief Receive a byte data. 625 * @param None. 626 * @retval Data received. 627 */ I2C_ReceiveData(void)628uint8_t I2C_ReceiveData(void) 629 { 630 return I2C->DATA; 631 } 632 633 /** 634 * @brief Sends a byte data. 635 * @param Dat:data to transmit. 636 * @retval None 637 */ I2C_SendData(uint8_t Dat)638void I2C_SendData(uint8_t Dat) 639 { 640 I2C->DATA = Dat; 641 } 642 643 /** 644 * @brief Generate start signal. 645 * @param NewState: 646 ENABLE 647 DISABLE 648 * @retval None. 649 */ I2C_GenerateSTART(uint32_t NewState)650void I2C_GenerateSTART(uint32_t NewState) 651 { 652 /* Check parameters */ 653 assert_parameters(IS_FUNCTIONAL_STATE(NewState)); 654 655 if (NewState == ENABLE) 656 I2C->CTRL |= I2C_CTRL_STA; 657 else 658 I2C->CTRL &= ~I2C_CTRL_STA; 659 } 660 661 /** 662 * @brief Generate stop signal. 663 * @param NewState: 664 ENABLE 665 DISABLE 666 * @retval None. 667 */ I2C_GenerateSTOP(uint32_t NewState)668void I2C_GenerateSTOP(uint32_t NewState) 669 { 670 /* Check parameters */ 671 assert_parameters(IS_FUNCTIONAL_STATE(NewState)); 672 673 if (NewState == ENABLE) 674 I2C->CTRL |= I2C_CTRL_STO; 675 else 676 I2C->CTRL &= ~I2C_CTRL_STO; 677 } 678 679 /** 680 * @brief Get status code. 681 * @param None 682 * @retval status code. 683 */ I2C_GetStatusCode(void)684uint8_t I2C_GetStatusCode(void) 685 { 686 return (I2C->STS&I2C_STS_STS); 687 } 688 689 /*********************************** END OF FILE ******************************/ 690