GyverLibs / microDS3231

Лёгкая библиотека для работы с RTC DS3231 для Arduino
MIT License
20 stars 7 forks source link

I2C Clear Bus #16

Open miyalisya opened 3 months ago

miyalisya commented 3 months ago

https://github-wiki-see.page/m/Koepel/How-to-use-the-Arduino-Wire-library/wiki/How-to-unlock-a-stuck-I2C-bus https://www.forward.com.au/pfod/ArduinoProgramming/I2C_ClearBus/index.html Arduino-Wire-library GitHub Wiki How to unlock a stuck I2C bus Introduction The I2C bus is stuck when a device is in a erroneous mode and keeps the SDA or SCL low. Some I2C devices are not according to the standard for the I2C bus and some are, but can still cause the I2C bus to be stuck. For example when the SDA signal is held low by a I2C device, then the I2C bus is stuck. The most common solution is to send out a few clock pulses followed by a STOP condition.

SDA is kept low To be able to create clock pulses, it is best to turn off the Arduino Wire control of the SDA and SCL pins with Wire.end(). The Arduino pins can toggle between high impedance and a strong low output, thus creating a open-source output. About 9 clock pulses should be enough, but there are non-standard I2C devices for 16-bit data. That would require 17 clock pulses. With a few extra, that makes 20 clock pulses.

See the explanation and code by Matthew Ford: www.forward.com.au/pfod/ArduinoProgramming/I2C_ClearBus.

Every Arduino board has the definition of 'SDA' and 'SCL' for the pins of the I2C bus. However, some boards allow to create a I2C bus on other pins. In that case the real pin numbers should be used instead of 'SDA' and 'SCL'.

SCL is kept low Most sensors are not able to pull the SCL signal low. Only microcontrollers and processors can pull the SCL signal low. When the SCL is held low, it is no longer possible to send a few clock pulses. There is probably a bug in the software when this happens. Perhaps the bad device will reset after some time. The solution is to wait a few seconds, and if it still exists then give up. The whole project needs to be reset or restarted.

Notes Thanks to MagierPhil for investigating this when he encountered a problem on the I2C bus with a DS3231.

GyverLibs commented 3 months ago

So what?