i2c_tools记录

i2c_tools是一个帮助调试i2c的开源工具;

使用说明:

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

1、i2cdetect:

直接在板子上敲i2cdetect,就会弹出帮助:

可以看到: 

有命令: i2cdetect -y -a  总线 试一下看看

可以看到:iic 1 下挂的设备地址是: 0x50  0x51 0x52  0x53  提示说不能使用smbus 快速访问,跳过了一些地址。那证明这些地址是可以通过 smbus 快速访问的;

再试一下: i2cdetect -y  -r 1  果然,确实跳过了一些地址: 0x4b  0x4c  0x4f之前就没有

 

再看一下: i2cdetect -F  表示支持哪些功能对吧;我感觉一般帮助不大,继续看;还有个 -l参数呢

再看:  i2cdetect -l  (list) : 列举了我板子上的两个总线; 都出来了   

所以:  -l  表示  总线的列举

             -F 表示某一总线支持的功能

             -y -r -a 等 是查看某个总线下的设备地址的;

2、i2cdump  :还是老方法敲击 i2cdump查看帮助

我们知道linux中有个hexdump一般查看二进制文件的: 16进制输出这个也应该差不多

i2cdump -f  -y  1   0x4f  (-f  -y  不能缺省,否则报错)1表示总线 0x4f表示设备地址     所以他就是查看设备的寄存器值命令 缺省按字节显示 (b  byte)word两个字节

3、 i2ctransfer  :

:~# i2ctransfer                                                  
Usage: i2ctransfer [-f] [-y] [-v] [-V] [-a] 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)                                        
    + (increase value by 1 until LENGTH)                                        
    - (decrease value by 1 until LENGTH)                                        
    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 w1@0x50 0x64 r8                                               
Example (same EEPROM, at offset 0x42 write 0xff 0xfe ... 0xf0):                 
  # i2ctransfer 0 w17@0x50 0x42 0xff-  

上面的命令没看懂但是example讲的很清楚哈;

Example (bus 0, read 8 byte at offset 0x64 from EEPROM at 0x50):                
  # i2ctransfer 0 w1@0x50 0x64 r8   

从0x50 这个设备里的0x64地址开始读取8个字节,

DESC describes the transfer in the form: {r|w}LENGTH[@address] 

参数含义应该就是: 0 表示总线 , w1表示宽度一次读取一个字节,  0x50表示设备地址,  0x64表示 设备中的寄存器地址   r 表示read 从设备中读取数据  8 表示读取数据的数量;

试一试: i2ctransfer -f -y 1 w1@0x4f 0x00 r8  嘿嘿果然如此啊

他还有写的功能:差别就是最后的r8 变成了写入的值的最大值.

Example (same EEPROM, at offset 0x42 write 0xff 0xfe ... 0xf0):                 
  # i2ctransfer 0 w17@0x50 0x42 0xff- 

观察一下哈:  w17 宽度是17表示有17个字节写入,从0x42开始,   数据从0xff递减一直到0xf0刚好17个对吧;

     因为有个“ - ” 减号所以是递减,上面的解释也说了还可以用+ = 等操作;

因为没有这个器件芯片手册所以没办法试试写入功能,不知道寄存器是否可写。所以就不测试了

4、i2cget  : 还是一样看看帮助文档 

:~# i2cget                                                       
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  

和之前的参数差不多,一看就懂了读取指定的寄存器值; 一个字节或者一个字(word)

 

5、i2cset :和get对应就是写入一个字节或者一个字了嘛;没办法测试了。

 i2cset                                                       
Usage: i2cset [-f] [-y] [-m MASK] [-r] [-a] I2CBUS CHIP-ADDRESS DATA-ADDRESS [VA
LUE] ... [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     

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值