-
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
i2c default clock speed for Pi Pico (RP2040) is 90.9kHz (and 400kHz is around 265kHz) #4466
Comments
I tried some 4 byte writes as I'm pretty sure I've read a discussion (perhaps with @Gadgetoid) about the special case bitbang code kicking in at The trace looks very different for 4 byte write. Here's first part. It's sped up a bit to 265kHz but it's still not the requested 400kHz. I found related tickets: #4315 and #4378 and maybe raspberrypi/pico-sdk#252 |
@kevinjwalters yes currently any write <= 2 bytes will go through a bitbangio instance: circuitpython/ports/raspberrypi/common-hal/busio/I2C.c Lines 159 to 161 in 98425c9
I've got an outstanding PR to change this to |
@kevinjwalters The 2 bytes-or-fewer writes are done using bitbangio and I would expect their timing to be approximate. The other off-timing may be due to clock divisor granularity. |
FYI, my PyPortal (SAMD51 / M4) talking to its ADT7410 running |
@dhalbert 786k is the new 400k.
From three runs measuring a chunk of clock pulses
Does this mean it's a bug in https://github.com/raspberrypi/pico-sdk ? |
The speeds you ask for may not be precisely available based on the way the peripheral clock is generated. It's usually generated by dividing a higher-speed clock. I don't think it's necessarily a bug; you'd need to study the clock setting in the I2C driver. This is common: for instance, when we have high SPI speeds on other chips, they are very approximate because the divisors are quite small. EDIT: It may also be the case that the speeds deemed to be made available are only 100k and 400k (and maybe 1MHz) also. So it picks the closest lower speed, for example. |
So based on your testing of 4-byte writes this issue title could be revised. |
We just pass the frequency on to the |
That's what I thought. I put in raspberrypi/pico-sdk#283 for this. I'll close this when it's acknowledged by RPi folk. It's curious the bitbang code is slow. 400kHz looks like it should make the Would be interesting to hear from anyone who has timed SDK's |
This is the RP2040 doing clock stretching apparently and pull-ups have an effect on speed. It will be interesting to see if it's doing it in appropriate places for fast mode. |
I've not had any particular i2c issues but looking at #4082 the clock speed looked wrong on both boards including the Pi Pico running
6.2.0-beta.1
. Here's a view from Ikalogic SQ25 of a (Maker) Pi Pico talking to a generic SSD1306-driven screen and using the change contrast command to get something to capture (at 25MHz).This has the 10k pullups on SSD1306 and whatever the RP2040 might be doing. The Maker Pi Pico adds 3M3 to GND on each GPIO and a mosfet gate to drive LED but I don't see that making any difference here.
I took those 3 measurements and 3 others to get mean of 90.8827kHz. That's suspiciously close to 1000/11 = 90.9090.
Would be useful if someone could confirm i2c speed on Pi Pico and perhaps another established processor. These examples are from
6.2.0-beta.4
, not6.2.0-beta.1
.Same result with
frequency=100_000
. Oddly,frequency=110_000
gives actual 111.193kHz.And
frequency=400_000
gives actual 250.000 kHz, shown below:That also shows up some fat clock pulses. The first one is 6.88us, the second one 3.16us then it settles into the circa 2.9us rhythm.
For comparison I had a look back at an old trace from a Gemma M0 talking to a bear running CircuitPython 2.2.0 (this is only at 1MHz capture) and everything is much more regular.
The text was updated successfully, but these errors were encountered: