I2C stuck after some time
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-12-02 6:34 AM
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
- Labels:
-
I2C
-
STM32Cube MCU Packages
-
STM32L0 Series
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-12-02 7:23 AM
- Switch the pins to open-drain output mode, and set SCL to 1. If it goes high, go to 3.
- 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).
- 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.
- Reset the master I2C controller in the RCC.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-12-03 1:57 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-12-03 2:32 AM
Are you using low power Stop mode in your application? Check the errata.
Anyway, pulsing the corresponding I2C reset bit in RCC should help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-12-03 11:41 PM
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
