i2cset:向i2c设备某个寄存器写入值
Usage: i2cset [-f] [-y] [-m MASK] [-r] [-a] I2CBUS CHIP-ADDRESS DATA-ADDRESS [VALUE] ... [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
f:强制访问
y:指令执行自动yes,否则会提示确认执行Continue? [Y/n] Y,不加参数y会有很多执行提示,可以帮助判断
r:写入后立即回读寄存器的值,并将结果与写入的值进行比较
i2cbus:总线编号
chip-address:i2c设备地址
data-address:i2c寄存器地址
value 要写入的值
mode:指定读取的大小,b字节,w字,s是SMBus块,i是i2c块
设置i2c-1上0x20器件的0x77寄存器值为0x3f
./i2cset -f -y 1 0x20 0x77 0x3f
i2cget:读取i2c设备某个寄存器的值
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
f:强制访问
y:关闭交互模式,不会提示警告信息
i2cbus:总线编号
chip-address:i2c设备地址
data-address:i2c寄存器地址
mode:指定读取的大小,b字节,w字,s是SMBus块,i是i2c块
读取i2c-1上0x20器件的0x77寄存器值
./i2cget -f -y 1 0x20 0x77
i2cdump:读取某个i2c设备所有寄存器的值
Usage: i2cdump [-f] [-y] [-r first-last] [-a] I2CBUS ADDRESS [MODE [BANK [BANKREG]]]
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 (byte, default)
w (word)
W (word on even register addresses)
s (SMBus block)
i (I2C block)
c (consecutive byte)
Append p for SMBus PEC
r:指定寄存器范围,只能扫描从 first 到 last 区域
f:强制访问设备
y:关闭人机交互模式
i2cbus:总线编号
address:指定设备地址
mode:指定读取的大小,b字节,w字,s是SMBus块,i是i2c块
读取i2c1上0x38器件的所有寄存器
./i2cdump -f -y -a 1 0x38
一般寄存器都是8位地址的,i2cdump、i2cget、i2cset 也是设置读取8位的地址,如果一次超过8位,需要用 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)
查看系统上存在的 i2c 总线及其设备地址
ls /sys/bus/i2c/devices/
可以在这里查看实际的设备,然后对比 i2c-tools 扫描出来的对不对。
全部0条评论
快来发表一下你的评论吧 !