Question
I2C read() strange status register in SR2
Posted on November 01, 2012 at 17:32
Hi all,
I have a problem on my I2C2 configuration on STM32F4. I try in poll mode first, and I have strange result : write() seems to be ok, but not read() (see comments in code below) :uint8_t data_received[16];
I2C_GenerateSTART(I2C2, ENABLE);
while
(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_MODE_SELECT)) {
;
}
I2C_Send7bitAddress(I2C2, COMPASS_ADDRESS_ADFAR, I2C_Direction_Receiver);
while
(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));
I2C_SendData(I2C2, ConfigRegA );
////////// This will never return from while :
// while (!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_BYTE_TRANSMITTED)); /// SR2 = 00 00 00 00 00 00 01 11 SR1 = 00 00 00 00 10 00 01 00
////////// But I can pass this step by doing CUSTOM CHECK
while
(!I2C_CheckEvent(I2C2, 0x00030044));
/// SR2 = 00 00 00 00 00 00 00 11 SR1 = 00 00 00 00 01 00 01 00
while
(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_BYTE_RECEIVED));
/// SR2 = 00 00 00 00 00 00 00 11 SR1 = 00 00 00 00 01 00 00 00
data_received[0] = I2C_ReceiveData(I2C2);
I2C_GenerateSTOP(I2C2, ENABLE); So the TRA bit from SR2 register is not set as it should be... But it should be, don't it ?
Thanks in advance for your help
#i2c #i2c #i2c #i2c-poll-tra-sr2