I2C tools under Linux: i2c_tools

i2cdetectThe command is an I2C tool under Linux, which is used to scan the I2C bus and list the addresses of existing I2C devices. It is usually installed in i2c-toolsa package.

i2cdetectThe command supports two modes: -lmode and -ymode.

  1. -lmodel

i2cdetect -lcommand is used to list all available I2C buses in the system. In the Linux system, the I2C bus is usually expressed as /dev/i2c-*a device node, where *is a number, indicating the number of the I2C bus. This command will list the number and adapter type of each I2C bus.

  1. -ymodel

i2cdetect -yThe command is used to scan the specified I2C bus and list valid I2C device addresses present on the bus. Among them -y, the option means to run the I2C detection command in a non-interactive mode.

This command will output a matrix where each number represents an I2C address. If an I2C device exists at that address, the corresponding number is marked UU, otherwise --.

In short, i2cdetectthe command is very useful and can help us quickly scan the I2C bus and list all existing I2C device addresses, which is convenient for subsequent I2C device operation and debugging.

[1] Use i2cdetect to detect several sets of i2c buses on the system

i2cdetect -lcommand is used to list all available I2C buses in the system. In the Linux system, the I2C bus is usually expressed as /dev/i2c-*a device node, where *is a number, indicating the number of the I2C bus.

i2cdetect -lThe command will list the number and adapter type of each I2C bus, for example:

i2c-0   i2c             msm_i2c.0                              I2C adapter
i2c-1   i2c             msm_i2c.1                              I2C adapter
i2c-2   i2c             QUP I2C adapter with a QUP v1.1 compatible HW blockqm_i2c.2                              I2C adapter

In this example, there are three I2C buses in the system, namely i2c-0, i2c-1and i2c-2, and the corresponding adapter types are msm_i2c.0, msm_i2c.1and qm_i2c.2.

In short, i2cdetect -lthe command can help us view the available I2C bus and the corresponding adapter type in the system, which is convenient for subsequent I2C device operation and debugging.

[2] Query the device and the address of the device connected to the i2c bus

i2cdetect -y <number>

The i2cdetect -y 0command is used to scan the I2C bus /dev/i2c-0and list all valid I2C device addresses present on the bus. Among them -y, the option means to run the I2C detection command in a non-interactive mode.

This command will output a matrix where each number represents an I2C address. If an I2C device exists at that address, the corresponding number is marked UU, otherwise --.

For example, the following is i2cdetect -y 0the output of the command after execution:

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- 48 -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

In this example, it can be seen that /dev/i2c-0there is a valid I2C device on the I2C bus with address 0x48.

In short, i2cdetect -y 0the command can help us scan the I2C bus, find the address of the I2C device, and facilitate the subsequent operation and debugging of the I2C device.

Guess you like

Origin blog.csdn.net/weixin_42581177/article/details/131158404
I2C