Associate III
April 27, 2016
Question
I2C Stop after Address
- April 27, 2016
- 2 replies
- 1657 views
Posted on April 27, 2016 at 13:45
Hello,
I am trying to handle I2C bus errors on the master side => get the I2C bus working again after detecting an error. (MCU: STM32F407) In the following test, the master send an Address + Read command to a none existing slave address. The firmwaredetect the none responding slave with a 20us time-out and try to reset the bus. But after trying several methods to reset the bus, I always get the same problem: Next time I try an Address + Read, the master send a stop condition mediately after the Slave NACK (or ACK if the slave is connected) Any idea on what could get the master to send a stop condition after sending an address? I tried to disable the stop condition just before sending the address, no change. Thanks!
/* Start condition */
I2C_GenerateSTART(I2Cx, ENABLE);
while
(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_MODE_SELECT));
/* Address + Read */
I2C_Send7bitAddress(I2Cx, Addr, I2C_Direction_Receiver);
/* Wait for Slave ack or time-out */
Tempo_StartTimeOut(WAIT_ACK);
while
(!I2C_GetFlagStatus(I2Cx, I2C_FLAG_ADDR))
{
if
(Tempo_IsTimeOut())
{
(
void
)(I2Cx->SR1);
// Clear ADDR flag
(
void
)(I2Cx->SR2);
ResetBus();
return
false
;
}
}
#i2c-error-handling