I have an python daemon running on Raspberry Pi. The daemon reads and writes value to chip connected with I2C bus. The chips are:
- MCP23008 (digital IO)
- MCP3428 (analog in)
- MCP4728 (analog out)
The daemon has a monitoring thread that performs read on the chips, sleeps for some time and repeats. If any change occurs, it's notified to a remote host.
Some time ago I've encountered an issue. Monitoring thread stopped reporting any value change. I think that it was stuck on some I2C IO operation, since there is no other blocking operations in it.
I did some research and discovered that I2C specification does not have any timeout condition (http://www.i2c-bus.org/i2c-primer/obscure-problems/ and SMBus specs at page 58). The problem happened once and on prototype board, whose wiring is surely not perfect.
In addition, two different libraries are user for I2C communication. For MCP3428 python-smbus is used. For MCP4728 python-pigpio is used. This choice derives from the fact that MCP4728 need some commands that does not fit SMBUS transmission paradigm. I don't know if there can be a conflict of any kind.
I want to protect my daemon from such issue. So I have several questions:
- how do I recover from such a blockage?
- do I need to close/open I2C handle?
- or reset I2C bus?
- or reset the whole system?
- do pigpio library has the possibility to set read/write timeouts?