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 on Khadas SBC. You will learn how to connect I2C devices, view 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

I2C A
Sensor SCLI2CA_SCK (PIN 25)
Sensor SDAI2CA_SDA (PIN 26)
Sensor GNDGND
Sensor VCC5V or 3.3V //depends on your sensor
I2C F
Sensor SCLI2CF_SCK (PIN 22)
Sensor SDAI2CF_SDA (PIN 23)
Sensor GNDGND
Sensor VCC5V or 3.3V //depends on your sensor

Device Detection

VIM1/2

Detect device on I2C A:

$ sudo i2cdetect -y -r 1
    0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- 1d -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

Detect device on I2C B:

$ sudo i2cdetect -y -r 2
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- 51 -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

VIM3/3L

Detect device on I2C 3:

$ sudo i2cdetect -y -r 3
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

Detect device on I2C 4:

$ sudo i2cdetect -y -r 4
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- 0e --
10: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- --
20: UU -- 22 -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- UU -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

VIM4

Detect device on I2C A:

$ sudo i2cdetect -r -y 0
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: UU -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

Detect device on I2C F:

$ sudo i2cdetect -r -y 5
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- UU -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

If you have made a connection, you will see the device address, e.g: 0x1d,0x18 and 0x51.

Read Registers from Device

Read register 0x0d of device 0x1d on I2C A.

$ sudo i2cget -f -y 1 0x1d 0x0d
0x2a

For more information, please refer to the help messages.

Last modified: 2022/07/08 02:38 by hyphop