cancel
Showing results for 
Search instead for 
Did you mean: 

I2C stuck after some time

Mvill.17
Associate III

I'm working with STM32L0 and use the I2C to read some registers of a bms by TEXAS.

I perform some I2C reading once every seconds using HAL_I2C_Master_Transmitand HAL_I2C_Master_Receive and everything work well maybe for hours. Then unexpectedly something goes wrong and I2c get stuck.

In these condition SCL is always LOW ( it rises no more ) and the the BUSY is ON. Every other reading fails and I don't know how to recover from this situation.

Anybody can help me?

Thanks

4 REPLIES 4
berendi
Principal
  1. Switch the pins to open-drain output mode, and set SCL to 1. If it goes high, go to 3.
  2. The slave is stuck. If it has a reset pin, toggle it. If it doesn't have one, find a way to cut its supply voltage for a moment while setting both SCL and SDA to 0 (so it doesn't get powered through some protection diodes).
  3. If SDA is stuck low too, then toggle SCL until it rises. If it doesn't go high at the 10th SCL pulse, go to 2.
  4. Reset the master I2C controller in the RCC.
Mvill.17
Associate III

Thanks I'll try to put in action your suggestion.

I used lot of times the I2C and have never had such problems.

This is the 1st time I used I2C master with this uC: just transmit and wait for an answer with the HAL library. Very easy.

Pull up resistors are 4k7, cable length ise less than 20 cm and signal waves seem OK

I can't explain why after so many I2C transactions the bus get stuck. I disconnected the

cable and SCL remains low so I think it's just the master that is stuck

Many thanks

Are you using low power Stop mode in your application? Check the errata.

Anyway, pulsing the corresponding I2C reset bit in RCC should help.

Mvill.17
Associate III

Are you referring to the point: "I2C and USART cannot wake up he device from Stop mode" reported in the errata sheet?

Well my uC never enters the stop mode.

I reinitialized the I2C when some error occurs:

if (I2Cread() == OK)

{

// do something

}

else

{

MX_I2C1_Init(); // method provide by CubeMX to reinitialize the I2C

}

Yesterday it worked all day without stopping.

Thanks for your help. I will let you know