1

I am setting the I2C frequency on the Compute Module 4 (running Ubuntu 22.04.2 LTS) with dtparam=i2c_arm=on,i2c_arm_baudrate=400000. The I2C bus has two parallel 10kOhm pullup (to 3.3V) resistors per line.

I've noticed that regardless of the speed I set it at, the actual measured clock frequency is significantly slower, roughly 33% slower. I've attached some screenshots from the oscilloscope used, and will list some of the measurements I found below:

Setting (kHz) | Measured (kHz)

10 | 4.66

50 | 26.7

100 | 66.8

200 | 134

300 | 200

400 | 292

I'm not sure why there is this large discrepancy, any ideas on what might be causing (or fix) this would be great! Not sure whether this is an issue in software, hardware, or something else.

I've heard of clock stretching being used by peripheral devices at high I2C speeds, but as I see this still happening at slower speeds (10kHz to 100kHz), I don't believe that's the cause of the discrepancy.

Screenshots below are in the same order as listed above. Measurements were taken by reading the difference in time (delta x) between the two cursors shown as vertical purple dotted lines. The measured delta x and equivalent frequency is shown in the grey box on the middle right (the oscilloscope traces are there but very faint, trace period is shown top left next to the M).

10kHz 50kHz 100kHz 200kHz 300kHz 400kHz

Below is a screenshot of multiple bytes being sent at 400kHz frequency setting. The cursors measure the period of 8 bits, which roughly corresponds with 33% slower (33.56kHz * 8 = 268kHz).

400 kHz multiple bytes

2
  • Did you reboot after changing config.txt?
    – Seamus
    Aug 2 at 21:54
  • @Seamus Yep have rebooted. You can see that the frequency does change with different settings, they're all just consistently slower than what they're supposed to be set at.
    – Eric
    Aug 2 at 22:01

1 Answer 1

1

Found a thread that was experiencing a similar issue, I tried the solution of changing the core frequency scaling governor to performance (as opposed to the default ondemand) using echo performance | sudo tee /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor and the baud rate of the I2C line now matches the setting. So seems like the variable core frequency was causing the discrepancy here.

For anyone's interest, I personally found that the I2C speed appears to scale directly with the CPU frequency, so if the frequency is 1.5/1.5MHz, I2C will run at full speed (400kHz at 400kHz setting), whereas if the CPU frequency is 1.0/1.5Mhz, the I2C will run at 66.7% of its set speed (266.7kHz at 400kHz setting).

i2c baudrate falling back to 160 kHz

I2C baudrate in Raspberry Pi, depends on arm core frequency

1
  • 1
    I don't know for certain, but I suspect you've discovered the reason. That said, the RPi documentation leaves something to be desired.
    – Seamus
    Aug 3 at 22:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.