Skip to content

I2C

Rockchip I2C controllers are compatible with both I2C and SMBus protocols. The I2C information for expansion pins is as follows:

Board SoC Platform Expansion Pins
K1 RK3568 Rockchip I2C X2
K1B RK3568 Rockchip I2C X1
K3 RK3562 Rockchip I2C X1
K7 RK3576 Rockchip I2C X3
K7C RK3576 Rockchip I2C X2
K8 RK3588 Rockchip I2C X2

Allwinner's TWI bus is compatible with the I2C bus protocol. The I2C information for expansion pins is as follows:

Board SoC Platform Expansion Pins
K2B H618 Allwinner I2C X3
K2C H618 Allwinner I2C X2
K4B T113 Allwinner I2C X3
K5C A133 Allwinner I2C X1

Terminology

Term Description
I2C Inter-Integrated Circuit
TWI Two-Wire Interface

Hardware Connection

The diagram below illustrates the hardware connection for the I2C bus, which requires pull-up resistors. Changing the value of the pull-up resistors adjusts the pull-up strength of the I2C bus.

image-20251112134828034

DTS Node Configuration

Rockchip

The following is an example DTS node configuration for the hym8563 device on the Rockchip platform's i2c bus:

&i2c2 {
    status = "okay";

    hym8563: hym8563@51 {
        compatible = "haoyu,hym8563";
        reg = <0x51>;
        pinctrl-names = "default";
        pinctrl-0 = <&hym8563_int>;
        interrupt-parent = <&gpio0>;
        interrupts = <RK_PA0 IRQ_TYPE_LEVEL_LOW>;
        wakeup-source;
    };
};

Allwinner

The following is an example DTS node configuration for the hym8563 device on the Allwinner platform's twi0 bus:

&twi0{
    clock-frequency = <400000>;
    pinctrl-0 = <&twi0_pins_a>;
    pinctrl-1 = <&twi0_pins_b>;
    status = "okay";

    hym8563@51 {
        compatible = "haoyu,hym8563";
        reg = <0x51>;
        interrupt-parent = <&pio>;
        interrupts = <PB 8 IRQ_TYPE_LEVEL_LOW>;
        status = "okay";
    };
};

I2C tools

I2C tools is an open-source utility that needs to be downloaded and cross-compiled separately. Download link:

git clone git://git.kernel.org/pub/scm/utils/i2c-tools/i2c-tools.git

After compilation, tools like i2cdetect, i2cdump, i2cset, and i2cget will be generated, which can be used directly from the command line for debugging.

Note

i2cdetect – Used to list I2C buses and all devices on them.
i2cdump – Displays the values of all registers of an I2C device.
i2cget – Reads the value of a specific register of an I2C device.
i2cset – Writes a value to a specific register of an I2C device.
I2C tools are open-source. Please refer to the included README and help documentation for compilation and usage instructions.

Example

Using the K1B expansion I2C pins to connect an I2C device (RTC hym8563 module) as an example; other boards are similar.

1. Identify the I2C pin positions on the expansion header and the power domain of the module. The RTC hym8563 uses 3.3V.

image-20251112142527332

2. Check if the module's SDA and SCL lines have built-in pull-up resistors. If not, external pull-up resistors need to be added.

3. Connect the module and use i2cdetect to check if the device is successfully detected and recognized.

Warning

Do not install or remove modules while the motherboard is powered on!

image-20251112142713347