I2C-Tools (4.0)
The I2C tools that used to be part of the lm-sensors package have been split to a separate package. The rationale for that move is that not all hardware monitoring chips are I2C devices, and not all I2C devices are hardware monitoring chips, so having everything in a single package was confusing and impractical.
The i2c-tools package contains a heterogeneous set of I2C tools for Linux: a bus probing tool, a chip dumper, register-level SMBus access helpers, EEPROM decoding scripts, EEPROM programming tools, and a python module for SMBus access. All versions of Linux are supported, as long as I2C support is included in the kernel.
I2C-Tools 4.0增加了i2ctransfer命令,可以对i2c设备指定定长度进行读写操作

下载地址

最新源码地址

https://i2c.wiki.kernel.org/index.php/I2C_Tools

android平台源码移植及说明下载地址

http://download.csdn.net/download/linuxarm521/10153440


执行文件
i2c-tools -4.0包含五个执行文件
i2cdetect – 显示所有的i2c适配器(控制器)及其使用的外设
i2cdump –读取外设所有register的值
i2cget – 读取外设某个register的值
i2cset – 向外设某个register写入值
i2ctransfer –读写i2c设备的数据 -4.0版本添加


帮助信息
i2ctransfer –help信息                                    
Usage: i2ctransfer [-f] [-y] [-v] [-V] I2CBUS DESC [DATA] [DESC [DATA]]...
  I2CBUS is an integer or an I2C bus name
  DESC describes the transfer in the form: {r|w}LENGTH[@address]
    1) read/write-flag  2) LENGTH (range 0-65535)  3) I2C address (use last one if omitted)
  DATA are LENGTH bytes for a write message. They can be shortened by a suffix:
    = (keep value constant until LENGTH)    //写入LENGTH个相同的数据
    + (increase value by 1 until LENGTH)     //写入LENTH个数据,数据递加
- (decrease value by 1 until LENGTH)    //写入LENTH个数据,数据递减
p (use pseudo random generator until LENGTH with value as seed)   //写入随机数


Example (bus 0, read 8 byte at offset 0x64 from EEPROM at 0x50):
  # i2ctransfer 0 [email protected]50 0x64 r8
Example (same EEPROM, at offset 0x42 write 0xff 0xfe ... 0xf0):
  # i2ctransfer 0 [email protected] 0x42 0xff-
eg:# i2ctransfer -f -y 1 [email protected] 0x55 r5
0x67 0x76 0x30 0x30 0x32


-f 强制执行,否则会提示Device or resource busy
-y 默认执行yes ,否则会提示确认执行Continue? [Y/n] Y


i2cdetect ,i2cdump ,i2cget ,i2cset不带参数执行时会显示对应的帮助信息,可参考。
例:列举i2c总线
i2cdetect -l
列举 I2C bus i2c-1 上面连接的所有i2c设备
i2cdetect -y 1
如:读取I2C 设备(地址为0x33)寄存器0x55的值,W表示读取长度为一个word,默认为一个字节
i2cget -y -f 1 0x33 0x55 w                          
0x7667
设置 I2C 设备(地址为0x33)寄存器0x03的值为0x05
# i2cset -y -f 1 0x33 0x03 0x05
dump I2C 读取外设(地址为0x33)的所有寄存器值
i2cdump -y -f 1 0x33


参考资料
http://blog.csdn.net/lqxandroid2012/article/details/48527887

更多相关文章

  1. android升级数据库(Sqlite)简单示例
  2. Android Room 数据库
  3. android 数据保存与提取
  4. android数据库操作
  5. sqlit导入外部数据库查找数据方法
  6. Android 和 PHP 之间进行数据加密传输
  7. Android使用SQLite数据库(1)
  8. Android 之 网络访问服务器,解析JSON数据

随机推荐

  1. Android的Spinner组件的XML属性(备查)
  2. Android(安卓)使用Preferences保存List
  3. Android简单实现更换桌面背景的方法
  4. Android双向seekbar
  5. 如何使用 Android(安卓)Studio 的 git hu
  6. Android(安卓)获取设备电池电量
  7. Android拨打电话 安卓拨打电话权限
  8. How to create a custom notification on
  9. android 输入对话框
  10. Android判断网络状态