I2ctool Raspberry Pi Linux
Directory (?) [+]
Install
I2C bus Scanning
I2C device Query
Register content Export
Register content writing
Register content reading
Summary
References
1. Install
For information about I2C driver loading and Speed Modification, see [Raspberry Pi learning notes-I2C device loading and speed setting ].
2. I2C bus Scanning
The i2cdetect-l command can be used to view the I2C bus on Raspberry Pi. From the returned results, Raspberry Pi contains two I2C buses. By reading relevant information, Raspberry Pi uses i2c0 on the first generation, raspberry Pi uses i2c1 for the second generation.
[Plain]View plaincopyprint?
Pi @ raspberrypi :~ $ I2cdetect-l
4) i2c-0 I2C bcm2708_i2c.0 I2C Adapter
I2c-1 I2C bcm2708_i2c.1 I2C Adapter
[email protected]:~$ i2cdetect -li2c-0 i2c bcm2708_i2c.0 I2C adapteri2c-1 i2c bcm2708_i2c.1 I2C adapter
3. I2C device Query
If I2C slave devices are mounted on the bus, you can use i2cdetect to scan all devices on an I2C bus. Enter i2cdetect-Y 1 on the console. The result is as follows.
[CPP]View plaincopyprint?
Pi @ raspberrypi :~ $ I2cdetect-Y 1
-
0 1 2 3 4 5 6 7 8 9 A B C D E F
-
00 :--------------------------
-
10 :--------------------------------
-
20: 20 ------------------------------
30 :--------------------------------
-
40 :--------------------------------
-
50: 50 51 ----------------------------
-
60 :--------------------------------
-
70 :----------------
[email protected]:~$ i2cdetect -y 1 0 1 2 3 4 5 6 7 8 9 a b c d e f00: -- -- -- -- -- -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: 20 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: 50 51 -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- --
Note 1:-y is an optional parameter. If the-y parameter exists, there is a user interaction process, meaning that you want to stop using the I2C bus. If this parameter is written, there is no interaction process. This parameter is generally used in the script.
NOTE 2: two devices, pcf8574 and at24c04, are mounted on the I2C bus. The slave address 0x20 is pcf8574, And the slave address 0x50 and 0x51 is at24c04. Note that at24c04 has two I2C addresses, for more information, see product reference section 6.4.
4. Register content Export
The i2cdump command can be used to export the content of all registers in the I2C device. For example, if you enter i2cdump-Y 1 0x51, you can obtain the following information:
[Plain]View plaincopyprint?
-
Pi @ raspberrypi :~ $ I2cdump-Y 1 0x51
-
No size specified (using byte-Data Access)
-
0 1 2 3 4 5 6 7 8 9 a B C D E F 0123456789 abcdef
00: FF ................
-
10: FF ................
-
20: FF ................
-
30: FF ................
40: FF ................
-
50: FF ................
-
60: FF ................
-
70: FF ................
80: FF ................
-
90: FF ................
-
A0: FF ................
-
B0: FF ................
C0: FF ................
-
D0: FF ................
-
E0: FF ................
-
F0: FF ................
[email protected]:~$ i2cdump -y 1 0x51No size specified (using byte-data access) 0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef00: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................10: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................20: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................30: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................40: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................50: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................60: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................70: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................80: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................90: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................a0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................b0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................c0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................d0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................e0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................f0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
In the i2cdump-Y 1 0x51 command,
-Y indicates canceling the user interaction process and executing commands directly;
1 represents the I2C bus number;
0x51 represents the slave address of the I2C device. Here, the 256-byte content of at24c04 is selected.
The 256-byte height of at24c04 is still in the factory default state, and the content of all storage addresses is 0xff.
5. Register content writing
If a byte is written to the I2C device, enter the command i2cset-Y 1 0x50 0x00 0x13
-Y indicates the curve user interaction process and directly executes commands.
1 represents the I2C bus number
0x50 represents the I2C device address. Here, select the 256-byte content of at24c04.
0x00 indicates the memory address
0x13 indicates the specific content in the memory address
6. Register content reading
[Plain]View plaincopyprint?
Pi @ raspberrypi :~ $ I2cget-Y 1 0x50 0x00
0x13
[email protected]:~$ i2cget -y 1 0x50 0x000x13
If a byte is read from the device by I2C, run i2cget-Y 1 0x50 0x00 to obtain the following feedback.
-Y indicates the curve user interaction process and directly executes commands.
1 represents the I2C bus number
0x50 represents the I2C device address. Here, select the 256-byte content of at24c04.
0x00 indicates the memory address
7. Summary
I2ctools is a simple and easy-to-use tool that makes debugging on I2C devices more convenient.
8. References
[1] i2ctools official references
[2] Why does at24c04 have two I2C slave address?
Raspberry Pi Study Notes-I2C tools Study Notes