I2C Clock Stretching
Hi there Pycom folks! Hope you had a restful weekend!
I was hoping you could shed some light on something I've been banging my head on today. I am trying to implement the Bosch BNO055 IMU fusion sensor based on the Adafruit breakout: https://www.adafruit.com/products/2472
What's happening is that I can't get the sensor to communicate on the I2C bus at baud rates any higher than 1000 (ugh). According to the datasheet (see table 4.8: I2C Timings), the sensor supports fast mode (400,000).
After going through the datasheet a few more times, the only thing that really stands out to me is that this sensor uses I2C "clock stretching". This correlates with how the official Adafruit Arduino driver sets up the sensor: https://github.com/adafruit/Adafruit_BNO055/blob/master/Adafruit_BNO055.cpp#L60
The stock I2C driver in micropython seems to know about clock stretching, too:
But, in the ESP32 I2C driver, it would seem these functions are completely (and conspicuously) absent. According to http://www.i2c-bus.org/clock-stretching/, "Clock stretching sounds a bit odd but is common practice."
So, my esteemed Pycom team, do you have a suggested workaround or any plans to implement this? It would seem, at least according to the available data, that the I2C functions for ESP32 would not be complete without it.
look at current firmware 1.7.6 there are some i2c releated fixes for hardware init
@jmarcelino Hmmm. It looks like the '323' issue applies to I2C slave mode only, but some clarification would be nice. We have some testing to do with the new I2C HW support (and we were having troubles with certain I2C peripherals when it comes to clock stretching); I'll see if we can do some specific tests with and without clock stretching to see how the HW I2C handles it.
The new firmware 1.7.5.b2 (like previous 1.7.5.b1) has hardware I2C and should support clock line stretching
Update: maybe I spoke too soon: https://github.com/espressif/esp-idf/issues/323 not sure if this means no clock stretching at all or just when I2C is slave
any news on this topic?
The I2C clock frequency setting is also not accurate.
baudrate=400000 results in an actual clock of 297kHz
baudrate=100000 results in an actual clock of 87.6kHz
baudrate=40000 results in an actual clock of 39kHz
@abilio, sounds good to me. Thanks again!
@brotherdust, our plan is to first complete the basic functionality of the board, and then go into specific details like this one in a second round. Of course, people's requests are also important :)
@abilio, thanks for the info! Feature requests are placed under issues, correct? On another note, is clock stretching any different for the ESP32? Or, to rephrase, is there any technical reason why it hasn't been done?
Hi @brotherdust, we haven't implemented clock stretching yet, I'll take note of your request. If you want, you can also go and add a feature request on github, so you'll get status updates :)