一极祸、下載i2c-tools卧晓,交叉編譯
1贞远、從開源網(wǎng)站http://dl.lm-sensors.org/i2c-tools/releases/ 下載i2c-tools
2蹬刷、編譯生成對應(yīng)的可執(zhí)行文件
i2cdetect, i2cdump, i2cget, i2cset
二瓢捉、使用舉例
1、用i2cdetect檢測有幾組i2c總線在系統(tǒng)上办成,輸入:
:/ # i2cdetect
Error: No i2c-bus specified!
Usage: i2cdetect [-y] [-a] [-q|-r] I2CBUS [FIRST LAST]
i2cdetect -F I2CBUS
i2cdetect -l
I2CBUS is an integer or an I2C bus name
If provided, FIRST and LAST limit the probing range.
:/ # i2cdetect -l
i2c-1 i2c aml_i2c_adap1 I2C adapter
i2c-2 i2c aml_i2c_adap2 I2C adapter
i2c-3 i2c aml_i2c_adap3 I2C adapter
2泡态、用i2cdetect檢測掛載在i2c總線上器件,以總線3為例迂卢,輸入
:/ # i2cdetect -r -y 3
-- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- UU -- --
20: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- 43 -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
可以看到上面的輸出是有識別的0x43 這個器件某弦,這個也是我實際環(huán)境上的一個器件
3、用i2cdump查看器件所有寄存器的值而克,以總線3上0x43 這個器件為例靶壮,輸入
:/ # i2cdump
Error: No i2c-bus specified!
Usage: i2cdump [-f] [-y] [-r first-last] I2CBUS ADDRESS [MODE [BANK [BANKREG]]]
I2CBUS is an integer or an I2C bus name
ADDRESS is an integer (0x03 - 0x77)
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
:/ # i2cdump -f -y 3 0x43
No size specified (using byte-data access)
0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef
00: 00 a0 00 00 00 00 00 ff 00 00 00 ff 00 00 00 6d .?.............m
10: 00 00 00 00 00 00 00 00 83 01 00 00 00 00 00 00 ........??......
20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
70: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
4、用i2cget 看單個寄存器地址, 以總線3上0x43 0x01這個寄存器為例
:/ # i2cget
Usage: i2cget [-f] [-y] I2CBUS CHIP-ADDRESS [DATA-ADDRESS [MODE]]
I2CBUS is an integer or an I2C bus name
ADDRESS is an integer (0x03 - 0x77)
MODE is one of:
b (read byte data, default)
w (read word data)
c (write byte/read byte)
Append p for SMBus PEC
:/ # i2cget -f -y 3 0x43 0x01
0xa0
讀出來的值跟上面dump是一樣的
5员萍、i2cset 操作寄存器值, 以總線3上0x43 0x03這個寄存器為例
:/ # i2cset
Usage: i2cset [-f] [-y] [-m MASK] [-r] I2CBUS CHIP-ADDRESS DATA-ADDRESS [VALUE] ... [MODE]
I2CBUS is an integer or an I2C bus name
ADDRESS is an integer (0x03 - 0x77)
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
:/ # i2cset -f -y 3 0x43 0x03 0x7f
:/ #
:/ # i2cget -f -y 3 0x43 0x03
0x7f
設(shè)置為0x03 0x7f 后腾降,讀取0x03為0x7f 修改成功
三、注意事項
Error: Could not set address to 0x49: Device or resource busy
From the manpage it looks like I can use the f option to force the connection
(source: http://manpages.ubuntu.com/manpages/hardy/man8/i2cget.8.html)
-f
Force access to the device even if it is already busy. By
default, i2cget will refuse to access a device which is already
under the control of a kernel driver. Using this flag is dangerous, it can seriously confuse the kernel driver in question. It can also cause i2cget to return an invalid value. So use at your own risk and only if you know what you’re doing.
因為設(shè)置已經(jīng)在kernel driver的控制下了充活,所以i2c tool返回 Device or resource busy
所以有兩個方法
一個rmmod dirver
一個是 使用i2c tool帶上 -f參數(shù)
# i2cdump -y -f 3 0x28