首页 > 技术知识 > 正文

【海思开源篇】-(3)i2c-tools

1 源码下载

https://mirrors.edge.kernel.org/pub/software/utils/i2c-tools/

下载版本为i2c-tools-4.1.tar.gz

根文件系统中已经通过busybox生成了i2c-tools,赞!!!

2 编译

make clean;make CC=arm-himix400-linux-gcc

拷贝i2cdetect i2cdump i2cget i2cset i2ctransfer

3 工具使用

3.1 i2cdetect

~ # i2cdetect -l

i2c-1 i2c hibvt-i2c I2C adapter

i2c-0 i2c hibvt-i2c I2C adapter

/home # i2cdetect

BusyBox v1.30.1 (2020-05-28 08:57:22 CST) multi-call binary.

Usage: i2cdetect -l | -F I2CBUS | [-ya] [-q|-r] I2CBUS [FIRST LAST]

Detect I2C chips

-l List installed buses

-F BUS# List functionalities on this bus

-y Disable interactive mode

-a Force scanning of non-regular addresses

-q Use smbus quick write commands for probing (default)

-r Use smbus read byte commands for probing

FIRST and LAST limit probing range

~ # i2cdetect -r -y 0

0 1 2 3 4 5 6 7 8 9 a b c d e f

00: — — — — — — — — — — — — —

10: — — — — — — — — — — — — — — — —

20: — — — — — — — — — — — — — — — —

30: 30 31 — — — — — — — — — — — — — —

40: — — — — — — — — — — — — — — — —

50: — — — — — — — — — — — — — — — —

60: — — — — — — — — — — — — — — — —

70: — — — — — — — —

i2c0上挂载两颗,由此推出i2c 地址分别为0x60,0x62(左移一位)

/home # i2cdetect -r -y 1

0 1 2 3 4 5 6 7 8 9 a b c d e f

00: — — — — — — — — — — — — —

10: — — — — — — — — — — — — — — — —

20: — — — — — — — — — — — — — — — —

30: — — — — — — — — — — — — — — — —

40: — — — — — — — — — — — — — — — —

50: — — — — — — — — — — — — — — — —

60: — — — — — — — — 68 — — — — — — —

70: — — — — — — — —

从而可知i2c1上挂载有三个设备0x68
<

3.2 i2cdump

/home # i2cdump

BusyBox v1.30.1 (2020-05-28 08:57:22 CST) multi-call binary.

Usage: i2cdump [-fy] [-r FIRST-LAST] BUS ADDR [MODE]

Examine I2C registers

I2CBUS I2C bus number

ADDRESS 0x03-0x77

MODE is:

b Byte (default)

w Word

W Word on even register addresses

i I2C block

s SMBus block

c Consecutive byte

Append p for SMBus PEC

-f Force access

-y Disable interactive mode

-r Limit the number of registers being accessed

/home # i2cdump -f -y 1 0x68

0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef

00: d1 21 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ?!…………..

10: 00 00 00 00 00 00 00 00 5f f8 dc 10 00 00 00 00 …….._???….

20: 00 80 00 00 80 00 00 00 00 00 00 00 00 00 00 00 .?..?………..

30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 …………….

40: 28 03 28 00 0b 88 80 10 00 00 00 20 80 42 4c 00 (?(.????… ?BL.

50: 00 00 00 00 00 00 00 00 00 00 07 30 81 0b c0 00 ……….?0???.

60: 14 14 24 04 0a 18 48 08 11 00 00 00 00 00 00 00 ??$???H??…….

70: 00 00 00 00 4c a1 14 00 00 00 15 03 00 00 00 00 ….L??…??….

80: d1 21 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ?!…………..

90: 00 00 00 00 00 00 00 00 8d 02 dd 10 00 00 00 00 ……..????….

a0: 00 80 00 00 80 00 00 00 00 00 00 00 00 00 00 00 .?..?………..

b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 …………….

c0: 28 03 28 00 0b 88 80 10 00 00 00 20 80 42 4c 00 (?(.????… ?BL.

d0: 00 00 00 00 00 00 00 00 00 00 07 30 81 0b c0 00 ……….?0???.

e0: 14 14 24 04 0a 18 48 08 11 00 00 00 00 00 00 00 ??$???H??…….

f0: 00 00 00 00 4c a1 14 00 00 00 15 03 00 00 00 00 ….L??…??….

3.3 i2cset

/home # i2cset

BusyBox v1.30.1 (2020-05-28 08:57:22 CST) multi-call binary.

Usage: i2cset [-fy] [-m MASK] BUS CHIP-ADDRESS DATA-ADDRESS [VALUE] … [MODE]

Set I2C registers

I2CBUS I2C bus number

ADDRESS 0x03-0x77

MODE is:

c Byte, no value

b Byte data (default)

w Word data

i I2C block data

s SMBus block data

Append p for SMBus PEC

-f Force access

-y Disable interactive mode

-r Read back and compare the result

-m MASK Mask specifying which bits to write

/home # i2cset -f -y 1 0x68 0x7a 0x15

3.4 i2cget

/home # i2cget

BusyBox v1.30.1 (2020-05-28 08:57:22 CST) multi-call binary.

Usage: i2cget [-fy] BUS CHIP-ADDRESS [DATA-ADDRESS [MODE]]

Read from I2C/SMBus chip registers

I2CBUS I2C bus number

ADDRESS 0x03-0x77

MODE is:

b Read byte data (default)

w Read word data

c Write byte/read byte

Append p for SMBus PEC

-f Force access

-y Disable interactive mo

/home # i2cget -f -y 1 0x68 0xfa

0x15

猜你喜欢