Skip to content
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

I2C1 clock frequency is wrong #1281

Open
AlanStern opened this issue Nov 1, 2019 · 2 comments
Open

I2C1 clock frequency is wrong #1281

AlanStern opened this issue Nov 1, 2019 · 2 comments

Comments

@AlanStern
Copy link

The clock frequency for I2C1 (that is, the I2C controller for physical GPIO pins 3 and 5) is wrong; it is too low by a factor of 5/8.

The default setting is supposed to be 100 KHz but the actual clock frequency, measured on an oscilloscope, is 62.5 KHz. Since I wanted to use Fast Mode I2C at 400 KHz, I added the following line to config.txt:

dtparam=i2c_arm=on,i2c_arm_baudrate=400000

but then the measured frequency was 250 KHz, Changing the baudrate value in the config line to 640000 causes the I2C clock to run at the desired speed.

Tests were made using the 2019-07-10-raspbian-buster system image.

  • Which model of Raspberry Pi? e.g. Pi3B+, PiZeroW
    Raspberry Pi 3 Model B V1.2

  • Which OS and version (cat /etc/rpi-issue)?
    Raspberry Pi reference 2019-07-10
    Generated using pi-gen, https://github.com/RPi-Distro/pi-gen, 175dfb027ffabd4b8d5080097af0e51ed9a4a56c, stage4

  • Which firmware version (vcgencmd version)?
    Jul 9 2019 14:40:53
    Copyright (c) 2012 Broadcom
    version 6c3fe3f096a93de3b34252ad98cdccadeb534be2 (clean) (release) (start)

  • Which kernel version (uname -a)?
    Linux honeypitest 4.19.57-v7+ Pi 4B (4GB) cannot set gpu_mem above 512. #1244 SMP Thu Jul 4 18:45:25 BST 2019 armv7l GNU/Linux

@pelwell
Copy link
Contributor

pelwell commented Nov 5, 2019

This is caused by the fact that the source clock that drives the I2C interfaces is the same as the VPU "core" clock. The core clock normally switches between 250MHz at idle and 400MHz under load. The I2C clock divider has to be calculated for the maximum clock speed so the bus clock never exceeds the requested value, hence the 62.5% ratio.

If you require a constant and accurate I2C clock, set core_freq and core_freq_min to the same value. I suggest you add the following to config.txt:

core_freq=250
core_freq_min=250

@pelwell
Copy link
Contributor

pelwell commented Jan 10, 2020

See #1308.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants