Skip to main content
YGail.1
Associate
January 25, 2020
Question

I2C seems blocked when restarting Debug session

  • January 25, 2020
  • 2 replies
  • 1254 views

Hi,

I have some troubles with my Nucleo STM32F446RE communicating with my MPU6050 IMU over I2C. When powering everything the first time and debug it, it works fine. However, when restarting with exactly the same code, the board fails to start the I2C clock returning HAL_I2C_ERROR_ARLO error code, then I have to shut everything down and hope next session will work (pretty annoying).

When I power up and program start autonomously without debug session, I2C works well. So it seems that the debug session is actually the problem.

I'm using Visual GDB as cross compiler, but had the same error with STM32 IDE.

Thx for any help.

This topic has been closed for replies.

2 replies

waclawek.jan
Super User
January 25, 2020

If you reset the I2C master (here, the STM32) amidst communication, when the slave is responding and holding SDA low, the master won't be able to reacquire the bus. You'll need to perform up to 9 SCL pulses ("manually"), and then perform a STOP (or a START-STOP), to bring the slave to a known state.

The 9-pulse recovery is part of the I2C specification, UM10204 of Philips/NXP/nexperia/whatever-they-are-called-this-week, chapter 3.1.16 Bus clear.

That said, not all slaves are compliant ie. they don't always reset properly their internal state machine upon STOP as the standard requires. In that case you are out of luck and then you need to modify the hardware so that the master can power down/up such slave, to bring it to known state.

JW

YGail.1
YGail.1Author
Associate
February 4, 2020

Hi,

thx for helping, indeed it was the slave fault. I found an easier way than sending 9 SCL pulses (don't know how to do it). I implemented a delay before I2C starts, so I can reset before slave hold the line.