Raspberry Pi Study Notes-I2C tools Study Notes

Source: Internet
Author: User

I2ctool Raspberry Pi Linux

Directory (?) [+]

    1. Install

    2. I2C bus Scanning

    3. I2C device Query

    4. Register content Export

    5. Register content writing

    6. Register content reading

    7. Summary

    8. 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?

    1. Pi @ raspberrypi :~ $ I2cdetect-l

    2. 4) i2c-0 I2C bcm2708_i2c.0 I2C Adapter

    3. 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?

  1. Pi @ raspberrypi :~ $ I2cdetect-Y 1

  2. 0 1 2 3 4 5 6 7 8 9 A B C D E F

  3. 00 :--------------------------

  4. 10 :--------------------------------

  5. 20: 20 ------------------------------

  6. 30 :--------------------------------

  7. 40 :--------------------------------

  8. 50: 50 51 ----------------------------

  9. 60 :--------------------------------

  10. 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?

  1. Pi @ raspberrypi :~ $ I2cdump-Y 1 0x51

  2. No size specified (using byte-Data Access)

  3. 0 1 2 3 4 5 6 7 8 9 a B C D E F 0123456789 abcdef

  4. 00: FF ................

  5. 10: FF ................

  6. 20: FF ................

  7. 30: FF ................

  8. 40: FF ................

  9. 50: FF ................

  10. 60: FF ................

  11. 70: FF ................

  12. 80: FF ................

  13. 90: FF ................

  14. A0: FF ................

  15. B0: FF ................

  16. C0: FF ................

  17. D0: FF ................

  18. E0: FF ................

  19. 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?

    1. Pi @ raspberrypi :~ $ I2cget-Y 1 0x50 0x00

    2. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.