raspberrypi / firmware

This repository contains pre-compiled binaries of the current Raspberry Pi kernel and modules, userspace libraries, and bootloader/GPU firmware.
5.18k stars 1.68k forks source link

I2C1 clock frequency is wrong #1281

Open AlanStern opened 5 years ago

AlanStern commented 5 years ago

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.

pelwell commented 5 years ago

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 commented 4 years ago

See https://github.com/raspberrypi/firmware/issues/1308.