I2C bus recovery
I wonder how useful would it be to add a bus recovery mechanism to the software I2C implementation. It would be something similar to what is discussed here: https://github.com/esp8266/Arduino/issues/1025
The particular use case is when either the slave or the master get reset in the middle of a transmission, and leave the bus in inconsistent state, usually with the other party pulling one of the lines down and preventing communication. This can easily happen when we are doing aggressive power management, entering deep sleep or cutting power to the sensors.
The proposed solution is to strobe the clock line several times and send a NACK, to make sure all the devices on the bus get to finish the last byte they were sending.
machine_i2c: Add I2C bus clear support.
I have some software that is using I2C on the rp2040. Over a couple of months of continuous running there have been some failed transactions resulting in exceptions. Since these are rare, and, the i2c waveform is not too pretty when looked at with an oscilloscope, I presume my hardware implementation is at fault. Nevertheless, since this system is running 24/7 in a critical environment it is essential to be able to recover from these crashes. The proper way to do this is to send an I2C bus clear sequence (a.k.a. software reset) and retry. To do the bus clearing you simply send 10 negative pulses on SCL. This clocks out potential stuck data in the output registers of peripherals.
This PR implements:
- API backend support for sending an I2C bus clear sequence
- accessible from python by
i2c.clear_bus()
- accessible from python by
- said function in the:
- soft I2C driver
- rp2 I2C driver