I2C configuration

From liteSOM Wiki
Jump to: navigation, search

I2C configuration

On i.MX6UL platform we can use up to four independent I2C peripherals:

  • i2c1,
  • i2c2,
  • i2c3,
  • i2c4.

Pinout configuration

Presented below device tree file snippet will configure pad:

  • CSI_MCLK/USDHC2_CD_B/RAWNAND_CE2_B/I2C1_SDA/EIM_CS0_B/GPIO4_IO17/SNVS_HP_VIO_5_CTL/UART6_TX (pad 153 on liteSOM) as SDA signal,
  • CSI_PIXCLK/USDHC2_WP/RAWNAND_CE3_B/I2C1_SCL/EIM_OE/GPIO4_IO18/SNVS_HP_VIO_5/UART6_RX (pad 155 on liteSOM) as SCL signal,
&iomuxc {
	pinctrl_i2c1: i2c1grp {
		fsl,pins = <
			MX6UL_PAD_CSI_MCLK__I2C1_SDA   0x4001b8b0
			MX6UL_PAD_CSI_PIXCLK__I2C1_SCL 0x4001b8b0
		>;
	};
};

I2C periphery configuration

Presented below device tree file snippet will configure I2C1 periphery to:

  • use I2C1 bus with 100kHz clock,
  • use I2C1 periphery with SDA/SCL pins defined above.
&i2c1 {
	clock-frequency = <100000>;
	pinctrl-names = "default";
	pinctrl-0 = <&pinctrl_i2c1>;
	status = "okay";
}

Example

Complete device tree example with configured I2C periphery you can find here.

Bindings documentation

For more details and available configuration options please read following documentation:

How to test I2C

You can various I2C* tools installed on the target.

i2cdetect

i2cdetect can be used to detect all IC connected to the I2C bus.

Example:

# i2cdetect -y -r 0
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- 19 -- -- 1c -- -- -- 
20: -- -- -- -- -- -- -- -- -- 29 -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- 76 -- 

In the example above on I2C-0 bus following devices has been detected:

  • I2C address: 0x19,
  • I2C address: 0x1c,
  • I2C address: 0x29,
  • I2C address: 0x76.

i2cget

i2cget can be used to read data from any I2C slave device.

Example:

# i2cget -y 0 0x19 0x00 b
0x00

Command like presented above will request to read from I2C slave device with address 0x19 connected to the I2C-0 bus one byte from 0x00 register.

i2cset

i2cset can be used to write data to any I2C slave device.

Example:

# i2cset -y 0 0x19 0x00 0x00

Command like presented above will request to write to I2C slave device with address 0x19 connected to the I2C-0 bus one byte 0x00 to the register 0x00.