Linux Tools i2c-tool and memtool32 for Register Operations

Linux | Red Hat Certified | IT Technology | Operations Engineer

👇Join our technical exchange QQ group with the remark 【Public Account】 for faster access

Linux Tools i2c-tool and memtool32 for Register Operations

1. First, download the i2c-tool and memtool32 tools directly to the development board for use:

Linux Tools i2c-tool and memtool32 for Register Operations

2. i2cdetect command: This command is used to scan for devices on the i2c bus of the board

Input ./i2cdetect to display the syntax operation instructions for the i2cdetect command

Linux Tools i2c-tool and memtool32 for Register Operations

Parameter Description:

Parameter y: Disable interactive mode; when using this parameter, no warning messages will be prompted.

Parameter a: Scan all devices on the bus.(I generally use -y instead of -a to scan devices)

Parameter q: Use the SMBus ‘quick write’ command for detection; this parameter is not recommended.

Parameter r: Use the SMBus ‘receive byte’ command for detection; this parameter is not recommended.

Parameter i2cbus: Specify the number of the i2c bus

Parameters first, last: Address range to scan

Input ./i2cdetect -l to scan how many i2c devices are mounted on the board, as shown below, there are 3 i2c devices

Linux Tools i2c-tool and memtool32 for Register Operations

Input ./i2cdetect -y 0, which indicates that there are two devices mounted under /dev/i2c-0, with addresses 0x49 and 0x51 respectively

Linux Tools i2c-tool and memtool32 for Register Operations

3. i2cget command: Read the value of a specific register; the register address can only be 8-bit.

Input command ./i2cget to display the syntax operation instructions for the i2cget command

Linux Tools i2c-tool and memtool32 for Register Operations

Parameter Description:

Parameter f: Force access to the device.

Parameter y: Disable interactive mode; when using this parameter, no warning messages will be prompted.

Parameter i2cbus: Specify the number of the i2c bus

Parameter chip-address: The i2c device address

Parameter data-address: The address of the device’s register

Parameter mode: Specify the size to read, which can be b, w, s, or i, corresponding to byte, word, SMBus block, I2C block.

Input ./i2cget -f -y 0 0x49 0x00, which indicates reading the value of the 0x00 register at the device address 0x49 on the /dev/i2c-0 bus

Linux Tools i2c-tool and memtool32 for Register Operations

4. i2cset command: Write a value to a specific register; the register address can only be 8-bit

Input ./i2cset -f -y 0 0x49 0x00, which indicates writing the value 0x00 to the 0x00 register at the device address 0x49 on the /dev/i2c-0 bus

Linux Tools i2c-tool and memtool32 for Register Operations

5. i2ctransfer command: Can read and write multi-byte register addresses. i2ctransfer can replace i2cset and i2cget

Input command ./i2ctransfer to display the syntax operation instructions for the i2ctransfer command

Linux Tools i2c-tool and memtool32 for Register Operations

Parameter Description:

Parameter f: Force access to the device.

Parameter y: Disable interactive mode;

Parameter v:

Parameter a: Allow addresses 0x00-0x07 and 0x78-0x7f

Parameter i2cbus: Specify the number of the i2c bus

……

6. Using the memtool tool to directly manipulate register values through addresses:

Input ./memtool32 to display the syntax operation instructions for the memtool32 command

Linux Tools i2c-tool and memtool32 for Register Operations

Input ./memtool32 -32 0x43c00020 1, which indicates reading the value of the register address 0x20 under the device base address 0x43c00000.

(At this time, the value read is from back to front; for example, if the value read is 03020100, then the value of 0x20 is 0x00, the value of 0x21 is 0x01, and so on…)

Linux Tools i2c-tool and memtool32 for Register Operations

Input ./memtool32 -32 0x43c00020=0x00, which indicates writing the value 0x00 to the register address 0x20 under the device base address 0x43c00000. The value written is a 32-bit data; if you want to write a value of a different data width, just modify it accordingly in front.

Linux Tools i2c-tool and memtool32 for Register Operations

Linux Tools i2c-tool and memtool32 for Register Operations

For course inquiries, add: HCIE666CCIE

↑ Or scan the QR code above ↑

What technical points and content would you like to see?

You can leave a message below to let us know!

Leave a Comment