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:指令執(zhí)行自動yes,否則會提示確認(rèn)執(zhí)行Continue? [Y/n] Y,不加參數(shù)y會有很多執(zhí)行提示,可以幫助判斷
r:寫入后立即回讀寄存器的值,并將結(jié)果與寫入的值進(jìn)行比較
i2cbus:總線編號
chip-address:i2c設(shè)備地址
data-address:i2c寄存器地址
value 要寫入的值
mode:指定讀取的大小,b字節(jié),w字,s是SMBus塊,i是i2c塊
設(shè)置i2c-1上0x20器件的0x77寄存器值為0x3f
./i2cset -f -y 1 0x20 0x77 0x3f
i2cget:讀取i2c設(shè)備某個寄存器的值
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:關(guān)閉交互模式,不會提示警告信息
i2cbus:總線編號
chip-address:i2c設(shè)備地址
data-address:i2c寄存器地址
mode:指定讀取的大小,b字節(jié),w字,s是SMBus塊,i是i2c塊
讀取i2c-1上0x20器件的0x77寄存器值
./i2cget -f -y 1 0x20 0x77
i2cdump:讀取某個i2c設(shè)備所有寄存器的值
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 區(qū)域
f:強制訪問設(shè)備
y:關(guān)閉人機交互模式
i2cbus:總線編號
address:指定設(shè)備地址
mode:指定讀取的大小,b字節(jié),w字,s是SMBus塊,i是i2c塊
讀取i2c1上0x38器件的所有寄存器
./i2cdump -f -y -a 1 0x38
一般寄存器都是8位地址的,i2cdump、i2cget、i2cset 也是設(shè)置讀取8位的地址,如果一次超過8位,需要用 i2ctransfer。
i2ctransfer:一次性讀寫多個字節(jié)
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)
查看系統(tǒng)上存在的 i2c 總線及其設(shè)備地址
ls /sys/bus/i2c/devices/
可以在這里查看實際的設(shè)備,然后對比 i2c-tools 掃描出來的對不對。
-
嵌入式
+關(guān)注
關(guān)注
5149文章
19659瀏覽量
317360 -
寄存器
+關(guān)注
關(guān)注
31文章
5433瀏覽量
124416 -
命令
+關(guān)注
關(guān)注
5文章
737瀏覽量
22873
發(fā)布評論請先 登錄
I2C總線原理詳解

I2C通信詳解
I2C Guid I2C指南
I2C總線詳解
嵌入式linux應(yīng)用讀寫i2c示例

Linux應(yīng)用開發(fā)【第十二章】I2C編程應(yīng)用開發(fā)

STM32F103硬件I2C Slave

硬件I2C與模擬I2C

評論