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.
unable to recover from I2C bus error
OK this version (1.5.2) has introduced a breaking change for I2C.
It is impossible to recover from an I2C bus error
1.5.1
from pyb import I2C
i2c=I2C(2,I2C.MASTER)
i2c.mem_write(8,76,112) # force a reset causes i2c error (but not until we next do a read)
i2c.init(I2C.MASTER) # reset the i2c bus to recover
i2c.mem_read(1,76,112) # works
1.5.2
from pyb import I2C
i2c=I2C(2,I2C.MASTER)
i2c.mem_write(8,76,112) # force a reset causes i2c error
i2c.init(I2C.MASTER) # reset the i2c bus to recover
i2c.mem_read(1,76,112) # nope doesnt work OSError 116
i2c=I2C(2,I2C.MASTER) # see if this works
i2c.mem_read(1,76,112) # nope doesnt work
see:
http://forum.micropython.org/viewtopic.php?f=2&t=1027