i2c instability
Posted: Thu Aug 31, 2017 8:59 pm
I've been trying to use the I2C for a number of digital sensors. They're generally 3.3V-5V capable, and for the 5V ones, I have a mosfet-based bi-directional level shifter.
Just testing the port using the arduino i2c scanner example and have it compiled+flashed via the Arduino IDE using the latest Arduino-ESP library. I've also tried the esp-idf and modified the i2c example to generate the same queries. In both cases the code basically goes through every address and simply writes the 7 bits, write bit, and then sees if there's an ACK from a slave on the bus responding to that particular address. Probing SDA/SCL without anything attached shows the correct i2c stream generated (using a bitscope micro as a logic analyzer).
However, as soon as I start trying the actual sensors, I get extremely unreliable behaviour: some devices get polled correctly, but after replugging it, the i2c port may stop working. Some devices will cause the ESP to hang completely, while others don't respond. I've tried different combinations of internal pullu-ps only as well as disabling them and using external pullups. Also tried with and without level shifting. It seems like the port is either very sensitive hardware-wise, or the i2c driver has a lot of places where it hangs/stops working. Sometimes the code still runs, but I don't see any signals on scl/sda...
My goal was to build a general purpose interface that allows plug-and-play for various i2c based sensors, but it looks like the current state of the i2c implementation might not be developed to that point yet? In contrast, I've used the same sensors (and just tried the scanning sketch) on an Arduino Uno and it works flawlessly. Also no issues running them with a Raspberry Pi using the bi-directional level shifter...
Comments/suggestion welcome!
Just testing the port using the arduino i2c scanner example and have it compiled+flashed via the Arduino IDE using the latest Arduino-ESP library. I've also tried the esp-idf and modified the i2c example to generate the same queries. In both cases the code basically goes through every address and simply writes the 7 bits, write bit, and then sees if there's an ACK from a slave on the bus responding to that particular address. Probing SDA/SCL without anything attached shows the correct i2c stream generated (using a bitscope micro as a logic analyzer).
However, as soon as I start trying the actual sensors, I get extremely unreliable behaviour: some devices get polled correctly, but after replugging it, the i2c port may stop working. Some devices will cause the ESP to hang completely, while others don't respond. I've tried different combinations of internal pullu-ps only as well as disabling them and using external pullups. Also tried with and without level shifting. It seems like the port is either very sensitive hardware-wise, or the i2c driver has a lot of places where it hangs/stops working. Sometimes the code still runs, but I don't see any signals on scl/sda...
My goal was to build a general purpose interface that allows plug-and-play for various i2c based sensors, but it looks like the current state of the i2c implementation might not be developed to that point yet? In contrast, I've used the same sensors (and just tried the scanning sketch) on an Arduino Uno and it works flawlessly. Also no issues running them with a Raspberry Pi using the bi-directional level shifter...
Comments/suggestion welcome!