When I set up a nominally 400 kbit/s software I2C bus on an ESP32 it runs significantly faster than when I set it up as a hardware I2C bus at the same frequency. Should this not be the other way around, if there's any difference at all? I'm interested in this as I'd like to minimise time taken by I2C communications. The software I2C bus takes about 250 μs to read one byte from a peripheral's register, whereas the hardware implementation takes about 420 μs.
I see from github that there's some granularity in the achievable bus frequencies for a software I2C implementation, but if I understood this correctly they shouldn't be faster than specified, so that doesn't seem to explain it.
Does anyone have any suggestions for why this may be, or hints about how I can make sure that my I2C bus is going at it's full speed?
Further info:
I'm using micropython v1.12 on an ESP32-WROOM-32D on a DFRobot Firebeetle board, communicating with an LSM9DS1 sensor (that supports an I2C frequency of up to 400 kbit/s). The software I2C bus is set up as follows:
Code: Select all
from machine import Pin, I2C
i2c = I2C(-1, scl=Pin(22), sda=Pin(14), freq=400_000)
Code: Select all
from machine import Pin, I2C
i2c = I2C(0, scl=Pin(22), sda=Pin(14), freq=400_000)
Matt