Configure and Debug I2C

Hardware Setup

Connect Sense HAT (B) to the 40-pin header illustrated in the following diagram.

Figure 1. Connect Sense Hat (B) to the 40-Pin GPIO Header
Sense HAT (B) 40-Pin GPIO Header
Pin Number Pin Name
3V3 1 3.3V Power
GND 9 GND
SDA 3 GPIO58 (I2C SDA)
SCL 5 GPIO57 (I2C SCL)

Configure DTS File

Configure the jh7110-visionfive-v2.dtsi file that is under /linux/arch/riscv/boot/dts/starfive.

The i2c0 to i2c6 channels are for the I2C bus. You can configure the unoccupied GPIOs as desired. The following is the default setting.

Figure 2. I2C Pins

Debug I2C GPIO

To debug I2C:
  1. Execute the following command to scan the bus:
    i2cdetect -l
    Figure 3. Example Output
  2. Execute the following command to detect the device:
    i2cdetect -y -r 0
    where, 0 is the I2C bus number.
    Figure 4. Example Output
  3. Execute the following command to read the register content:
    i2cget -f -y 0 0x5c 0x0f
    where,
    • 0 is the I2C bus number.

    • 0x5C is the I2C device address.

    • 0x0f is the memory address.

  4. Execute the following command to write register data:
    i2cset -y 0 0x5c 0x11 0x10
    where,
    • 0 is the I2C bus number.

    • 0x5C is the I2C device address.

    • 0x11 is the memory address.

    • 0x10 is the content to be written to the register.

  5. Execute the following command to read all register values:
    i2cdump -y 0 0x5c
    where,
    • 0 is the I2C bus number.

    • 0x5C is the I2C device address.