2014-07-08 02:33 AM
Hi i have e following code for communication with an I2C Device.
#define DEVICE_ADDR 0x14
#define DEVICE_READ 0x4c
Therm_Timeout = 10 * Therm_LONG_TIMEOUT;
while(I2C_GetFlagStatus(DEVICE_I2C, I2C_ISR_BUSY) != RESET)
{
if((Therm_Timeout--) == 0)
return Therm_TIMEOUT_UserCallback();
}
for (x = 0 ; x < 0xFFFFF ; x++)
/* Configure slave address, nbytes, reload, end mode and start or stop generation */
I2C_TransferHandling(DEVICE_I2C, DEVICE_ADDR, 1, I2C_SoftEnd_Mode, I2C_Generate_Start_Write);
//for (y = 0 ; y < 0xFFFFF ; y++);
/* Wait until TXIS flag is set */
Therm_Timeout = Therm_LONG_TIMEOUT;
while(I2C_GetFlagStatus(DEVICE_I2C, I2C_ISR_TXIS) == RESET)
{
if((Therm_Timeout--) == 0)
return Therm_TIMEOUT_UserCallback();
}
/* Send Register address */
I2C_SendData(DEVICE_I2C, (uint8_t)DEVICE_READ);
// NEED TO GENERATE RESTART CONDITION HERE
I2C_GenerateSTART(DEVICE_I2C, ENABLE);
while(I2C_GetFlagStatus(I2C1,I2C_FLAG_BUSY));
/* Wait until TC flag is set */
Therm_Timeout = 10 * Therm_LONG_TIMEOUT;
while(I2C_GetFlagStatus(DEVICE_I2C, I2C_ISR_TC) == RESET)
{
if((Therm_Timeout--) == 0)
return Therm_TIMEOUT_UserCallback(); // Program TIMEOUT here
}
/* Configure slave address, nbytes, reload, end mode and start or stop generation */
I2C_TransferHandling(DEVICE_I2C, DEVICE_ADDR, 35, I2C_AutoEnd_Mode, I2C_Generate_Start_Read);
/* Wait until all data are received */
while (DataNum != 35){
/* Wait until RXNE flag is set */
Therm_Timeout = Therm_LONG_TIMEOUT;
while(I2C_GetFlagStatus(DEVICE_I2C, I2C_ISR_RXNE) == RESET){
if((Therm_Timeout--) == 0)
return Therm_TIMEOUT_UserCallback();
}
/* Read data from RXDR */
DEVICE_BufferRX[DataNum]= I2C_ReceiveData(DEVICE_I2C);
/* Update number of received data */
DataNum++;
}
/* Wait until STOPF flag is set */
Therm_Timeout = Therm_LONG_TIMEOUT;
while(I2C_GetFlagStatus(DEVICE_I2C, I2C_ISR_STOPF) == RESET)
{
if((Therm_Timeout--) == 0)
return Therm_TIMEOUT_UserCallback();
}
/* Clear STOPF flag */
I2C_ClearFlag(DEVICE_I2C, I2C_ICR_STOPCF);
STM_EVAL_LEDOn(LED10);
The protocol is shown in the image above. How can i generate a re-start condition. i have tried
I2C_GenerateSTART(DEVICE_I2C, ENABLE);
while(I2C_GetFlagStatus(I2C1,I2C_FLAG_BUSY));
but it still when into the timeout. Thanks.
#wait-for-you--clive1-!-!-! #i2c #stm32