Khadas Docs

Amazing Khadas, always amazes you!

User Tools

Site Tools


Sidebar

products:sbc:common:applications:gpio:i2c

This is an old revision of the document!


I2C

Introduction

This document mainly introduces how to use I2C bus on Khadas SBC. You will learn how to connect I2C devices, check I2C devices, and read device register values.

Hardware Connection

VIM1/2

I2C A
Sensor SCLI2C_SCK_A (PIN 22)
Sensor SDAI2C_SDA_A (PIN 23)
Sensor GNDGND
Sensor VCC5V or 3.3V //depends on your sensor
I2C B
Sensor SCLI2C_SCK_B (PIN 25)
Sensor SDAI2C_SDA_B (PIN 26)
Sensor GNDGND
Sensor VCC5V or 3.3V //depends on your sensor

VIM3/3L

I2C 3
Sensor SCLI2C0_SCK (PIN 22)
Sensor SDAI2C0_SDA (PIN 23)
Sensor GNDGND
Sensor VCC5V or 3.3V //depends on your sensor
I2C 4
Sensor SCLI2C1_SCK (PIN 25)
Sensor SDAI2C1_SDA (PIN 26)
Sensor GNDGND
Sensor VCC5V or 3.3V //depends on your sensor

VIM4

I2CM A
Sensor SCLI2CM_A_SCL (PIN 25)
Sensor SDAI2CM_A_SDA (PIN 26)
Sensor GNDGND
Sensor VCC5V or 3.3V //depends on your sensor
I2CM F
Sensor SCLI2CM_F_SCL (PIN 22)
Sensor SDAI2CM_F_SDA (PIN 23)
Sensor GNDGND
Sensor VCC5V or 3.3V //depends on your sensor

I2C PIN & GPIO Number DT Overlays Node Bus Number Device Node
I2CM A SCL - PIN25 - GPIOT_20 (#466)
SDA - PIN26 - GPIOT_21 (#467)
i2cm_a 0 /dev/i2c-0
I2CM F SCL - PIN22 - GPIOY_17 (#501)
SDA - PIN23 - GPIOY_18 (#502)
i2cm_f 5 /dev/i2c-5

Enabel I2C

In order to use the I2C, you need to enable the I2C function via Device Tree Overlay.

VIM1/2/3/3L/Edge1

Edit /boot/env.txt to add the i2c node to overlays node.

Take VIM3 as an example to enable i2c3:

overlays=uart4 pwm_ao_a pwm_f i2c3

After reboot, you will see the I2C device node.

khadas@Khadas:~$ ls /dev/i2c-3
/dev/i2c-3

VIM4

Edit /boot/dtb/amlogic/kvim4.dtb.overlay.env to add i2c node to fdt_overlays node.

e.g. Enable I2CM A, you need to add i2cm_a to node fdt_overlays.

fdt_overlays=i2cm_a

After reboot, you will see the I2C device node.

khadas@Khadas:~$ ls /dev/i2c-0
/dev/i2c-0

Disable I2C to Use GPIO

If you want to use normal GPIO instead of I2C, you can remove the I2C node in device tree overlays configration file.

Last modified: 2022/07/12 04:27 by nick