2015-05-31 05:01 AM
Hi everyone. Did anybody deal with situation when I2C flag keeps being set after unsuccessful transfer (write). Lets imaging that your slave device is not connected right now or it fails to respond. First call to I2C-> HAL_I2C_Master_Transmit fails with HAL_TIMEOUT. After that, SR2 register has a I2C_FLAG_BUSY set and where is no way to clear it or I have found none. Call to deinit and then init to I2C does nothig, How do i reset I2C bus to clear that bit?
#i2c #stm32f1032015-05-31 06:16 AM
2015-05-31 06:57 AM
Hello Tesca! Thanks a Lot! The problem is on STM32 side. I did what you have recommend to me. I've copied some code from HAL driver that sends a STOP and waits for a BUSY bit to be reset. It did help.
SET_BIT(hi2c1.Instance->CR1, I2C_CR1_STOP); I2C_WaitOnFlagUntilTimeout(&hi2c1, I2C_FLAG_BUSY, SET, 1000);PS: May be a 1000 ms is too much, but it works 🙂2015-05-31 07:11 AM
I think the code I have added to my logic has to be placed into HAL driver implementation. I have found some other BUGS in that driver like doing __HAL_LOCK(hi2c) with no UNLOCK when exiting with HAL_TIMEOUT. One place had a code with disabling interrupts and exit without enabling it again. The result is HAL_Dalay() keeps running in infinite loop. 🙂
Thanks again.2015-05-31 02:06 PM