Closed caternuson closed 4 years ago
Could you zoom in on the trace so we can see what the response was? Thanks!
Here's a zoom on the response. SDA/SCL state remain unchanged for rest of trace. Attached the trace file also.
I'm thinking this has something to do with bitbangio and clock stretching.
I didn't even need to use the drivers. I was able to see an issue with just this simple test:
>>> import board, busio
>>> from adafruit_bus_device.i2c_device import I2CDevice
>>> i2c = busio.I2C(board.SCL, board.SDA)
>>> device = I2CDevice(i2c, 0x28)
Tested with a Feather M0 Express and Feather ESP8266 using a TCS347245 and a BNO055. Here's what it looks like under the scope:
Feather M0 Express w/ TCS34725
No clock stretching, all good:
Feather M0 Express w/ BNO055
Some clock stretching in the ACK, but it handles it, all good:
Feather ESP8266 w/ TCS34725
No clock stretching, all good:
Feather ESP8266 w/ BNO055
It doesn't like that clock stretch :(
The code for clock stretching in bitbangio is here: https://github.com/adafruit/circuitpython/blob/master/extmod/machine_i2c.c#L56-L61
Personally I don't see anything wrong with it, but maybe I'm missing something...
Hmm, looking at the shared-module
, it seems the code I linked above is not used. Instead, this is used: https://github.com/adafruit/circuitpython/blob/master/shared-module/bitbangio/I2C.c#L53-L55 which is the old version with the time stretch timeout hard-coded to 255µs — but that should still work, as on the trace the stretch is a bit over 100µs, so I still have no idea.
Could it be that there is enough delay between releasing the SCL pin and releasing SDA pin, that ACK is missed?
Blaming this on clock stretching may be a red herring.
It seems to be more related to specific timing issues with specific sensors. As an example, can get the same failure on the Feather M0 Express w/ BNO055 combo using bitbangio
instead of busio
, like this:
>>> import board, bitbangio
>>> from adafruit_bus_device.i2c_device import I2CDevice
>>> i2c = bitbangio.I2C(board.SCL, board.SDA)
>>> device = I2CDevice(i2c, 0x28)
and here's the trace:
Note the difference in timing on SCL between
bitbangio
(~40kHz) and busio
(~333kHz)
@caternuson Is this still an issue?
@kattni Unknown. The landscape has changed so much (ESP8266 is no longer supported and bitbangio isn't in M0 builds) that I'd say let's just close this and if there is still some issue, we can open a new one with updated info and testing when we hit it.
Not sure if this is related to #2 or not. The traces look different, so maybe bitbangio is playing into it? It's failing before it even gets to the reset part.