How to use I2C
This page shows the basic usage of the I2C bus.
the following examples are using an external GPIO expander.
List i2c devices on a specific bus
i2cdetect is used to identify available I2C devices on a given I2C bus. An overview of the available I2C busses can be achieved by using i2cdetect -l
test@test-desktop:~$ i2cdetect -l
i2c-3 i2c 3190000.i2c I2C adapter
i2c-1 i2c c240000.i2c I2C adapter
i2c-101 i2c 15210000.nvdisplay I2C adapter
i2c-8 i2c 31e0000.i2c I2C adapter
i2c-6 i2c 31c0000.i2c I2C adapter
i2c-4 i2c Tegra BPMP I2C adapter I2C adapter
i2c-2 i2c 3180000.i2c I2C adapter
i2c-0 i2c 3160000.i2c I2C adapter
i2c-9 i2c i2c-2-mux (chan_id 0) I2C adapter
i2c-10 i2c i2c-2-mux (chan_id 1) I2C adapter
i2c-7 i2c c250000.i2c I2C adapter
i2c-5 i2c 31b0000.i2c I2C adapterSymols:
--: No device found21: There is a device on address 0x21UU: A Linux driver is currently using this device
Syntax: i2cdetect [options] <busNr>
Dump i2c device registers
The ì2cdump operation is good tool to see the content of a given I2C device to get a better overview of the stored data in its registers.
Syntax: i2cdump [options] <busNr> <deviceAddress>
Read register value:
i2cget is used for reading a byte value from a given device I2C register address.
Syntax: i2cget [options] <busNr> <deviceAddress> <register> <address>
Set register value:
i2cset is used for writing a byte value to a given device I2C register address.
Syntax: i2cset [options] <busNr> <deviceAddress> <register> <address> <value>
Last updated
Was this helpful?
