/** * @brief This function handles the DMA Tx Channel interrupt Handler. * @param None * @retval None */ void sEE_I2C_DMA_TX_IRQHandler(void) { /* Check if the DMA transfer is complete */ if(DMA_GetFlagStatus(sEE_I2C_DMA_FLAG_TX_TC) != RESET) { /* Disable the DMA Tx Channel and Clear all its Flags */ DMA_Cmd(sEE_I2C_DMA_CHANNEL_TX, DISABLE); DMA_ClearFlag(sEE_I2C_DMA_FLAG_TX_GL); /*!< Wait till all data have been physically transferred on the bus */ sEETimeout = sEE_LONG_TIMEOUT; while(!I2C_GetFlagStatus(sEE_I2C, I2C_FLAG_BTF)) { if((sEETimeout--) == 0) sEE_TIMEOUT_UserCallback(); } /*!< Send STOP condition */ I2C_GenerateSTOP(sEE_I2C, ENABLE); /* Perform a read on SR1 and SR2 register to clear eventualaly pending flags */ (void)sEE_I2C->SR1; (void)sEE_I2C->SR2; /* Reset the variable holding the number of data to be written */ *sEEDataWritePointer = 0; } }
/** * @brief Wait for EEPROM Standby state. * * @note This function allows to wait and check that EEPROM has finished the * last operation. It is mostly used after Write operation: after receiving * the buffer to be written, the EEPROM may need additional time to actually * perform the write operation. During this time, it doesn't answer to * I2C packets addressed to it. Once the write operation is complete * the EEPROM responds to its address. * * @param None * * @retval sEE_OK (0) if operation is correctly performed, else return value * different from sEE_OK (0) or the timeout user callback. */ uint32_t sEE_WaitEepromStandbyState(void) { __IO uint32_t sEETrials = 0; /* Keep looping till the slave acknowledge his address or maximum number of trials is reached (this number is defined by sEE_MAX_TRIALS_NUMBER define in stm32373c_eval_i2c_ee.h file) */ /* Configure CR2 register : set Slave Address and end mode */ I2C_TransferHandling(sEE_I2C, sEEAddress, 0, I2C_AutoEnd_Mode, I2C_No_StartStop); do { /* Initialize sEETimeout */ sEETimeout = sEE_FLAG_TIMEOUT; /* Clear NACKF */ I2C_ClearFlag(sEE_I2C, I2C_ICR_NACKCF | I2C_ICR_STOPCF); /* Generate start */ I2C_GenerateSTART(sEE_I2C, ENABLE); /* Wait until timeout elapsed */ while (sEETimeout-- != 0); /* Check if the maximum allowed numbe of trials has bee reached */ if (sEETrials++ == sEE_MAX_TRIALS_NUMBER) { /* If the maximum number of trials has been reached, exit the function */ return sEE_TIMEOUT_UserCallback(); } } while(I2C_GetFlagStatus(sEE_I2C, I2C_ISR_NACKF) != RESET); /* Clear STOPF */ I2C_ClearFlag(sEE_I2C, I2C_ICR_STOPCF); /* Return sEE_OK if device is ready */ return sEE_OK; }
/** * @brief This function handles the DMA Tx Channel interrupt Handler. * @param None * @retval None */ void sEE_I2C_DMA_TX_IRQHandler(void) { /* Check if the DMA transfer is complete */ if(DMA_GetFlagStatus(sEE_I2C_DMA_STREAM_TX, sEE_TX_DMA_FLAG_TCIF) != RESET) { /* Disable the DMA Tx Stream and Clear TC flag */ DMA_Cmd(sEE_I2C_DMA_STREAM_TX, DISABLE); DMA_ClearFlag(sEE_I2C_DMA_STREAM_TX, sEE_TX_DMA_FLAG_TCIF); /*!< Wait till all data have been physically transferred on the bus */ sEETimeout = sEE_LONG_TIMEOUT; while(!I2C_GetFlagStatus(sEE_I2C, I2C_FLAG_BTF)) { if((sEETimeout--) == 0) sEE_TIMEOUT_UserCallback(); } /*!< Send STOP condition */ I2C_GenerateSTOP(sEE_I2C, ENABLE); /* Reset the variable holding the number of data to be written */ *sEEDataWritePointer = 0; } }
/** * @brief Wait for EEPROM Standby state. * * @note This function allows to wait and check that EEPROM has finished the * last operation. It is mostly used after Write operation: after receiving * the buffer to be written, the EEPROM may need additional time to actually * perform the write operation. During this time, it doesn't answer to * I2C packets addressed to it. Once the write operation is complete * the EEPROM responds to its address. * * @param None * @retval sEE_OK (0) if operation is correctly performed, else return value * different from sEE_OK (0) or the timeout user callback. */ uint32_t sEE_WaitEepromStandbyState(void) { __IO uint16_t tmpSR1 = 0; __IO uint32_t sEETrials = 0; /*!< While the bus is busy */ sEETimeout = sEE_LONG_TIMEOUT; while(I2C_GetFlagStatus(sEE_I2C, I2C_FLAG_BUSY)) { if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } /* Keep looping till the slave acknowledge his address or maximum number of trials is reached (this number is defined by sEE_MAX_TRIALS_NUMBER define in stm32f429i_discovery_i2c_ee.h file) */ while (1) { /*!< Send START condition */ I2C_GenerateSTART(sEE_I2C, ENABLE); /*!< Test on EV5 and clear it */ sEETimeout = sEE_FLAG_TIMEOUT; while(!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_MODE_SELECT)) { if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } /*!< Send EEPROM address for write */ I2C_Send7bitAddress(sEE_I2C, sEEAddress, I2C_Direction_Transmitter); /* Wait for ADDR flag to be set (Slave acknowledged his address) */ sEETimeout = sEE_LONG_TIMEOUT; do { /* Get the current value of the SR1 register */ tmpSR1 = sEE_I2C->SR1; /* Update the timeout value and exit if it reach 0 */ if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } /* Keep looping till the Address is acknowledged or the AF flag is set (address not acknowledged at time) */ while((tmpSR1 & (I2C_SR1_ADDR | I2C_SR1_AF)) == 0); /* Check if the ADDR flag has been set */ if (tmpSR1 & I2C_SR1_ADDR) { /* Clear ADDR Flag by reading SR1 then SR2 registers (SR1 have already been read) */ (void)sEE_I2C->SR2; /*!< STOP condition */ I2C_GenerateSTOP(sEE_I2C, ENABLE); /* Exit the function */ return sEE_OK; } else { /*!< Clear AF flag */ I2C_ClearFlag(sEE_I2C, I2C_FLAG_AF); } /* Check if the maximum allowed number of trials has bee reached */ if (sEETrials++ == sEE_MAX_TRIALS_NUMBER) { /* If the maximum number of trials has been reached, exit the function */ return sEE_TIMEOUT_UserCallback(); } } }
/** * @brief Writes buffer of data to the I2C EEPROM. * @param pBuffer : pointer to the buffer containing the data to be written * to the EEPROM. * @param WriteAddr : EEPROM's internal address to write to. * @param NumByteToWrite : number of bytes to write to the EEPROM. * @retval None */ void sEE_WriteBuffer(uint8_t* pBuffer, uint16_t WriteAddr, uint16_t NumByteToWrite) { uint16_t NumOfPage = 0, NumOfSingle = 0, count = 0; uint16_t Addr = 0; Addr = WriteAddr % sEE_PAGESIZE; count = sEE_PAGESIZE - Addr; NumOfPage = NumByteToWrite / sEE_PAGESIZE; NumOfSingle = NumByteToWrite % sEE_PAGESIZE; /*!< If WriteAddr is sEE_PAGESIZE aligned */ if(Addr == 0) { /*!< If NumByteToWrite < sEE_PAGESIZE */ if(NumOfPage == 0) { /* Store the number of data to be written */ sEEDataNum = NumOfSingle; /* Start writing data */ sEE_WritePage(pBuffer, WriteAddr, (uint8_t*)(&sEEDataNum)); /* Wait transfer through DMA to be complete */ sEETimeout = sEE_LONG_TIMEOUT; while (sEEDataNum > 0) { if((sEETimeout--) == 0) {sEE_TIMEOUT_UserCallback(); return;}; } sEE_WaitEepromStandbyState(); } /*!< If NumByteToWrite > sEE_PAGESIZE */ else { while(NumOfPage--) { /* Store the number of data to be written */ sEEDataNum = sEE_PAGESIZE; sEE_WritePage(pBuffer, WriteAddr, (uint8_t*)(&sEEDataNum)); /* Wait transfer through DMA to be complete */ sEETimeout = sEE_LONG_TIMEOUT; while (sEEDataNum > 0) { if((sEETimeout--) == 0) {sEE_TIMEOUT_UserCallback(); return;}; } sEE_WaitEepromStandbyState(); WriteAddr += sEE_PAGESIZE; pBuffer += sEE_PAGESIZE; } if(NumOfSingle!=0) { /* Store the number of data to be written */ sEEDataNum = NumOfSingle; sEE_WritePage(pBuffer, WriteAddr, (uint8_t*)(&sEEDataNum)); /* Wait transfer through DMA to be complete */ sEETimeout = sEE_LONG_TIMEOUT; while (sEEDataNum > 0) { if((sEETimeout--) == 0) {sEE_TIMEOUT_UserCallback(); return;}; } sEE_WaitEepromStandbyState(); } } } /*!< If WriteAddr is not sEE_PAGESIZE aligned */ else { /*!< If NumByteToWrite < sEE_PAGESIZE */ if(NumOfPage== 0) { /*!< If the number of data to be written is more than the remaining space in the current page: */ if (NumByteToWrite > count) { /* Store the number of data to be written */ sEEDataNum = count; /*!< Write the data contained in same page */ sEE_WritePage(pBuffer, WriteAddr, (uint8_t*)(&sEEDataNum)); /* Wait transfer through DMA to be complete */ sEETimeout = sEE_LONG_TIMEOUT; while (sEEDataNum > 0) { if((sEETimeout--) == 0) {sEE_TIMEOUT_UserCallback(); return;}; } sEE_WaitEepromStandbyState(); /* Store the number of data to be written */ sEEDataNum = (NumByteToWrite - count); /*!< Write the remaining data in the following page */ sEE_WritePage((uint8_t*)(pBuffer + count), (WriteAddr + count), (uint8_t*)(&sEEDataNum)); /* Wait transfer through DMA to be complete */ sEETimeout = sEE_LONG_TIMEOUT; while (sEEDataNum > 0) { if((sEETimeout--) == 0) {sEE_TIMEOUT_UserCallback(); return;}; } sEE_WaitEepromStandbyState(); } else { /* Store the number of data to be written */ sEEDataNum = NumOfSingle; sEE_WritePage(pBuffer, WriteAddr, (uint8_t*)(&sEEDataNum)); /* Wait transfer through DMA to be complete */ sEETimeout = sEE_LONG_TIMEOUT; while (sEEDataNum > 0) { if((sEETimeout--) == 0) {sEE_TIMEOUT_UserCallback(); return;}; } sEE_WaitEepromStandbyState(); } } /*!< If NumByteToWrite > sEE_PAGESIZE */ else { NumByteToWrite -= count; NumOfPage = NumByteToWrite / sEE_PAGESIZE; NumOfSingle = NumByteToWrite % sEE_PAGESIZE; if(count != 0) { /* Store the number of data to be written */ sEEDataNum = count; sEE_WritePage(pBuffer, WriteAddr, (uint8_t*)(&sEEDataNum)); /* Wait transfer through DMA to be complete */ sEETimeout = sEE_LONG_TIMEOUT; while (sEEDataNum > 0) { if((sEETimeout--) == 0) {sEE_TIMEOUT_UserCallback(); return;}; } sEE_WaitEepromStandbyState(); WriteAddr += count; pBuffer += count; } while(NumOfPage--) { /* Store the number of data to be written */ sEEDataNum = sEE_PAGESIZE; sEE_WritePage(pBuffer, WriteAddr, (uint8_t*)(&sEEDataNum)); /* Wait transfer through DMA to be complete */ sEETimeout = sEE_LONG_TIMEOUT; while (sEEDataNum > 0) { if((sEETimeout--) == 0) {sEE_TIMEOUT_UserCallback(); return;}; } sEE_WaitEepromStandbyState(); WriteAddr += sEE_PAGESIZE; pBuffer += sEE_PAGESIZE; } if(NumOfSingle != 0) { /* Store the number of data to be written */ sEEDataNum = NumOfSingle; sEE_WritePage(pBuffer, WriteAddr, (uint8_t*)(&sEEDataNum)); /* Wait transfer through DMA to be complete */ sEETimeout = sEE_LONG_TIMEOUT; while (sEEDataNum > 0) { if((sEETimeout--) == 0) {sEE_TIMEOUT_UserCallback(); return;}; } sEE_WaitEepromStandbyState(); } } } }
/** * @brief Writes more than one byte to the EEPROM with a single WRITE cycle. * * @note The number of bytes (combined to write start address) must not * cross the EEPROM page boundary. This function can only write into * the boundaries of an EEPROM page. * This function doesn't check on boundaries condition (in this driver * the function sEE_WriteBuffer() which calls sEE_WritePage() is * responsible of checking on Page boundaries). * * @param pBuffer : pointer to the buffer containing the data to be written to * the EEPROM. * @param WriteAddr : EEPROM's internal address to write to. * @param NumByteToWrite : pointer to the variable holding number of bytes to * be written into the EEPROM. * * @note The variable pointed by NumByteToWrite is reset to 0 when all the * data are written to the EEPROM. Application should monitor this * variable in order know when the transfer is complete. * * @note This function just configure the communication and enable the DMA * channel to transfer data. Meanwhile, the user application may perform * other tasks in parallel. * * @retval sEE_OK (0) if operation is correctly performed, else return value * different from sEE_OK (0) or the timeout user callback. */ uint32_t sEE_WritePage(uint8_t* pBuffer, uint16_t WriteAddr, uint8_t* NumByteToWrite) { /* Set the pointer to the Number of data to be written. This pointer will be used by the DMA Transfer Completer interrupt Handler in order to reset the variable to 0. User should check on this variable in order to know if the DMA transfer has been complete or not. */ sEEDataWritePointer = NumByteToWrite; /*!< While the bus is busy */ sEETimeout = sEE_LONG_TIMEOUT; while(I2C_GetFlagStatus(sEE_I2C, I2C_FLAG_BUSY)) { if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } /*!< Send START condition */ I2C_GenerateSTART(sEE_I2C, ENABLE); /*!< Test on EV5 and clear it */ sEETimeout = sEE_FLAG_TIMEOUT; while(!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_MODE_SELECT)) { if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } /*!< Send EEPROM address for write */ sEETimeout = sEE_FLAG_TIMEOUT; I2C_Send7bitAddress(sEE_I2C, sEEAddress, I2C_Direction_Transmitter); /*!< Test on EV6 and clear it */ sEETimeout = sEE_FLAG_TIMEOUT; while(!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) { if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } /*!< Send the EEPROM's internal address to write to : MSB of the address first */ I2C_SendData(sEE_I2C, (uint8_t)((WriteAddr & 0xFF00) >> 8)); /*!< Test on EV8 and clear it */ sEETimeout = sEE_FLAG_TIMEOUT; while(!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_BYTE_TRANSMITTING)) { if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } /*!< Send the EEPROM's internal address to write to : LSB of the address */ I2C_SendData(sEE_I2C, (uint8_t)(WriteAddr & 0x00FF)); /*!< Test on EV8 and clear it */ sEETimeout = sEE_FLAG_TIMEOUT; while(!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_BYTE_TRANSMITTING)) { if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } /* Configure the DMA Tx Channel with the buffer address and the buffer size */ sEE_LowLevel_DMAConfig((uint32_t)pBuffer, (uint8_t)(*NumByteToWrite), sEE_DIRECTION_TX); /* Enable the DMA Tx Stream */ DMA_Cmd(sEE_I2C_DMA_STREAM_TX, ENABLE); /* If all operations OK, return sEE_OK (0) */ return sEE_OK; }
/** * @brief Reads a block of data from the EEPROM. * @param pBuffer : pointer to the buffer that receives the data read from * the EEPROM. * @param ReadAddr : EEPROM's internal address to start reading from. * @param NumByteToRead : pointer to the variable holding number of bytes to * be read from the EEPROM. * * @note The variable pointed by NumByteToRead is reset to 0 when all the * data are read from the EEPROM. Application should monitor this * variable in order know when the transfer is complete. * * @note When number of data to be read is higher than 1, this function just * configures the communication and enable the DMA channel to transfer data. * Meanwhile, the user application may perform other tasks. * When number of data to be read is 1, then the DMA is not used. The byte * is read in polling mode. * * @retval sEE_OK (0) if operation is correctly performed, else return value * different from sEE_OK (0) or the timeout user callback. */ uint32_t sEE_ReadBuffer(uint8_t* pBuffer, uint16_t ReadAddr, uint16_t* NumByteToRead) { /* Set the pointer to the Number of data to be read. This pointer will be used by the DMA Transfer Completer interrupt Handler in order to reset the variable to 0. User should check on this variable in order to know if the DMA transfer has been complete or not. */ sEEDataReadPointer = NumByteToRead; /*!< While the bus is busy */ sEETimeout = sEE_LONG_TIMEOUT; while(I2C_GetFlagStatus(sEE_I2C, I2C_FLAG_BUSY)) { if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } /*!< Send START condition */ I2C_GenerateSTART(sEE_I2C, ENABLE); /*!< Test on EV5 and clear it (cleared by reading SR1 then writing to DR) */ sEETimeout = sEE_FLAG_TIMEOUT; while(!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_MODE_SELECT)) { if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } /*!< Send EEPROM address for write */ I2C_Send7bitAddress(sEE_I2C, sEEAddress, I2C_Direction_Transmitter); /*!< Test on EV6 and clear it */ sEETimeout = sEE_FLAG_TIMEOUT; while(!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) { if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } /*!< Send the EEPROM's internal address to read from: MSB of the address first */ I2C_SendData(sEE_I2C, (uint8_t)((ReadAddr & 0xFF00) >> 8)); /*!< Test on EV8 and clear it */ sEETimeout = sEE_FLAG_TIMEOUT; while(!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_BYTE_TRANSMITTING)) { if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } /*!< Send the EEPROM's internal address to read from: LSB of the address */ I2C_SendData(sEE_I2C, (uint8_t)(ReadAddr & 0x00FF)); /*!< Test on EV8 and clear it */ sEETimeout = sEE_FLAG_TIMEOUT; while(I2C_GetFlagStatus(sEE_I2C, I2C_FLAG_BTF) == RESET) { if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } /*!< Send STRAT condition a second time */ I2C_GenerateSTART(sEE_I2C, ENABLE); /*!< Test on EV5 and clear it (cleared by reading SR1 then writing to DR) */ sEETimeout = sEE_FLAG_TIMEOUT; while(!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_MODE_SELECT)) { if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } /*!< Send EEPROM address for read */ I2C_Send7bitAddress(sEE_I2C, sEEAddress, I2C_Direction_Receiver); /* If number of data to be read is 1, then DMA couldn't be used */ /* One Byte Master Reception procedure (POLLING) ---------------------------*/ if ((uint16_t)(*NumByteToRead) < 2) { /* Wait on ADDR flag to be set (ADDR is still not cleared at this level */ sEETimeout = sEE_FLAG_TIMEOUT; while(I2C_GetFlagStatus(sEE_I2C, I2C_FLAG_ADDR) == RESET) { if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } /*!< Disable Acknowledgement */ I2C_AcknowledgeConfig(sEE_I2C, DISABLE); /* Clear ADDR register by reading SR1 then SR2 register (SR1 has already been read) */ (void)sEE_I2C->SR2; /*!< Send STOP Condition */ I2C_GenerateSTOP(sEE_I2C, ENABLE); /* Wait for the byte to be received */ sEETimeout = sEE_FLAG_TIMEOUT; while(I2C_GetFlagStatus(sEE_I2C, I2C_FLAG_RXNE) == RESET) { if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } /*!< Read the byte received from the EEPROM */ *pBuffer = I2C_ReceiveData(sEE_I2C); /*!< Decrement the read bytes counter */ (uint16_t)(*NumByteToRead)--; /* Wait to make sure that STOP control bit has been cleared */ sEETimeout = sEE_FLAG_TIMEOUT; while(sEE_I2C->CR1 & I2C_CR1_STOP) { if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } /*!< Re-Enable Acknowledgement to be ready for another reception */ I2C_AcknowledgeConfig(sEE_I2C, ENABLE); } else/* More than one Byte Master Reception procedure (DMA) -----------------*/ { /*!< Test on EV6 and clear it */ sEETimeout = sEE_FLAG_TIMEOUT; while(!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED)) { if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } /* Configure the DMA Rx Channel with the buffer address and the buffer size */ sEE_LowLevel_DMAConfig((uint32_t)pBuffer, (uint16_t)(*NumByteToRead), sEE_DIRECTION_RX); /* Inform the DMA that the next End Of Transfer Signal will be the last one */ I2C_DMALastTransferCmd(sEE_I2C, ENABLE); /* Enable the DMA Rx Stream */ DMA_Cmd(sEE_I2C_DMA_STREAM_RX, ENABLE); } /* If all operations OK, return sEE_OK (0) */ return sEE_OK; }
uint32_t sEE_WaitEepromStandbyState(void) { __IO uint8_t tmpSR1 = 0; __IO uint32_t sEETrials = 0; /* While the bus is busy */ sEETimeout = sEE_LONG_TIMEOUT; while(I2C_GetFlagStatus(I2C_FLAG_BUSBUSY)) { if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } /* Keep looping till the slave acknowledges his address or the maximum number of trials is reached (this number is defined by sEE_MAX_TRIALS_NUMBER define in stm8s_eval_i2c_ee.h file) */ while (1) { /* Send START condition */ I2C_GenerateSTART(ENABLE); /* Test on EV5 and clear it */ sEETimeout = sEE_FLAG_TIMEOUT; while(!I2C_CheckEvent(I2C_EVENT_MASTER_MODE_SELECT)) { if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } /* Send EEPROM address for write */ I2C_Send7bitAddress((uint8_t)sEEAddress, I2C_DIRECTION_TX); /* Wait for ADDR flag to be set (Slave acknowledged his address) */ sEETimeout = sEE_LONG_TIMEOUT; do { /* Get the current value of the SR1 register */ tmpSR1 = I2C->SR1; /* Update the timeout value and exit if it reach 0 */ if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } /* Keep looping till the Address is acknowledged or the AF flag is set (address not acknowledged at time) */ while((I2C_GetFlagStatus(I2C_FLAG_ADDRESSSENTMATCHED)== RESET) & (I2C_GetFlagStatus(I2C_FLAG_ACKNOWLEDGEFAILURE)== RESET)); tmpSR1 = I2C->SR1; /* Check if the ADDR flag has been set */ if (tmpSR1 & I2C_SR1_ADDR) { /* Clear ADDR Flag by reading SR1 then SR3 registers (SR1 have already been read) */ (void)I2C->SR3; /* STOP condition */ I2C_GenerateSTOP(ENABLE); /* Exit the function */ return sEE_OK; } else { /* Clear AF flag */ I2C_ClearFlag(I2C_FLAG_ACKNOWLEDGEFAILURE); } /* Check if the maximum allowed number of trials has bee reached */ if (sEETrials++ == sEE_MAX_TRIALS_NUMBER) { /* If the maximum number of trials has been reached, exit the function */ return sEE_TIMEOUT_UserCallback(); } } }
uint32_t sEE_ReadBuffer(uint8_t* pBuffer, uint16_t ReadAddr, uint16_t NumByteToRead) { /* While the bus is busy */ sEETimeout = sEE_LONG_TIMEOUT; while(I2C_GetFlagStatus( I2C_FLAG_BUSBUSY)) { if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } /* Send START condition */ I2C_GenerateSTART(ENABLE); /* Test on EV5 and clear it (cleared by reading SR1 then writing to DR) */ sEETimeout = sEE_FLAG_TIMEOUT; while(!I2C_CheckEvent( I2C_EVENT_MASTER_MODE_SELECT)) { if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } /* Send EEPROM address for write */ I2C_Send7bitAddress( (uint8_t)sEEAddress, I2C_DIRECTION_TX); /* Test on EV6 and clear it */ sEETimeout = sEE_FLAG_TIMEOUT; while(!I2C_CheckEvent( I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) { if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } #ifdef sEE_M24C64_32 /* Send the EEPROM's internal address to read from: MSB of the address first */ I2C_SendData( (uint8_t)((ReadAddr & 0xFF00) >> 8)); /* Test on EV8 and clear it */ sEETimeout = sEE_FLAG_TIMEOUT; while(!I2C_CheckEvent( I2C_EVENT_MASTER_BYTE_TRANSMITTED)) { if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } #endif /* sEE_M24C64_32 */ /* Send the EEPROM's internal address to read from: LSB of the address */ I2C_SendData( (uint8_t)(ReadAddr & 0x00FF)); /* Test on EV8 and clear it */ sEETimeout = sEE_FLAG_TIMEOUT; while(I2C_GetFlagStatus(I2C_FLAG_TRANSFERFINISHED) == RESET) { if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } /* Send START condition a second time */ I2C_GenerateSTART( ENABLE); /* Test on EV5 and clear it (cleared by reading SR1 then writing to DR) */ sEETimeout = sEE_FLAG_TIMEOUT; while(!I2C_CheckEvent( I2C_EVENT_MASTER_MODE_SELECT)) { if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } /* Send EEPROM address for read */ I2C_Send7bitAddress((uint8_t)sEEAddress, I2C_DIRECTION_RX); if ((uint16_t)(NumByteToRead)> 2) { sEETimeout = sEE_FLAG_TIMEOUT; while(!I2C_GetFlagStatus( I2C_FLAG_ADDRESSSENTMATCHED)) { if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } I2C->SR3; /* Read data from first byte until byte N-3 */ while ((uint16_t)(NumByteToRead)> 3) { /* Poll on BTF */ sEETimeout = sEE_FLAG_TIMEOUT; while (I2C_GetFlagStatus( I2C_FLAG_TRANSFERFINISHED) == RESET) { if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } /* Read a byte from the EEPROM */ *pBuffer = I2C_ReceiveData(); /* Point to the next location where the byte read will be saved */ pBuffer++; /* Decrement the read bytes counter */ (uint16_t)(NumByteToRead)--; } //} /* Remains three data for read: data N-2, data N-1, Data N */ /* Three Bytes Master Reception procedure (POLLING) ------------------------*/ // if ((uint16_t)(*NumByteToRead) == 3) //{ /* Data N-2 in DR and data N -1 in shift register */ /* Poll on BTF */ sEETimeout = sEE_FLAG_TIMEOUT; while (I2C_GetFlagStatus( I2C_FLAG_TRANSFERFINISHED) == RESET) { if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } /* Clear ACK */ I2C_AcknowledgeConfig(I2C_ACK_NONE); /* Call User callback for critical section start (should typically disable interrupts) */ sEE_EnterCriticalSection_UserCallback(); /* Read Data N-2 */ *pBuffer = I2C_ReceiveData(); /* Point to the next location where the byte read will be saved */ pBuffer++; /* Program the STOP */ I2C_GenerateSTOP(ENABLE); /* Read DataN-1 */ *pBuffer = I2C_ReceiveData(); /* Call User callback for critical section end (should typically re-enable interrupts) */ sEE_ExitCriticalSection_UserCallback(); /* Point to the next location where the byte read will be saved */ pBuffer++; /* Poll on RxNE */ sEETimeout = sEE_FLAG_TIMEOUT; while (I2C_GetFlagStatus( I2C_FLAG_RXNOTEMPTY) == RESET) { if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } /* Read DataN */ *pBuffer = I2C_ReceiveData(); /* Reset the number of bytes to be read from the EEPROM */ NumByteToRead = 0; return sEE_OK; } /* If number of data to be read is 2 */ /* Tow Bytes Master Reception procedure (POLLING) ---------------------------*/ if ((uint16_t)(NumByteToRead) == 2) { /* Enable acknowledgement on next byte (set POS and ACK bits)*/ I2C_AcknowledgeConfig(I2C_ACK_NEXT); /* Wait on ADDR flag to be set (ADDR is still not cleared at this level */ sEETimeout = sEE_FLAG_TIMEOUT; while(I2C_GetFlagStatus( I2C_FLAG_ADDRESSSENTMATCHED) == RESET) { if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } /* Clear ADDR register by reading SR1 then SR3 register (SR1 has already been read) */ (void)I2C->SR3; /* Disable Acknowledgement */ I2C_AcknowledgeConfig(I2C_ACK_NONE); /* Wait for BTF flag to be set */ sEETimeout = sEE_FLAG_TIMEOUT; while (I2C_GetFlagStatus( I2C_FLAG_TRANSFERFINISHED) == RESET) { if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } /* Call User callback for critical section start (should typically disable interrupts) */ sEE_EnterCriticalSection_UserCallback(); /* Program the STOP */ I2C_GenerateSTOP(ENABLE); /* Read Data N-1 */ *pBuffer = I2C_ReceiveData(); /* Point to the next location where the byte read will be saved */ pBuffer++; /* Call User callback for critical section end (should typically re-enable interrupts) */ sEE_ExitCriticalSection_UserCallback(); /* Read Data N */ *pBuffer = I2C_ReceiveData(); /* Reset the number of bytes to be read from the EEPROM */ NumByteToRead = 0; return sEE_OK; } /* If number of data to be read is 1 */ /* One Byte Master Reception procedure (POLLING) ---------------------------*/ if ((uint16_t)(NumByteToRead) < 2) { /* Wait on ADDR flag to be set (ADDR is still not cleared at this level */ sEETimeout = sEE_FLAG_TIMEOUT; while(I2C_GetFlagStatus( I2C_FLAG_ADDRESSSENTMATCHED) == RESET) { if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } /* Disable Acknowledgement */ I2C_AcknowledgeConfig(I2C_ACK_NONE); /* Call User callback for critical section start (should typically disable interrupts) */ sEE_EnterCriticalSection_UserCallback(); /* Clear ADDR register by reading SR1 then SR3 register (SR1 has already been read) */ (void)I2C->SR3; /* Send STOP Condition */ I2C_GenerateSTOP( ENABLE); /* Call User callback for critical section end (should typically re-enable interrupts) */ sEE_ExitCriticalSection_UserCallback(); /* Wait for the byte to be received */ sEETimeout = sEE_FLAG_TIMEOUT; while(I2C_GetFlagStatus( I2C_FLAG_RXNOTEMPTY) == RESET) { if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } /* Read the byte received from the EEPROM */ *pBuffer = I2C_ReceiveData(); /* Decrement the read bytes counter */ (uint16_t)(NumByteToRead)--; /* Wait to make sure that STOP control bit has been cleared */ sEETimeout = sEE_FLAG_TIMEOUT; while(I2C->CR2 & I2C_CR2_STOP) { if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } /* Re-Enable Acknowledgement to be ready for another reception */ I2C_AcknowledgeConfig( I2C_ACK_CURR); } /* If all operations OK, return sEE_OK (0) */ return sEE_OK; }
/** * @brief Writes more than one byte to the EEPROM. * * @note The number of bytes (combined to write start address) must not * cross the EEPROM page boundary. This function can only write into * the boundaries of an EEPROM page. * This function doesn't check on boundaries condition (in this driver * the function sEE_WriteBuffer() which calls sEE_WritePage() is * responsible of checking on Page boundaries). * * @param pBuffer : pointer to the buffer containing the data to be written to * the EEPROM. * @param WriteAddr : EEPROM's internal address to write to. * @param NumByteToWrite : pointer to the variable holding number of bytes to * be written into the EEPROM. * * @note The variable pointed by NumByteToWrite is reset to 0 when all the * data are written to the EEPROM. Application should monitor this * variable in order know when the transfer is complete. * * @retval sEE_OK (0) if operation is correctly performed, else return value * different from sEE_OK (0) or the timeout user callback. */ uint32_t sEE_WritePage(uint8_t* pBuffer, uint16_t WriteAddr, uint8_t* NumByteToWrite) { /* Set the pointer to the Number of data to be written. User should check on this variable in order to know if the data transfer has been completed or not. */ sEEDataWritePointer = NumByteToWrite; /* While the bus is busy */ sEETimeout = sEE_LONG_TIMEOUT; while(I2C_GetFlagStatus(I2C_FLAG_BUSBUSY)) { if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } /* Send START condition */ I2C_GenerateSTART( ENABLE); /* Test on EV5 and clear it */ sEETimeout = sEE_FLAG_TIMEOUT; while(!I2C_CheckEvent(I2C_EVENT_MASTER_MODE_SELECT)) { if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } /* Send EEPROM address for write */ sEETimeout = sEE_FLAG_TIMEOUT; I2C_Send7bitAddress((uint8_t)sEEAddress, I2C_DIRECTION_TX); /* Test on EV6 and clear it */ sEETimeout = sEE_FLAG_TIMEOUT; while(!I2C_CheckEvent( I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) { if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } /* Send the EEPROM's internal address to write to : only one byte Address */ I2C_SendData( WriteAddr); #ifdef defined(sEE_M24C64_32) /* Send the EEPROM's internal address to write to : MSB of the address first */ I2C_SendData( (uint8_t)((WriteAddr & 0xFF00) >> 8)); /* Test on EV8 and clear it */ sEETimeout = sEE_FLAG_TIMEOUT; while(!I2C_CheckEvent( I2C_EVENT_MASTER_BYTE_TRANSMITTED)) { if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } /* Send the EEPROM's internal address to write to : LSB of the address */ I2C_SendData( (uint8_t)(WriteAddr & 0x00FF)); #endif /* sEE_M24C08 */ /* Test on EV8 and clear it */ sEETimeout = sEE_FLAG_TIMEOUT; while(!I2C_CheckEvent( I2C_EVENT_MASTER_BYTE_TRANSMITTED)) { if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } /* While there is data to be written */ while((uint16_t)(*sEEDataWritePointer) > 0) { /* Send the byte to be written */ I2C_SendData( *pBuffer); pBuffer++; /* Test on EV8 and clear it */ /* Wait till all data have been physically transferred on the bus */ sEETimeout = sEE_LONG_TIMEOUT; while(!I2C_GetFlagStatus( I2C_FLAG_TRANSFERFINISHED)) { if((sEETimeout--) == 0) sEE_TIMEOUT_UserCallback(); } (uint16_t)(*sEEDataWritePointer)--; } /* Send STOP condition */ I2C_GenerateSTOP(ENABLE); /* Perform a read on SR1 and SR3 register to clear eventually pending flags */ (void)I2C->SR1; (void)I2C->SR3; /* If all operations OK, return sEE_OK (0) */ return sEE_OK; }
/** * @brief Writes more than one byte to the EEPROM with a single WRITE cycle. * * @note The number of bytes (combined to write start address) must not * cross the EEPROM page boundary. This function can only write into * the boundaries of an EEPROM page. * @note This function doesn't check on boundaries condition (in this driver * the function sEE_WriteBuffer() which calls sEE_WritePage() is * responsible of checking on Page boundaries). * * @param pBuffer: pointer to the buffer containing the data to be written to * the EEPROM. * @param WriteAddr: EEPROM's internal address to write to. * @param NumByteToWrite: pointer to the variable holding number of bytes to * be written into the EEPROM. * * @retval sEE_OK (0) if operation is correctly performed, else return value * different from sEE_OK (0) or the timeout user callback. */ uint32_t sEE_WritePage(uint8_t* pBuffer, uint16_t WriteAddr, uint8_t* NumByteToWrite) { uint32_t DataNum = 0; #ifdef sEE_M24C08 /* Configure slave address, nbytes, reload and generate start */ I2C_TransferHandling(sEE_I2C, sEEAddress, 1, I2C_Reload_Mode, I2C_Generate_Start_Write); /* Wait until TXIS flag is set */ sEETimeout = sEE_LONG_TIMEOUT; while(I2C_GetFlagStatus(sEE_I2C, I2C_ISR_TXIS) == RESET) { if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } /* Send memory address */ I2C_SendData(sEE_I2C, (uint8_t)WriteAddr); #elif defined(sEE_M24M01) || defined(sEE_M24C64_32) || defined (sEE_M24LR64) /* Configure slave address, nbytes, reload and generate start reload_mode*/ I2C_TransferHandling(sEE_I2C, sEEAddress, 1, I2C_Reload_Mode, I2C_Generate_Start_Write); /* Wait until TXIS flag is set */ sEETimeout = sEE_LONG_TIMEOUT; while(I2C_GetFlagStatus(sEE_I2C, I2C_ISR_TXIS) == RESET) { if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } /* Send MSB of memory address */ // I2C_SendData(sEE_I2C, (uint8_t)((WriteAddr & 0xFF00) >> 8)); /* Wait until TXIS flag is set */ // sEETimeout = sEE_LONG_TIMEOUT; // while(I2C_GetFlagStatus(sEE_I2C, I2C_ISR_TXIS) == RESET) // { // if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); // } /* Send LSB of memory address */ I2C_SendData(sEE_I2C, (uint8_t)WriteAddr ); delayms2(6); //dacus delay #endif /*!< sEE_M24C08 */ /* Wait until TCR flag is set */ sEETimeout = sEE_LONG_TIMEOUT; while(I2C_GetFlagStatus(sEE_I2C, I2C_ISR_TCR) == RESET) { if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } /* Update CR2 : set Slave Address , set write request, generate Start and set end mode */ I2C_TransferHandling(sEE_I2C, sEEAddress, (uint8_t)(*NumByteToWrite), I2C_AutoEnd_Mode, I2C_No_StartStop); while (DataNum != (*NumByteToWrite)) { /* Wait until TXIS flag is set */ sEETimeout = sEE_LONG_TIMEOUT; while(I2C_GetFlagStatus(sEE_I2C, I2C_ISR_TXIS) == RESET) { if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } /* Write data to TXDR */ I2C_SendData(sEE_I2C, (uint8_t)(pBuffer[DataNum])); /* Update number of transmitted data */ DataNum++; } /* Wait until STOPF flag is set */ sEETimeout = sEE_LONG_TIMEOUT; while(I2C_GetFlagStatus(sEE_I2C, I2C_ISR_STOPF) == RESET) { if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } /* Clear STOPF flag */ I2C_ClearFlag(sEE_I2C, I2C_ICR_STOPCF); /* If all operations OK, return sEE_OK (0) */ return sEE_OK; }
/** * @brief Reads a block of data from the EEPROM. * @param pBuffer: pointer to the buffer that receives the data read from * the EEPROM. * @param ReadAddr: EEPROM's internal address to start reading from. * @param NumByteToRead: pointer to the variable holding number of bytes to * be read from the EEPROM. * * @retval sEE_OK (0) if operation is correctly performed, else return value * different from sEE_OK (0) or the timeout user callback. */ uint32_t sEE_ReadBuffer(uint8_t* pBuffer, uint16_t ReadAddr, uint16_t* NumByteToRead) { uint32_t NumbOfSingle = 0, Count = 0, DataNum = 0, StartCom = 0; /* Get number of reload cycles */ Count = (*NumByteToRead) / 255; NumbOfSingle = (*NumByteToRead) % 255; #ifdef sEE_M24C08 /* Configure slave address, nbytes, reload and generate start */ I2C_TransferHandling(sEE_I2C, sEEAddress, 1, I2C_SoftEnd_Mode, I2C_Generate_Start_Write); /* Wait until TXIS flag is set */ sEETimeout = sEE_LONG_TIMEOUT; while(I2C_GetFlagStatus(sEE_I2C, I2C_ISR_TXIS) == RESET) { if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } /* Send memory address */ I2C_SendData(sEE_I2C, (uint8_t)ReadAddr); #elif defined(sEE_M24M01) || defined(sEE_M24C64_32) || defined (sEE_M24LR64) /* Configure slave address, nbytes, reload and generate start */ I2C_TransferHandling(sEE_I2C, sEEAddress, 1, I2C_SoftEnd_Mode, I2C_Generate_Start_Write); /* Wait until TXIS flag is set */ sEETimeout = sEE_LONG_TIMEOUT; while(I2C_GetFlagStatus(sEE_I2C, I2C_ISR_TXIS) == RESET) { if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } /* Send MSB of memory address */ I2C_SendData(sEE_I2C, (uint8_t)(ReadAddr)); //---------------------------------------------- delayms2(6); #endif /*!< sEE_M24C08 */ /* Wait until TC flag is set */ sEETimeout = sEE_LONG_TIMEOUT; while(I2C_GetFlagStatus(sEE_I2C, I2C_ISR_TC) == RESET) { if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } /* If number of Reload cycles is not equal to 0 */ if (Count != 0) { /* Starting communication */ StartCom = 1; /* Wait until all reload cycles are performed */ while( Count != 0) { /* If a read transfer is performed */ if (StartCom == 0) { /* Wait until TCR flag is set */ sEETimeout = sEE_LONG_TIMEOUT; while(I2C_GetFlagStatus(sEE_I2C, I2C_ISR_TCR) == RESET) { if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } } /* if remains one read cycle */ if ((Count == 1) && (NumbOfSingle == 0)) { /* if starting communication */ if (StartCom != 0) { /* Configure slave address, end mode and start condition */ I2C_TransferHandling(sEE_I2C, sEEAddress, 255, I2C_AutoEnd_Mode, I2C_Generate_Start_Read); } else { /* Configure slave address, end mode */ I2C_TransferHandling(sEE_I2C, sEEAddress, 255, I2C_AutoEnd_Mode, I2C_No_StartStop); } } else { /* if starting communication */ if (StartCom != 0) { /* Configure slave address, end mode and start condition */ I2C_TransferHandling(sEE_I2C, sEEAddress, 255, I2C_Reload_Mode, I2C_Generate_Start_Read); } else { /* Configure slave address, end mode */ I2C_TransferHandling(sEE_I2C, sEEAddress, 255, I2C_Reload_Mode, I2C_No_StartStop); } } /* Update local variable */ StartCom = 0; DataNum = 0; /* Wait until all data are received */ while (DataNum != 255) { /* Wait until RXNE flag is set */ sEETimeout = sEE_LONG_TIMEOUT; while(I2C_GetFlagStatus(sEE_I2C, I2C_ISR_RXNE) == RESET) { if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } /* Read data from RXDR */ pBuffer[DataNum]= I2C_ReceiveData(sEE_I2C); /* Update number of received data */ DataNum++; (*NumByteToRead)--; } /* Update Pointer of received buffer */ pBuffer += DataNum; /* update number of reload cycle */ Count--; } /* If number of single data is not equal to 0 */ if (NumbOfSingle != 0) { /* Wait until TCR flag is set */ sEETimeout = sEE_LONG_TIMEOUT; while(I2C_GetFlagStatus(sEE_I2C, I2C_ISR_TCR) == RESET) { if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } /* Update CR2 : set Nbytes and end mode */ I2C_TransferHandling(sEE_I2C, sEEAddress, (uint8_t)(NumbOfSingle), I2C_AutoEnd_Mode, I2C_No_StartStop); /* Reset local variable */ DataNum = 0; /* Wait until all data are received */ while (DataNum != NumbOfSingle) { /* Wait until RXNE flag is set */ sEETimeout = sEE_LONG_TIMEOUT; while(I2C_GetFlagStatus(sEE_I2C, I2C_ISR_RXNE) == RESET) { if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } /* Read data from RXDR */ pBuffer[DataNum]= I2C_ReceiveData(sEE_I2C); /* Update number of received data */ DataNum++; (*NumByteToRead)--; } } } else { /* Update CR2 : set Slave Address , set read request, generate Start and set end mode */ I2C_TransferHandling(sEE_I2C, sEEAddress, (uint32_t)(NumbOfSingle), I2C_AutoEnd_Mode, I2C_Generate_Start_Read); /* Reset local variable */ DataNum = 0; /* Wait until all data are received */ while (DataNum != NumbOfSingle) { /* Wait until RXNE flag is set */ sEETimeout = sEE_LONG_TIMEOUT; while(I2C_GetFlagStatus(sEE_I2C, I2C_ISR_RXNE) == RESET) { if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } /* Read data from RXDR */ pBuffer[DataNum]= I2C_ReceiveData(sEE_I2C); /* Update number of received data */ DataNum++; (*NumByteToRead)--; } } /* Wait until STOPF flag is set */ sEETimeout = sEE_LONG_TIMEOUT; while(I2C_GetFlagStatus(sEE_I2C, I2C_ISR_STOPF) == RESET) { if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); } /* Clear STOPF flag */ I2C_ClearFlag(sEE_I2C, I2C_ICR_STOPCF); /* If all operations OK, return sEE_OK (0) */ return sEE_OK; }