首页 / LINUX / linux i2c-tools
linux i2c-tools
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了linux i2c-tools,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含5536字,纯文字阅读大概需要8分钟。
内容图文
![linux i2c-tools](/upload/InfoBanner/zyjiaocheng/952/4c978e4abe744bf585f12e700a889de5.jpg)
- 了解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:
- “–”. The address was probed but no chip answered.
- “UU”. Probing was skipped, because this address is currently in use by a driver. This strongly suggests that there is a chip at this address.
- An address number in hexadecimal, e.g. “2d” or “4e”. A chip was found at this address.
Options
-
-y
Disable interactive mode. By default, i2cdetect will wait for a confirmation from the user before messing with the I2C bus. When this flag is used, it will perform the operation directly. This is mainly meant to be used in scripts. -
-a
Force scanning of non-regular addresses. Not recommended. -
-q
Use SMBus “quick write” commands for probing (by default, the command used is the one believed to be the safest for each address). Not recommended. This is known to corrupt the Atmel AT24RF08 EEPROM found on many IBM Thinkpad laptops. -
-r
Use SMBus “read byte” commands for probing (by default, the command used is the one believed to be the safest for each address). Not recommended. This is known to lock SMBus on various write-only chips (most notably clock chips at address 0x69). -
-F
Display the list of functionalities implemented by the adapter and exit. -
-l
Output a list of installed busses.
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
-
-f
Force access to the device even if it is already busy. By default, i2cdump will refuse to access a device which is already under the control of a kernel driver. Using this flag is dangerous, it can seriously confuse the kernel driver in question. It can also cause i2cdump to return invalid results. So use at your own risk and only if you know what you’re doing. -
-r first-last
Limit the range of registers being accessed. This option is only available with modes b, w, c and W. For mode W, first must be even and last must be odd. -
-y
Disable interactive mode. By default, i2cdump will wait for a confirmation from the user before messing with the I2C bus. When this flag is used, it will perform the operation directly. This is mainly meant to be used in scripts.
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
- -f
Force access to the device even if it is already busy. By default, i2cset will refuse to access a device which is already under the control of a kernel driver. Using this flag is dangerous, it can seriously confuse the kernel driver in question. It can also cause i2cset to silently write to the wrong register. So use at your own risk and only if you know what you’re doing. - -y
Disable interactive mode. By default, i2cset will wait for a confirmation from the user before messing with the I2C bus. When this flag is used, it will perform the operation directly. This is mainly meant to be used in scripts. - -m mask
The mask parameter, if specified, describes which bits of value will be actually written to data-address. Bits set to 1 in the mask are taken from value, while bits set to 0 will be read from data-address and thus preserved by the operation. Please note that this parameter assumes that the read and write operations for the specified mode are symmetrical for the device you are accessing. This may or may not be the case, as neither I2C nor SMBus guarantees this. - -r
Read back the value right after writing it, and compare the result with the value written. This used to be the default behavior. The same limitations apply as those of option -m.
内容总结
以上是互联网集市为您收集整理的linux i2c-tools全部内容,希望文章能够帮你解决linux i2c-tools所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。