Android/linux 平台下使用 i2c-tools调试IIC方法

本文介绍了如何利用busybox及其包含的i2c-tools工具来管理和操作I2C总线上的设备。通过i2cdetect、i2cdump、i2cget和i2cset命令,可以检测I2C总线、批量获取设备寄存器数据、读取和写入特定寄存器。示例代码展示了如何列出I2C总线、检测I2C设备位置、读取和写入设备寄存器。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在busybox包含i2c-tools工具,使用时只需busybox+指令只可。

  • i2cdetect
  • i2cdump
  • i2cget
  • i2cset

i2cdetect

列举 I2C bus

  1. # i2cdetect -l  
  2. i2c-0   i2c             imx-i2c                                 I2C adapter  
  3. i2c-1   i2c             imx-i2c                                 I2C adapter  
  4. i2c-2   i2c             imx-i2c                                 I2C adapter  
# i2cdetect -l
i2c-0   i2c             imx-i2c                                 I2C adapter
i2c-1   i2c             imx-i2c                                 I2C adapter
i2c-2   i2c             imx-i2c                                 I2C adapter
列举 I2C bus i2c-1 上面连接的所有设备

  1. # i2cdetect -y 1  
  2.      0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f  
  3. 00:          -- -- -- -- -- UU -- -- -- -- -- -- --   
  4. 10: -- UU -- -- -- -- -- -- -- -- -- -- -- -- -- --   
  5. 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --   
  6. 30: -- -- -- -- -- -- -- -- -- -- 3a -- -- -- -- --   
  7. 40: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- --   
  8. 50: UU -- -- -- -- -- -- -- -- -- -- -- -- -- -- --   
  9. 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --   
  10. 70: -- -- -- -- -- -- -- --  
# i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- UU -- -- -- -- -- -- -- 
10: -- UU -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- 3a -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- -- 
50: UU -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --
发现 I2C 设备的位置显示为 UU或者表示设备地址的数值, UU表示该设备在 driver 中被使用。

i2cdump

dump I2C 设备大批量 register 的值

  1. # i2cdump -y -f 1 0x3a  
  2. No size specified (using byte-data access)  
  3.      0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f    0123456789abcdef  
  4. 00: eb 00 7f 05 3d 00 00 00 08 06 00 00 00 00 00 00    ?.??=...??......  
  5. 10: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................  
  6. 20: 01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10    ?#Eg????????vT2?  
  7. 30: f0 e1 d2 c3 00 00 00 00 00 00 00 00 00 00 00 00    ????............  
  8. 40: 80 00 10 00 00 00 00 00 00 00 00 00 00 00 00 00    ?.?.............  
  9. 50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................  
  10. 60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................  
  11. 70: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................  
  12. 80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................  
  13. 90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................  
  14. a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................  
  15. b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................  
  16. c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................  
  17. d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................  
  18. e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................  
  19. f0: 00 00 00 00 00 00 00 00 00 00 00 30 00 00 00 00    ...........0....  
# i2cdump -y -f 1 0x3a
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: eb 00 7f 05 3d 00 00 00 08 06 00 00 00 00 00 00    ?.??=...??......
10: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
20: 01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10    ?#Eg????????vT2?
30: f0 e1 d2 c3 00 00 00 00 00 00 00 00 00 00 00 00    ????............
40: 80 00 10 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: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
90: 00 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 30 00 00 00 00    ...........0....

i2cget

读取 I2C 设备某个 register 的值

  1. # i2cget -y -f 1 0x3a 0x02  
  2. 0x7f  
# i2cget -y -f 1 0x3a 0x02
0x7f


i2cset

设置 I2C 设备某个 register 的值

  1. # i2cset -y -f 1 0x3a 0x02 0x05  
# i2cset -y -f 1 0x3a 0x02 0x05

参考

http://my.oschina.net/luoly/blog/368881

正常log [ 116.487588] (0)[455:composer@2.1-se][HIF-SDIO][W]wmt_fb_notifier_callback:@@@@@@@@@@wmt enter early POWERDOWN @@@@@@@@@@@@@@ [ 116.487606] (0)[455:composer@2.1-se][wlan][455]wlan_fb_notifier_callback:(SW4 INFO) wlan_fb_notifier_callback: event[9], blank[4] [ 116.487611] (0)[455:composer@2.1-se][wlan][455]kalSetPerMonDisable:(SW4 INFO) enter kalSetPerMonDisable [ 116.487623] (0)[455:composer@2.1-se][wlan][455]wlan_fb_notifier_callback:(SW4 INFO) wlan_fb_notifier_callback: end [ 116.487631] (1)[1208:main_thread][wlan][1208]kalPerMonDisable:(SW4 INFO) enter kalPerMonDisable [ 116.487748] (1)[1208:main_thread][wlan][1208]kalPerMonUpdate:(SW4 INFO) <2973ms> Tput: 0(0.000mbps) [0:0:0:0][0:0:0:0][0:0:0:0][0:0:0:0] Pending:0/256 [0:0:0:0][0:0:0:0][0:0:0:0][0:0:0:0] Used:0/768/256 [0][0][0][0][0] LQ[0:0:0] lv:0 th:3 fg:0x7 Mo:[0:0:0:0] TxDp[ST:BS:FO:QM:DP]:0:0:0:0:0 [ 116.487762] (1)[1208:main_thread][wlan][1208]kalPerMonUpdate:(SW4 INFO) ndevdrp:[0:0:0:0][0:0:0:0][0:0:0:0] drv[RM,IL,RI,RT,RM,RW,RA,RB,DT,NS,IB,HS,LS,DD,ME,BD,NI,DR,TE,CE,DN,FE,DE,IE,TME]:9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 [ 116.487867] (0)[203:kworker/0:2][STP-PSM] [I]_stp_psm_do_wait: STP is waiting state for ACT, i=1, state = 2 [ 116.511882] -(1)[1024:system_server]alarmtimer_enqueue, 574145000000 [ 116.523904] (0)[203:kworker/0:2][STP-PSM] [I]_stp_psm_do_wait: +Total waits for ACT takes 36025 usec [ 116.525750] (0)[203:kworker/0:2][HIF-SDIO][I]mtk_wcn_wmt_func_ctrl:wmt-exp: OPID(4) type(9) start [ 116.525801] (1)[580:mtk_wmtd][WMT-CORE][I]wmt_core_dump_func_state:[AF FUNC OFF]status(b:0 f:0 g:0 gl5:0 w:2 lpbk:0 coredump:0 wmt:2 ant:0 sd1:0 sd2:0 stp:0) [ 116.526065] (0)[203:kworker/0:2][HIF-SDIO][I]mtk_wcn_wmt_func_ctrl:OPID(4) type(9) ok [ 116.565175] (1)[573:mtk_stp_psm]MTK-BTIF-EXP[I]mtk_wcn_btif_dpidle_ctrl:enter deep idle [ 116.617529] (0)[335:logd.auditd]type=1400 audit(1672660091.950:271): avc: denied { read } for comm="binder:377_4" name="wakeup113" dev="sysfs" ino=38281 scontext=u:r:system_suspend:s0 tcontext=u:object_r:sysfs_batteryinfo:s0 tclass=dir permissive=0 [ 116.644258] -(0)[456:health@2.1-serv]mt635x_auxadc_read_raw: 5 callbacks suppressed [ 116.644269] (0)[456:health@2.1-serv]mt635x-auxadc mt635x-auxadc: name:BATADC, channel=0, adc_out=0x5f4c, adc_result=4020 [ 116.648067] (0)[456:health@2.1-serv]mt635x-auxadc mt635x-auxadc: name:BAT_TEMP, channel=3, adc_out=0xa9b, adc_result=1193 [ 116.648746] (0)[456:health@2.1-serv]mt635x-auxadc mt635x-auxadc: name:VBIF, channel=11, adc_out=0xfff, adc_result=1799 [ 116.650187] (1)[456:health@2.1-serv]mt635x-auxadc mt635x-auxadc: name:BAT_TEMP, channel=3, adc_out=0xa9c, adc_result=1193 [ 116.650871] (0)[456:health@2.1-serv]mt635x-auxadc mt635x-auxadc: name:VBIF, channel=11, adc_out=0xfff, adc_result=1799 异常log [ 119.152791] (0)[455:composer@2.1-se][HIF-SDIO][W]wmt_fb_notifier_callback:@@@@@@@@@@wmt enter early POWERDOWN @@@@@@@@@@@@@@ [ 119.152823] (0)[455:composer@2.1-se][wlan][455]wlan_fb_notifier_callback:(SW4 INFO) wlan_fb_notifier_callback: event[9], blank[4] [ 119.152833] (0)[455:composer@2.1-se][wlan][455]kalSetPerMonDisable:(SW4 INFO) enter kalSetPerMonDisable [ 119.152861] (0)[455:composer@2.1-se][wlan][455]wlan_fb_notifier_callback:(SW4 INFO) wlan_fb_notifier_callback: end [ 119.152876] (1)[1208:main_thread][wlan][1208]kalPerMonDisable:(SW4 INFO) enter kalPerMonDisable [ 119.153177] (1)[1208:main_thread][wlan][1208]kalPerMonUpdate:(SW4 INFO) <2665ms> Tput: 0(0.000mbps) [0:0:0:0][0:0:0:0][0:0:0:0][0:0:0:0] Pending:0/256 [0:0:0:0][0:0:0:0][0:0:0:0][0:0:0:0] Used:0/768/256 [0][0][0][0][0] LQ[0:0:0] lv:0 th:3 fg:0x7 Mo:[0:0:0:0] TxDp[ST:BS:FO:QM:DP]:0:0:0:0:0 [ 119.153206] (1)[1208:main_thread][wlan][1208]kalPerMonUpdate:(SW4 INFO) ndevdrp:[0:0:0:0][0:0:0:0][0:0:0:0] drv[RM,IL,RI,RT,RM,RW,RA,RB,DT,NS,IB,HS,LS,DD,ME,BD,NI,DR,TE,CE,DN,FE,DE,IE,TME]:9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 [ 119.153243] (0)[1100:kworker/0:3][STP-PSM] [I]_stp_psm_do_wait: STP is waiting state for ACT, i=1, state = 2 [ 119.178491] -(1)[1024:system_server]alarmtimer_enqueue, 574145000000 [ 119.184024] (0)[1100:kworker/0:3][STP-PSM] [I]_stp_psm_do_wait: +Total waits for ACT takes 30771 usec [ 119.185607] (0)[1100:kworker/0:3][HIF-SDIO][I]mtk_wcn_wmt_func_ctrl:wmt-exp: OPID(4) type(9) start [ 119.185856] (3)[580:mtk_wmtd][WMT-CORE][I]wmt_core_dump_func_state:[AF FUNC OFF]status(b:0 f:0 g:0 gl5:0 w:2 lpbk:0 coredump:0 wmt:2 ant:0 sd1:0 sd2:0 stp:0) [ 119.185956] (0)[1100:kworker/0:3][HIF-SDIO][I]mtk_wcn_wmt_func_ctrl:OPID(4) type(9) ok [ 119.225289] (0)[573:mtk_stp_psm]MTK-BTIF-EXP[I]mtk_wcn_btif_dpidle_ctrl:enter deep idle [ 119.369243] (0)[293:init]init 3: [119365][75]ReapLogT PropSet [sys.btn.screen.state]=[off]119164 [sys.bw.rup.icon.state]=[1000]119289 Done [ 119.386756] (1)[2301:binder:377_5]active wakeup source: ttyC0 [ 119.386873] (1)[2301:binder:377_5]active wakeup source: ttyC0 [ 119.714253] (1)[2301:binder:377_5]PM: suspend entry (deep) 导致 [ 90.462570] (0)[291:irq/145-tlsc6x_]i2c i2c-0: err, access at suspend no irq stage [ 90.462590] (0)[291:irq/145-tlsc6x_][tlsc][error] [IIC]: i2c_transfer(2) error, addr= 0xd3!! [ 90.462597] (0)[291:irq/145-tlsc6x_][tlsc][error] [IIC]: i2c_transfer(2) error, ret=-16, rlen=2, wlen=1!! 的原因,和解决方法
最新发布
07-19
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值