2
\$\begingroup\$

I have a problem with an I2C communication and want you to ask whether there is a better solution than mine.

I am programming an STM32F103 at the moment. There is one sensor (MPU6050) which is connected via I2C to the STM32. I recognized that if I reset the STM32 a few times, the STM32 gets stuck (or got an timeout error) during the initialization of the I2C. The timeout error was during the wait of the busy flag. So the I2C communication was "occupied". The MPU6050 is the only other I2C device (slave).

In my opinion there is an error, because I was reading a register from the MPU6050 when I reset the STM32. So the MPU6050 never gets the stop condition.

I do not know how to reset the I2C connection, when the bus is "occupied" (by the MPU6050). So my solution would be to do a hardware reset with a transmission gate of the MPU6050. Is there maybe a simpler software solution?

Thanks for the help.

\$\endgroup\$
6
\$\begingroup\$

One general solution to unsticking an I2C bus is to just clock the SCL line for 18 or more cycles. This will clock the rest of the current byte out of the slave, let it see a NACK and then clock out one more byte. However, if the slave is very confused, this may not work. Also, most hardware I2C modules cannot do this so you would need to take control of the I2C lines as GPIOs and clock it manually.

Externally driving a reset line to the slave is the best solution. Also, some slaves can be configured to timeout after a relatively long time (e.g. 250 ms).

\$\endgroup\$
  • 4
    \$\begingroup\$ +1 I believe this issue is documented in an old Philips AppNote, but I can't find it right now. So in case it helps readers, here's a link to Analog Devices AppNote AN-686 which also describes the problem and the approaches you kindly mentioned, for those who want more reading material on the topic. \$\endgroup\$ – SamGibson Aug 19 '18 at 22:13
  • \$\begingroup\$ Thanks. Yeah like in the document at figure 1, I would do a cut of the power line to reset the MPU6050. \$\endgroup\$ – Lukas_M94 Aug 20 '18 at 5:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.