【I2C】i2c-tools工具使用,以及开发调试
i2c调试
eeprom
手动创建eeprom设备调试,例如0x50 是FRU的地址,i2c-3是bus
创建设备
echo 24c32 0x50 > /sys/bus/i2c/devices/i2c-4/new_device
如果设备正确,将成功被创建,并且生成/sys/bus/i2c/devices/4-0050/eeprom:
 
使用hexdump -C eeprom 可以查看里面的数据
 
 如果想要写二进制数据,可使用命令
dd if=/path/to/fru.bin of=/sys/bus/i2c/devices/4-0054/eeprom bs=1 count=256
删除设备的命令
echo 0x50 > /sys/bus/i2c/devices/i2c-3/delete_device
i2c-tools工具
i2cdetect
扫描I2C BUS上所有设备
 https://linux.die.net/man/8/i2cdetect
显示所有bus
 i2cdetect -l
扫描bus下设备
 i2cdetect -y 3
 3指bus number
i2cdump
显示设备上所有register值
 https://linux.die.net/man/8/i2cdump
读取某I2C设备下所有registers的值
 i2cdump -y 16 0x1d
 16为i2c bus
 0x1d为i2c slave
i2cget
读取装置上某个register的值
 https://linux.die.net/man/8/i2cget
i2cget -f -y
b (read byte data, default)
 w (read word data)
 i (read I2C block data)
获取bus 11上 0x32设备的数据
 1)get byte
 i2cget -f -y 11 0x32 0x00
 i2cget -f -y 11 0x32 0x00 b
2)getword
 i2cget -f -y 11 0x32 0x00 w
(get 6 bytes)最大只能获取32个字节
 i2cget -f -y 11 0x32 0x00 i 6
i2cset
写入设备上某个register
 https://linux.die.net/man/8/i2cset
i2cset -f -y
c (byte, no value)
 b (byte data, default)
 w (word data)
 i (I2C block data)
 s (SMBus block data)
 Append p for SMBus PEC
set byte
 i2cset -f -y
 i2cset -f -y
 切换bus 11上 0x70 (pca9548)设备的channel
 (如关闭9548的channel 1-8(bit0-7))
 i2cset -f -y 6 0x70 0x00
 (如打开9548的channel 1(bit0))
 i2cset -f -y 6 0x70 0x01
 (如打开9548的channel 2(bit1))
 i2cset -f -y 6 0x70 0x02
 (如打开9548的channel 3(bit2))
 i2cset -f -y 6 0x70 0x04
 (如打开9548的channel 1-8(bit0-7))
 i2cset -f -y 6 0x70 0xFF
mb
 -bus6
 –pca9548(0x70)
 —bp0(ch0)
 —-pca9548(0x74)
 —–disk0(ch0)
 i2cset -f -y 6 0x70 0x01
 i2cset -f -y 6 0x74 0x01
 i2cget -f -y 4 0x33 0x00
1)set word
 i2cset -f -y
 i2cset -f -y 6 0x32 0x0001 w
set block
 i2cset -f -y i
 i2cset -f -y i
 i2cset -f -y 6 0x32 0x00 0x01 0x02 0x03 i
write smbus block data with pec
 i2cset -f -y sp
 i2cset -f -y 6 0x32 0x00 0x01 0x02 0x03 … sp
i2ctransfer
传输i2c原始数据
write
 i2ctransfer w@
 向0x32写入2字节数据
 i2ctransfer 11 w2@0x32 0x00 0x01
 = = i2cset -f -y 6 0x32 0x00 0x01
向0x32写入256字节数据
 i2ctransfer 11 w256@0x32 0x00 0x01 0x02 …. 0xff
write&read
 i2ctransfer w@ r
 向0x32写入2字节数据,然后读取6个字节的数据i2ctransfer 11 w1@0x32 0x0e r32
 i2ctransfer 11 w2@0x32 0x00 0x01 r6
 = =
 i2cset -f -y 6 0x32 0x00 0x01
 i2cget -f -y 6 0x32 0x00 i 6
i2ctransfer 11 w2@0x32 0x00 0x01….
切PCA9548
 i2ctransfer -y -f 6 w1@0x70 0x00
 i2ctransfer -y -f 6 w1@0x70 0x01
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!