嵌入式爱好者

i2c-tools

2019-4-25 16:07| 发布者: zzinlinx| 查看: 1415| 评论: 0

类目: 知识库  >  AM5718系列产品     文档编号: 274

i2c-tools使用

5718的镜像带有i2c-tools工具, 下面介绍i2c-tools工具包的使用

检测总线数目

root@ok5718-idk:~# i2cdetect -l
i2c-1   i2c             OMAP I2C adapter                        I2C adapter
i2c-4   i2c             OMAP I2C adapter                        I2C adapter
i2c-2   i2c             OMAP I2C adapter                        I2C adapter
i2c-0   i2c             OMAP I2C adapter                        I2C adapter
root@ok5718-idk:~#

其中i2c-1编号的总线为I2C1的总线,对应开发板原理图

需要在设备树中打开i2c1的使能, 并重新编译设备树,替换设备树,从新启动。

查看总线挂载设备

root@ok5718-idk:~# i2cdetect -r -y 4
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- UU -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
root@ok5718-idk:~#

可以看到 0x32和 0x48 有设备挂载。查看设备树文件可以一一对应上

其他的总线挂载类似。

当前总线挂载状态

总线编号设备树文件引用reg设备备注
I2C-0&I2C1reg=0x48tmp102
reg=0x58tps65917
I2C-2&I2C3reg=0x1Awm8960
I2C-4&I2C5reg=0x32rtc
reg=0x48ts2007

单独操作设备

使用i2cdump查看器件所有寄存器的值:

root@ok5718-idk:~# i2cdump -f -y 4 0x32
No size specified (using byte-data access)
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f    0123456789abcdef
00: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX    **********X
10: 04 58 21 02 26 09 17 d8 00 10 00 00 00 06 20 00    ?X!?&???.?...? .
20: 01 01 10 01 00 00 80 01 0a 24 60 03 02 00 00 00    ????..???$`??...
30: 00 08 00 00 00 00 00 00 00 00 00 00 00 00 00 00    .?..............
40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
50: 00 00 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: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX    **********X
80: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX    **********X
90: 05 58 21 02 26 09 17 d8 00 10 00 00 00 06 20 00    ?X!?&???.?...? .
a0: 01 01 10 01 00 00 80 01 0a 24 60 03 02 00 00 00    ????..???$`??...
b0: 00 08 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: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX    **********X
root@ok5718-idk:~#

读写测试

root@ok5718-idk:~# i2cset -f -y 4 0x32 0x30 0xff
root@ok5718-idk:~# i2cget -f -y 4 0x32 0x30
0xff
root@ok5718-idk:~#

可以用i2cdump来验证是否写入

root@ok5718-idk:~# i2cdump -f -y 4 0x32
No size specified (using byte-data access)
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f    0123456789abcdef
00: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX    **********X
10: 11 15 22 02 26 09 17 d8 00 10 00 00 00 06 20 00    ??"?&???.?...? .
20: 01 01 10 01 00 00 80 01 0a 24 60 03 02 00 00 00    ????..???$`??...
30: ff 08 00 00 00 00 00 00 00 00 00 00 00 00 00 00    .?..............
40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
50: 00 00 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: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX    **********X
80: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX    **********X
90: 12 15 22 02 26 09 17 d8 00 10 00 00 00 06 20 00    ??"?&???.?...? .
a0: 01 01 10 01 00 00 80 01 0a 24 60 03 02 00 00 00    ????..???$`??...
b0: ff 08 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: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX    **********X
root@ok5718-idk:~#

已解决

未解决

只是看看

最新评论

QQ|小黑屋| 飞凌嵌入式 ( 冀ICP备12004394号-1 )

GMT+8, 2024-11-22 09:24

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

返回顶部