系统相关
首页 > 系统相关> > linux i2c-tools

linux i2c-tools

作者:互联网

1.Introduction

  i2c-tools工具是一个专门调试i2c的,开源,可获取挂载的设备及设备地址,还可以在对应的设备指定寄存器设置值或者获取值等功能。

1.1.下载i2c-tools,交叉编译

  从https://mirrors.edge.kernel.org/pub/software/utils/i2c-tools/下载i2c-tools,解压,修改Makefile,保存退出,直接make,进行编译。

CROSS_COMPILE :=xxx/arm-linux/gnueabihf-
CC := $(CROSS_COMPILE)gcc

  编译之后,在tools目录生成可执行文件i2cdetect, i2cdump, i2cget, i2cset,在lib目录生成libi2c.so.0.1.1,将这些文件push到android 设备。测试过程中发现执行 i2cdetect命令时,会出现报错,如下所示,解决方法参考如下即可。

[root@test]# ls -l
total 256
-rwxrwxr-x    1 1008     1008         23080 Jan  1 00:06 i2cdetect
-rwxrwxr-x    1 1008     1008         23384 Jan  1 00:06 i2cdump
-rwxrwxr-x    1 1008     1008         23132 Jan  1 00:06 i2cget
-rwxrwxr-x    1 1008     1008         23428 Jan  1 00:06 i2cset
-rwxrwxr-x    1 1008     1008         23024 Jan  1 00:06 i2ctransfer
-rwxrwxr-x    1 1008     1008          9224 Jan  1 00:06 libi2c.so.0.1.1

[root@test]# ./i2cdetect 
./i2cdetect: error while loading shared libraries: libi2c.so.0: cannot open shared object file: No such file or directory

解决方法:创建软连接
[root@ test]# ln -s libi2c.so.0.1.1 libi2c.so.0   

2.命令

2.1. i2cdetect

i2cdetect [-y] [-a] [-q|-r] i2cbus [first last]
i2cdetect -F i2cbus
i2cdetect -V
i2cdetect -l

  i2cdetect is a userspace program to scan an I2C bus for devices. It outputs a table with the list of detected devices on the specified bus. i2cbus indicates the number or name of the I2C bus to be scanned, and should correspond to one of the busses listed by i2cdetect -l. The optional parameters first and last restrict the scanning range (default: from 0x03 to 0x77).

  i2cdetect can also be used to query the functionalities of an I2C bus (see option -F.)

Interpreting the Output
  Each cell in the output table will contain one of the following symbols:

Options

2.2.i2cdump

i2cdump [-f] [-r first-last] [-y] i2cbus address [mode [bank [bankreg]]]
i2cdump -V

  i2cdump is a small helper program to examine registers visible through the I2C bus.

Options

2.3.i2cset - set I2C registers

i2cset [-f] [-y] [-m mask] [-r] i2cbus chip-address data-address [value] … [mode]
i2cset -V

  i2cset is a small helper program to set registers visible through the I2C bus.

Options

标签:linux,I2C,address,will,used,i2cdetect,1008,i2c,tools
来源: https://blog.csdn.net/weixin_41028621/article/details/101196447