系统:qnx
1.使用
use i2ctool
usage: i2ctool
options:
list: list all the valid i2c buses
scan: list all the valid address in the specified i2c bus
read: read mode
write: write mode
endian: little/big endian, 0: little, 1: big
verbosity: log level
for example:
i2ctool list
i2ctool /dev/i2c1 scan
i2ctool /dev/i2c1 read 0x62 0x00 2 1
i2ctool /dev/i2c1 read 0x62 0x00 2 1 endian 1
i2ctool /dev/i2c1 write 0x62 0x00 2 0xc4 endian 1
i2ctool /dev/i2c1 read 0x62 0x00 2 1 endian 1
| | | | | |
| | | | | |
| | | | | |
[i2c bus] [slave address] [register addr] [reg len (2 bytes)] [read len (1 byte)] [Big endian]
i2ctool /dev/i2c1 write 0x62 0x00 2 0xc4 endian 1
| | | | | |
| | | | | |
| | | | | |
[i2c bus] [slave address] [register addr] [reg len (2 bytes)] [write value] [Big endian]
注意:
1.slave address为7bit值,如果需要读取的寄存器位16位,则reg_len为2 byte,
2.cci总线和i2c总线使用的方式一样
2.扫描总线器件
i2ctool /dev/i2c4 scan
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- 34 -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
在代码中也可以直接使用如
system("i2ctool /dev/i2c2 scan");
system("i2ctool /dev/cci2 scan");
3.读取16位寄存器的值
i2ctool /dev/i2c4 read 0x34 0x42 2 1 endian 1
argc: 9, endian: 1, reg_addr: 0x42, reg_size: 1
read slave_address: 0x34, register_address: 0x4200, reg_addr_len: 2, size: 1
R data:
reg(0x42): 0x30
R: success
4.写入总线寄存器
i2ctool /dev/i2c4 write 0x34 0x3200 2 0x1f endian 1
write slave_address: 0x34 , register_address: 0x32, reg_addr_len: 2
write data_len: 1, data: 0x1f
W: success
read slave_address: 0x34 , register_address: 0x3200, reg_addr_len: 2, size: 1
R data:
reg(0x34): 0x01f
R: success