i2c-tool使用詳細說明

1.首先檢測系統上有幾組i2c:

root@imx8qmmek:/etc/xen# i2cdetect -l
i2c-3   i2c             56247000.i2c                            I2C adapter
i2c-2   i2c             56226000.i2c                            I2C adapter

由上可知,系統中存在兩組總線分別i2c-2和i2c-3。

2.用i2cdetect檢測掛載在i2c總線上器件

輸入 i2cdetect -r -y 2 ,該命令是檢測56247000.i2c(i2c0_mipi_dsi0)上的i2c。

root@imx8qmmek:/etc/xen# i2cdetect -r -y 2 
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- UU -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: UU -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --  

一共掛載了兩個設備,分別是60和2a。
查看dts,確實如此:

&i2c0_mipi_dsi0 {
	dsi-pannel@60 {
		compatible = "max96755";
		reg = <0x60>;
		#address-cells = <0x1>;
		#size-cells = <0x0>;
		#reset-cells = <0x1>;
    	};
	dsi-pannel@2a {
		compatible = "max96752";
		reg = <0x2a>;
		#address-cells = <0x1>;
		#size-cells = <0x0>;
		#reset-cells = <0x1>;
	};
};

3.用i2cdump查看器件所有寄存器的值

這個很有用,輸入 i2cdump -f -y 2 0x2a (查看max96752存器值)

root@imx8qmmek:/etc/xen# i2cdump -f -y 2 0x2a
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: da 00 81 00 fb 03 00 00 00 00 00 43 01 03 00 00    ?.?.??.....C??..
10: 55 55 55 00 00 00 00 00 00 00 00 00 00 00 00 00    UUU.............
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.用i2cset設置單個寄存器值

用i2cget讀取單個寄存器值。

i2cset -f -y 2 0x2a 0x77 0x3f (設置i2c-1上0x20器件的0x77寄存器值爲0x3f)
i2cget -f -y 2 0x2a 0x0d    (讀取i2c-1上0x20器件的0x77寄存器值)

5.用i2ctransfer讀16位寄存器。

i2ctransfer -f -y 2 w2@0x60 0x00 0x0d r1 (其中參數2爲i2c2,w2表示寫兩個字節,@0x60爲你的i2c設備(注意要7位地址),0x00 0x0d 爲高低位地址,r1爲讀取的數據是一個byte。)

i2ctransfer  -f -y 2 w4@0x60 0x03 0x30 0x00 0x06

i2ctransfer  -f -y 2 w2@0x60 0x02 0xd3 r1
i2ctransfer  -f -y 2 w3@0x60 0x02 0xd3  0x84 

i2ctransfer  -f -y 2 w2@0x2a 0x02 0x15 r1
i2ctransfer  -f -y 2 w3@0x2a 0x02 0x15  0x82  

6.linux yocto添加方法(默認加了):

conf/local.conf
IMAGE_INSTALL_append += " i2c-tools"
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章