i2c-tools工具用法

i2cdetect

扫描I2C总线,查找总线上的设备。
输出指定总线上检测到的设备列表。
i2cbus表示i2c总线编号或名称,与i2cdetect -l列出的总线之一相对应。
可选参数first last限制扫描范围(默认0x08~0x77)。

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

$ i2cdetect -l  # 所有注册的的i2c总线
i2c-1   i2c             PSENSOR                            I2C adapter
i2c-2   i2c             LSENSOR                            I2C adapter

$ i2cdetect 0     # i2c-0 上i2c设备地址,需确认
$ i2cdetect -y 1  # i2c-1 上i2c设备地址,-y 无需确认
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- 37 -- -- -- -- -- -- -- --
40: -- -- -- 43 -- -- -- -- -- -- -- -- -- -- -- --
50: 50 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

$ i2cdetect -V    # 查看i2c tools版本
i2cdetect version 4.1

$ i2cdetect -F 1  # 查看i2c-1的功能
Functionalities implemented by /dev/i2c-1:
I2C                              yes
SMBus Quick Command              yes
SMBus Send Byte                  yes
SMBus Receive Byte               yes
SMBus Write Byte                 yes
SMBus Read Byte                  yes
SMBus Write Word                 yes
SMBus Read Word                  yes
SMBus Process Call               yes
SMBus Block Write                yes
SMBus Block Read                 yes
SMBus Block Process Call         yes
SMBus PEC                        yes
I2C Block Write                  yes
I2C Block Read                   yes

i2cdump

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

i2cbus: i2c number
address: slave addr
-r first-last:从first到last,默认访问全部寄存器
-f: 强制访问,即使busy状态(危险)
-a: 允许使用 0x00 - 0x07 和 0x78 - 0x7f 之间的地址。不建议。
$ i2cdump -y 1 0x50                # 获取 i2c-1 上 addr=0x50 的i2c设备的所有数据
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f    0123456789abcdef
00: 00 ff ff ff ff ff ff 00 05 e3 01 24 26 02 00 00    ........???$&?..
10: 24 1f 01 04 a5 35 1e 78 3a 0e 31 a4 54 4d 9d 26    $????5?x:?1?TM?&
..: ...

$ i2cdump -y -r 0x00-0x7f 1 0x50   # 获取 i2c-1 上 addr=0x50 的i2c设备的 00-7f 范围的寄存器数据

i2cget

i2cget [-f] [-y] [-a] i2cbus chip-address [data-address [mode [length]]]

$ i2cget -y 1 0x50 0x10   # 获取 i2c-1 上 addr=0x50 的i2c设备的 0x10寄存器的值
$ i2cget -y 1 0x50 0x10 w # 获取16bit数据

i2cset

i2cset [-f] [-y] [-m mask] [-r] [-a] i2cbus chip-address data-address [value] ... [mode]

$ i2cset -y [i2cbus] [slv-addr] [addr] [val] # 常用格式
$ i2cset -y 1        0x50       0x11   0x42  # 将 0x42 写入 0x11寄存器
$ i2cset -y -m 0x0F 1 0x50 0x11 0x07  # 将0x07写入0x11寄存器,且mask=0x0F

i2ctransfer

i2ctransfer [-f] [-y] [-v] [-a] i2cbus desc [data] [desc [data]] …

# 创建 I2C 消息并将它们合并为一次传输。
$ i2ctranster 0 w1@0x50 0x64 r8
$ i2ctransfer 0 w17@0x50 0x42 0xff-
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值