工具篇: i2c 调试工具 i2c-tools

Posted 旧年不在cd

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了工具篇: i2c 调试工具 i2c-tools相关的知识,希望对你有一定的参考价值。

一、安装

sudo apt-get -y install i2c-tools

安装完会得到以下几个工具:

  • i2cdetect
  • i2cdump
  • i2cget
  • i2cset
  • i2c-stub-from-dump
  • i2ctransfer

二、用法

1、i2cdetect:用来列举i2c bus和上面的所有设备
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.
  • 示例
droid@droid:~$ sudo i2cdetect -y 0
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- UU -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: UU UU -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- UU -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --

说明:UU说明该地址已经被设备占用
2、i2cdump:用于检查通过i2c bus可见的寄存器
Usage: i2cdump [-f] [-y] [-r first-last] [-a] I2CBUS ADDRESS [MODE [BANK [BANKREG]]]
  I2CBUS is an integer or an I2C bus name
  ADDRESS is an integer (0x03 - 0x77, or 0x00 - 0x7f if -a is given)
  MODE is one of:
    b (byte, default)
    w (word)
    W (word on even register addresses)
    s (SMBus block)
    i (I2C block)
    c (consecutive byte)
    Append p for SMBus PEC
  • 示例
droid@droid:~$ sudo i2cdump -f -y 0 0x1b b
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f    0123456789abcdef
00: 02 50 08 21 01 13 01 00 00 00 00 01 01 00 00 00    ?P?!???....??...
10: 80 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ??..............
20: 00 5f 00 6f ff 00 00 00 10 00 ff 0f ff 02 19 0f    ._.o....?..?.???
30: 00 00 19 07 00 00 02 03 00 00 09 00 00 0c 00 0a    ..??..??..?..?.?
40: 00 0c 00 0c 00 07 00 0a 00 0c 00 00 00 5f 00 03    .?.?.?.?.?..._.?
50: 06 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ??..............
60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
70: 00 cf 03 00 28 00 0c 1c 80 19 00 34 12 00 71 00    .??.(.????.4?.q.
80: 10 50 1f ac 00 40 10 01 00 00 00 08 00 09 00 00    ?P??.@??...?.?..
90: ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
a0: 00 00 00 00 00 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: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
3、i2cget:读取i2c设备上某个寄存器的值
Usage: i2cget [-f] [-y] [-a] I2CBUS CHIP-ADDRESS [DATA-ADDRESS [MODE]]
  I2CBUS is an integer or an I2C bus name
  ADDRESS is an integer (0x03 - 0x77, or 0x00 - 0x7f if -a is given)
  MODE is one of:
    b (read byte data, default)
    w (read word data)
    c (write byte/read byte)
    Append p for SMBus PEC
  • 示例
droid@droid:~$ sudo i2cget -f -y 0 0x1b 0x0e b
0x00
4、i2cset:设置i2c设备上某个寄存器的值
Usage: i2cset [-f] [-y] [-m MASK] [-r] [-a] I2CBUS CHIP-ADDRESS DATA-ADDRESS [VALUE] ... [MODE]
  I2CBUS is an integer or an I2C bus name
  ADDRESS is an integer (0x03 - 0x77, or 0x00 - 0x7f if -a is given)
  MODE is one of:
    c (byte, no value)
    b (byte data, default)
    w (word data)
    i (I2C block data)
    s (SMBus block data)
    Append p for SMBus PEC
  • 示例
droid@droid:~$ sudo i2cset -f -y -r 0 0x1b 0x08 0x7f
Value 0x7f written, readback matched

以上是关于工具篇: i2c 调试工具 i2c-tools的主要内容,如果未能解决你的问题,请参考以下文章

i2c-tools测试工具

Linux系统下i2c工具 i2c-tool 的使用以及源码操作i2c设备

Linux i2ctool 工具的使用方法

Linux i2ctool 工具的使用方法

Android i2c-tools移植

i2c-tools移植