参考自:https://www.jianshu.com/p/1295881fd501
https://blog.youkuaiyun.com/kai_zone/article/details/80491706
一、前言
在进行I2C相关程序开发时,很多时候我们需要确认硬件是否正常连接,设备是否正常工作,设备的地址是多少等等,这里我们就需要使用一个用于测试I2C总线的工具——i2c tools。i2c-tools工具是一个专门调试i2c的,开源,可获取挂载的设备及设备地址,还可以在对应的设备指定寄存器设置值或者获取值等功能,下面我们就对这个工具的安装和使用做个简单介绍。
二、下载i2c-tools,交叉编译
1、从开源网站http://dl.lm-sensors.org/i2c-tools/releases/ 下载i2c-tools;
2、编译生成对应的可执行文件 i2cdetect, i2cdump, i2cget, i2cset
a. 解压后:
b. 修改makefile文件:
c. 然后保存退出。直接make,进行编译。编译完成后在tools/文件夹下会有如下几个可执行文件,i2cdetect, i2cdump, i2cget, i2cset。如下图所示:
将i2cdetect, i2cdump, i2cget, i2cset push到安卓设备就可以调试了。
三、使用举例
1、用i2cdetect检测有几组i2c总线在系统上,输入:
:/ # i2cdetect
Error: No i2c-bus specified!
Usage: i2cdetect [-y] [-a] [-q|-r] I2CBUS [FIRST LAST]
i2cdetect -F I2CBUS
i2cdetect -l
I2CBUS is an integer or an I2C bus name
If provided, FIRST and LAST limit the probing range.
:/ # i2cdetect -l
i2c-1 i2c aml_i2c_adap1 I2C adapter
i2c-2 i2c aml_i2c_adap2 I2C adapter
i2c-3 i2c aml_i2c_adap3 I2C adapter
2、用i2cdetect检测挂载在i2c总线上器件,以总线3为例,输入:
:/ # i2cdetect -r -y 3
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- UU -- --
20: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- 43 -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- --