I2C Interface
1. I2C port pins
Within the 40-pin header, two I2C buses are available: i2c-3 and i2c-5.

I2C | PIN | Functions |
---|---|---|
I2C3-SCL | 5 | I2C3 的时钟信号线 |
I2C3-SDA | 3 | I2C3 的数据线 |
I2C5-SCL | 28 | I2C5 的时钟信号线 |
I2C5-SDA | 27 | I2C5 的数据线 |
2. Enable I2C Interface
You can enable I2C3 and I2C5 in the file arch/arm64/boot/dts/rockchip/rk3568-toybrick-x0-linux.dts (these two interfaces are already enabled by default).
&i2c3{
status = "okay";
};
&i2c5{
status = "okay";
};
3. Mount an I2C device
When registering an I2C device, the i2c_client structure is required to describe the I2C device. However, in standard Linux, users only need to provide the corresponding I2C device information, and Linux will construct the i2c_client structure based on the provided information.
The I2C device information provided by the user is written into the DTS file in the form of nodes, as shown below:
&i2c3{
nca9555:nca9555@20{
reg=<0x20>;
compatible = "novosense,nca9555";
status="okay";
gpio-controller;
#gpio-cells = <2>;
};
};
The driver mounts the device by obtaining the node information from the DTS.
Note
The NCA9555 is a 24-pin CMOS device that provides 16-bit general-purpose parallel I2C bus input/output (GPIO) expansion functionality.
4. Check the I2C device
Check whether the I2C bus is enabled through the following command
As shown in the figure:

5. I2C Test Tool
The board is equipped with I2C test commands, including i2cdetect, i2cdump, i2cset, and i2cget. These commands are used to scan devices on the I2C bus, read from and write to the registers of specified devices, etc.
For example, to check the status of the devices mounted on I2C5, the output is as follows:
# i2cdetect -y 5
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- 15 -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- UU -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
Tips
Among them, "15" indicates that there is a device with the address of 15, but its driver has not been loaded. "UU" indicates that the driver for the device with the address of 50 has been successfully loaded.
The usage examples of other commonly used commands are as follows:
#Detect how many groups of I2C buses there are in the current system.
i2cdetect -l
#Check the devices on the I2C-3 interface.
i2cdetect -a 3
#Read the values of all registers of the specified device.
i2cdump -f -y 3 0x20
#Read the value of a specific register of the specified I2C device. For example, read the value of register 0x01 in the device with the address 0x68 as follows.
i2cget -f -y 3 0x20 0x01
#Write a value to a specific register of the specified I2C device. For example, set the value of register 0x01 in the device with the address 0x68 to 0x6f as follows;
i2cset -f -y 3 0x20 0x01 0x6f b