Search by Tags

I2C (Linux)

 

Compare with Revision

Subscribe for this article updates

The Apalis standard provides 3 I2C busses on the MXM pins 201/203, 205/207 and 209/211. The Colibri standard provides one I2C bus on the SODIMM pins 194/196 and for the modules providing an Extension Connector an additional one on its pins 15/16 usually used for the display DDC channel. On top of that most modules use an I2C bus for on-module components like the audio codec, PMIC or touch controller.

Depending on the module type additional I2C busses might be available as alternate functions of other pins given the kernel gets configured accordingly in the device tree or the platform data.

Bus Assignment

Module
(Proposed use)
MXM_209/211
(Generic)
MXM_205/207
(DDC)
MXM_201/203
(CAM)
On-Module
Apalis iMX6 i2c-1 i2c-0 *) i2c-3 i2c-2
Apalis T30 i2c-0 i2c-3 i2c-2 i2c-4

*) uses the GPIO bitbang driver.


Module
(Proposed use)
SODIMM_194/196
(Generic)
Extension Connector 15/16
(DDC)
On-Module
Colibri iMX6 i2c-2 i2c-0 i2c-1
Colibri T20 i2c-0 i2c-1 i2c-4
Colibri T30 i2c-1 i2c-4 i2c-0
Colibri VF i2c-0 N/A N/A

I2C Tools

Most I2C devices are handled by kernel drivers. The device tree or platform data binds the I2C bus to such drivers. From user space one accesses them then through the relevant subsystem rather than having to do low-level I2C access. E.g. for an RTC one would use /dev/rtcX or even a user space program like hwclock.

The I2C Tools package provides tools for low-level access to I2C devices. As follows a few sample use cases:

Check the configured I2C busses

root@colibri-t20:~# ls -l /dev/i2c-*
crw-------    1 root     root       89,   0 Jan  1  2000 /dev/i2c-0
crw-------    1 root     root       89,   1 Jan  1  2000 /dev/i2c-1
crw-------    1 root     root       89,   4 Jan  1  2000 /dev/i2c-4

Detect devices on i2c-0

root@colibri-t20:~# i2cdetect -y -r 0
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: 20 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --

UU denotes a device which is used by a kernel driver and thus is usually not touched. Depending on the I2C device it may not get discovered by i2cdetect.

Dump register content of an I2C device

root@colibri-t20:~# i2cdump -r 0-0xf 0 0x20 b
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-0, address 0x20, mode byte
Probe range limited to 0x00-0x0f.
Continue? [Y/n] y
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f    0123456789abcdef
00: 10 40 00 00 10 80 00 80 88 02 00 23 00 00 03 18    ?@..??.???.#..??

Read a single byte, change its value and verify it with an additional read

root@colibri-t20:~# i2cget 0 0x20 4 b
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will read from device file /dev/i2c-0, chip address 0x20, data address
0x04, using read byte data.
Continue? [Y/n] y
0x10
root@colibri-t20:~# i2cset 0 0x20 4 0x18 b
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will write to device file /dev/i2c-0, chip address 0x20, data address
0x04, data 0x18, mode byte.
Continue? [Y/n] y
root@colibri-t20:~# i2cget 0 0x20 4 b
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will read from device file /dev/i2c-0, chip address 0x20, data address
0x04, using read byte data.
Continue? [Y/n] 
0x18