How to use I2C

From IGEP - ISEE Wiki

Revision as of 19:10, 16 January 2012 by Pau (talk | contribs)

Jump to: navigation, search

Overview

This How-To is meant to be a starting point for people to learn use I2C for IGEP v2 devices as quickly and easily as possible. In this how-to, we use a program that reads and decodes EDID information from display. This program was tested in Linaro Headless with Kernel 2.6.35.y and Poky Linux distribution.

NOTE: This program is a beta version, it decodes EDID following E-EDID Standard Release A-1 from VESA using i2c-dev driver. There are some functionalities that are not implemented (see code comments) and other new ones that appear in other revisions. Besides, this program only parses the first EDID 128 bytes block. But this code is only a sample to learnt use I2C.

More information about EDID.

Feedback and Contributing

At any point, if you see a mistake you can contribute to this How-To.

Check I2C Devices

In this How-to, I used pre-compiled modules, because: it's quick and it works. All versions of Linux are supported, as long as I2C support is included in the kernel.

To make sure that I2C driver works well, follow the next steps (tested in Linaro Headless), install i2c-tools:

sudo apt-get install  i2c-tools

Parse I2C busses:

i2cdetect -l

The result will be similar at that:

i2c-1	i2c       	OMAP I2C adapter                	I2C adapter
i2c-3	i2c       	OMAP I2C adapter                	I2C adapter

It's important than i2c-3 was enabled, because it connects to DVI-D by default.

Compile and Run

Download (upload source code) and extract it.

There are some things that is interesting learn, before compiling the program. Open (main program) and seek next lines:

//1==enabled 0==disable
#define FORCE 1

//Address DVI Standard: 0x50
#define ADDRESS 0x50

Constant FORCE is defined to allow this program access to I2c, although other programs use it at the same time. It can be dangerous in writing operations but in this case, read operations, have sense use it.

Constant ADDRESS is defined to acces in specific I2C address. In DVI devices, 0x50 is default address, that means that other peripherals can be connected to same bus.

See the code below:

for (i=0;i<=255;i++)
{
     edidint[i]=i2c_smbus_read_byte_data(fd,i);
     if (edidint[i]<0)
     {
          printf("Error:read failed\n");
          return -1;
     }
} 

The program uses i2c_smbus_read_byte_data function to get information from display, "i" variable is the EEPROM address. EEPROM (Slave) reads address from Omap (Master), after, EEPROM sends the address value to Omap (Master).

More information about I2C.

Compile program using your Cross Compiler, i used arm-linux-gnueabi-:

arm-linux-gnueabi-gcc parse-edid-beta2.c -o parse-edid-beta2

Run program as root. Pass the i2c number that you want to parse:

parse-edid-beta2 -d 2

Results

Under construction