Page 1 of 1

i2c bus speed

Posted: Wed Oct 03, 2018 7:20 pm
by braincore
What is the i2c bus speed? 100kHz? 400kHz? 1MHz? Is there a way to configure the bus speed?

Re: i2c bus speed

Posted: Thu Oct 04, 2018 7:10 pm
by mpanetta
Which bus? They are set to different speeds.

The .dts files in the kernel source set the I2C bus speeds. Looking at android source file rk3399-nanopi4-common.dtsi we have:

&i2c0 {
status = "okay";
i2c-scl-rising-time-ns = <160>;
i2c-scl-falling-time-ns = <30>;
clock-frequency = <400000>;

&i2c1 {
status = "okay";
i2c-scl-rising-time-ns = <150>;
i2c-scl-falling-time-ns = <30>;
clock-frequency = <200000>;


&i2c2 {
status = "okay";
};

&i2c4 {
status = "okay";
i2c-scl-rising-time-ns = <160>;
i2c-scl-falling-time-ns = <30>;
clock-frequency = <400000>;



I think the ones that don't specify clock speed default to 100KHz.

Mike

Re: i2c bus speed

Posted: Sat Oct 06, 2018 6:46 pm
by braincore
Thanks for the info. Follow up: How do I set the i2c speed? The rk3399 datasheet suggests that the buses can operate at 1MHz. As an example, I'm able to change the Raspberry Pi i2c bus speed by modifying /boot/config.txt and setting a dtparam.

As a note for others, I also verified these speeds by checking the device-tree:

Code: Select all

/proc/device-tree/i2c*/clock-frequency


Note that the frequencies are binary packed, so I had to use the following script:

Code: Select all

import pathlib
import struct
for p in pathlib.Path('/proc/device-tree').glob('i2c*'):
    print(p.name, (p / 'status').open().read(), end=' ')
    freq_p = p / 'clock-frequency'
    if freq_p.exists():
        print('freq =', struct.unpack(">I", freq_p.open('rb').read()), end='')
    print()


The output matches @mpanetta's response:

Code: Select all

i2c@ff3c0000 okay freq = (400000,)
i2c@ff3d0000 okay freq = (400000,)
i2c@ff3e0000 disabled
i2c@ff110000 okay freq = (200000,)
i2c@ff120000 okay
i2c@ff130000 disabled
i2c@ff140000 disabled
i2c@ff150000 disabled
i2c@ff160000 okay

Re: i2c bus speed

Posted: Tue Oct 09, 2018 5:00 pm
by mpanetta
I'm not sure the NanoPC's OS versions support DT overlays yet. So you would have to modify the kernel dts files and then rebuild and load.

If it does support DT overlays I would love to know!

Mike