-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Espressif: 10ms gap between I2C transactions #6263
Comments
This comment was marked as off-topic.
This comment was marked as off-topic.
@Neradoc noted in discord:
|
This comment was marked as off-topic.
This comment was marked as off-topic.
To illustrate what I mentioned on discord, here is a low level test code I've been running, with a couple different I2C devices. It does only 2 reads in this case, I've tried different combinations depending on what the devices support with the same results: import board
import busio
import time
ADDRESS = 0x20
buffer = bytearray([0] * 10)
def measure_time(frequency = 100_000, nsamples = 10):
print(f"Frequency @ {frequency:7d}", end="")
with busio.I2C(scl=board.SCL, sda=board.SDA, frequency=frequency) as i2c:
times = 0
for i in range(nsamples):
i2c.try_lock()
t0 = time.monotonic_ns()
i2c.readfrom_into(ADDRESS, buffer)
i2c.readfrom_into(ADDRESS, buffer)
# i2c.writeto(ADDRESS, buffer)
# i2c.writeto_then_readfrom(ADDRESS, buffer, buffer)
t1 = time.monotonic_ns()
i2c.unlock()
times += (t1 - t0)
mean = times // nsamples // 1000 / 1000
print(f" {mean:8.3f} ms")
import random
frequencies = [50_000, 80_000, 100_000, 110_000, 120_000, 200_000, 400_000]
# frequencies.sort(key=lambda x: random.random())
for freq in frequencies:
measure_time(freq)
|
Some more findings:
|
what if you change it to like 500? |
The gap at 100 kHz bus frequency is the interval defined by I wrote this observation up in espressif/esp-idf#8770 as well. |
I have reproduced this in a small ESP-IDF example. It is related to clock frequency, and can be ameliorated by a small delay in the ESP-IDF code at a crucial spot. |
should this really be closed, or should it wait for us to switch to this submodule & ref in main? |
I did not mean to link the issue. |
CircuitPython 7.2.5: tested on FeatherS2 and Adafruit Feather ESP32-S2. Also true as far back as 6.3.0 (did not test further back).
Using the PCA9685 driver, there is at minimum an almost 10ms gap between any two I2C transactions. This causes stepper motor rotations to be very slow, etc. This slowness was first noticed by a user here: https://forums.adafruit.com/viewtopic.php?f=60&t=190046.
I see a similar 10ms gap in some case in the SHT4x library, so I think it is generic to I2C.
The text was updated successfully, but these errors were encountered: