Setting the Bitrate of I2C2 on the Beaglebone Black

I’m been working a project with my BBB that requires use of I2C. I’ve successfully communicated with devices on the I2C2 bus (Pins 19/20), but the default clock rate of 100kHz is too slow for my application. I set my devices to function at 400kHz but I still need to configure the BBB to run I2C2 at 400kHz. I have tried to use the following device tree overlay but it has no effect on the bit rate:

`
/dts-v1/;
/plugin/;

/ {
compatible = “ti,beaglebone”, “ti,beaglebone-black”;

/* identification */
part-number = “BB-I2C2”;
version = “00A0”;

/* state the resources this cape uses /
exclusive-use =
/
the pin header uses /
“P9.20”, /
i2c2_sda /
“P9.19”, /
i2c2_scl /
/
the hardware ip uses */
“i2c2”;

fragment@0 {
target = <&am33xx_pinmux>;
overlay {
bb_i2c2_pins: pinmux_bb_i2c2_pins {
pinctrl-single,pins = <
0x178 0x73 // spi0_d1.i2c2_sda, SLEWCTRL_SLOW | // INPUT_PULLUP | MODE3
0x17c 0x73 // spi0_cs0.i2c2_scl, SLEWCTRL_SLOW | // INPUT_PULLUP | MODE3

;
};
};
};

fragment@1 {
target = <&i2c2>; /* i2c2 is numbered correctly */
overlay {
status = “okay”;
pinctrl-names = “default”;
pinctrl-0 = <&bb_i2c2_pins>;

/* this is the configuration part */
clock-frequency = <400000>;

#address-cells = <1>;
#size-cells = <0>;
};
};
};

`

I’ve used a similar Device Tree Overlay to start the normally disabled I2C1 bus, but in both instances I cannot set the bitrate. Is there something wrong with my device tree overlay or is there a better way to set the I2C2 bitrate?

Had the same problem. It seems that I2C frecuency has to be set at boot time and cannot changed after so I had to change am335x-boneblack.dts or the .dtsi I cannot remember in order to start with a 400Khz clock at boot time.

Thanks Juanjo, I edited the clock speed on the am335x-bone-common.dtsi and it work perfectly.

hi,
can i know where I can find the am335x-bone-common.dtsi?
it is not present in /lib/firmware so where can i find out???

If you have the kernel source it is located at arch/arm/boot/dts/am335x-bone-common.dtsi
Then you will need to recompile the am335x-boneblack.dtb

You don’t need the kernel source. You can convert the compiled device tree blob to the text version, edit it, and the convert it back to the binary using dtc:

backup the original .dtb

cp /boot/am335x-boneblack.dtb /boot/am335x-boneblack.dtb.orig

generate the dts from the dtb

dtc -I dtb -O dts -o am335x-boneblack.dts /boot/am335x-boneblack.dtb

modify the dts with a text editor

generate the dtb from the modified dts

dtc -I dts -O dtb -o am335x-boneblack.dtb am335x-boneblack.dts

hey thank you so much…
also can I know whats the maximum frequency that a beaglebone black supports to connect an LCD??

Hi all. Can you guys help me.I am using beaglebone black i2c2 pin 19 and 20 of p9. Somewhere in the net it was told i2c2 has told accessed with i2c-1 in /dev folder. I am booting default amstrom linux from emmc. Hardware is completely checked and verified. I have connected 3 io expansion modules to i2c bus. I can communicate to them by i2ctest commands from command line. But the problem is with the file writes. I cant write to /dev/i2c-1 file with "write" function. The file descriptor doeant have an error. Also the ioctl calls doest make any errors. But the write function is having problem. And thus I cant access i2c bus in application layer.

I think this can only mean that a device isn’t responding to the address you’re providing. Did you set the i2c device address to the same value used with i2ctest?

I am using i2cset just fine on my BBB of P9 19 and 20, it is currently Bus1.
My notes:

i2c detect on Bus1, see my address at 4C and 4D:

i2cdetect -r -y 1

0 1 2 3 4 5 6 7 8 9 a b c d e f

00: – -- – -- – -- – -- – -- – -- –

10: – -- – -- – -- – -- UU – -- – -- – -- –

20: – -- – -- – -- – -- – -- – -- – -- – --

30: – -- – -- – -- – -- – -- – -- – -- – --

40: – -- – -- – -- – -- – -- – -- 4c 4d – --

50: – -- – -- UU UU UU UU – -- – -- – -- – --

60: – -- – -- – -- – -- – -- – -- – -- – --

Dump the 4C device registers, register 0x14 is 0x00:

i2cdump -y 1 0x4c

No size specified (using byte-data access)

0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef

00: 00 00 00 00 11 31 00 00 20 00 00 01 7c 10 00 00 …?1… …?|?..

10: 00 00 00 10 00 10 00 00 01 00 80 01 0f 03 07 04 …?.?..?.???

20: 00 00 00 04 00 08 f3 04 13 00 11 1f 00 00 00 00 …?.???.??..

30: 00 00 00 00 00 00 00 00 00 00 00 00 00 30 30 22 …00"

40: 02 04 14 05 00 00 00 00 55 00 00 00 00 00 00 00 ???..U…

50: 00 00 00 00 00 07 00 00 81 00 00 00 00 40 78 15 …?..?..@x?

60: 01 10 00 00 00 01 0f 03 07 11 00 00 00 00 06 03 ??..???..??

70: 02 83 03 00 04 00 80 01 00 00 00 00 00 00 00 00 ???.?.??..

80: 00 00 00 00 11 31 00 00 20 00 00 01 7c 10 00 00 …?1… …?|?..

90: 00 00 00 10 00 10 00 00 01 00 80 01 0f 03 07 04 …?.?..?.???

a0: 00 00 00 04 00 08 f3 04 13 00 11 1f 00 00 00 00 …?.???.??..

b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 30 30 22 …00"

c0: 02 04 14 05 00 00 00 00 55 00 00 00 00 00 00 00 ???..U…

d0: 00 00 00 00 00 07 00 00 81 00 00 00 00 40 78 15 …?..?..@x?

e0: 01 10 00 00 00 01 0f 03 07 11 00 00 00 00 06 03 ??..???..??

f0: 02 83 03 00 04 00 80 01 00 00 00 00 00 00 00 00 ???.?.??..

Write 0x01 to register 0x14:

i2cset -y 1 0x4c 0x14 0x01

Dump the registers and not the change to 0x01:

i2cdump -y 1 0x4c

No size specified (using byte-data access)

0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef

00: 00 00 00 00 11 31 00 00 20 00 00 01 7c 10 00 00 …?1… …?|?..

10: 00 00 00 10 01 10 00 00 01 00 80 01 0f 03 07 04 …???..?.???

20: 00 00 00 04 00 08 f3 04 13 00 11 1f 00 00 00 00 …?.???.??..

30: 00 00 00 00 00 00 00 00 00 00 00 00 00 30 30 22 …00"

40: 02 04 14 05 00 00 00 00 55 00 00 00 00 00 00 00 ???..U…

50: 00 00 00 00 00 07 00 00 81 00 00 00 00 40 78 15 …?..?..@x?

60: 01 10 00 00 00 01 0f 03 07 11 00 00 00 00 06 03 ??..???..??

70: 02 83 03 00 04 00 80 01 00 00 00 00 00 00 00 00 ???.?.??..

80: 00 00 00 00 11 31 00 00 20 00 00 01 7c 10 00 00 …?1… …?|?..

90: 00 00 00 10 01 10 00 00 01 00 80 01 0f 03 07 04 …???..?.???

a0: 00 00 00 04 00 08 f3 04 13 00 11 1f 00 00 00 00 …?.???.??..

b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 30 30 22 …00"

c0: 02 04 14 05 00 00 00 00 55 00 00 00 00 00 00 00 ???..U…

d0: 00 00 00 00 00 07 00 00 81 00 00 00 00 40 78 15 …?..?..@x?

e0: 01 10 00 00 00 01 0f 03 07 11 00 00 00 00 06 03 ??..???..??

f0: 02 83 03 00 04 00 80 01 00 00 00 00 00 00 00 00 ???.?.??..