STM32F446RET6: I2C Invalid address after repeated start
Hello,
While working with STM32F446RET6, I encountered a problem with I2C1. When using HAL_I2C_Mem_Read_IT(), an error occasionally occurs in the form of sending 0x00 instead of the address with the read bit after Repeated Start. The error seems to only occur with O3 optimization.
I2C Configuration:

NVIC Configuration:

Only TIM1 update interrupt (TIM10 not used), DMA1 stream2 (SPI3_RX) and DMA1 stream5 (SPI3_TX) have higher priority than I2C1.
Here is an example of a correct signal:

The signal with error and I2C_Flush_DR() looks like this:

static void I2C_Flush_DR(I2C_HandleTypeDef *hi2c)
{
/* Write a dummy data in DR to clear TXE flag */
if (__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_TXE) != RESET)
{
hi2c->Instance->DR = 0x00U;
}
} The signal and I2C_Flush_DR() looks like this:

static void I2C_Flush_DR(I2C_HandleTypeDef *hi2c)
{
/* Write a dummy data in DR to clear TXE flag */
if (__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_TXE) != RESET)
{
hi2c->Instance->DR = 0xF4U;
}
} As you can see, this happens because I2C_Flush_DR() is called at the wrong time, but I don't know why. The slave address should be written to the DR register, but the value from I2C_Flush_DR() is written instead.
Can anybody help?
Thanks,
Arek
