cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103XX I2C Busy Flag after unsuccessful transfer

aprokudin1978
Associate II
Posted on May 31, 2015 at 14:01

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 #stm32f103
4 REPLIES 4
tescaflown
Associate II
Posted on May 31, 2015 at 15:16

Hello,

did you mesure the Data / Clk voltage to see if your bus is really busy.

if yes and if it's side STM, I presume the start was ok, even if you have a nack, you need to send a stop to release the bus.

If it's not the STM side but from the other device, try to unplug it. If you have no problem of releasing the bus. That means your other device keep the bus busy...

Best regards,

Tesca

aprokudin1978
Associate II
Posted on May 31, 2015 at 15:57

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 :)

aprokudin1978
Associate II
Posted on May 31, 2015 at 16:11

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.

tescaflown
Associate II
Posted on May 31, 2015 at 23:06

Thanks for your feedback.

BR