Friday, October 22, 2010

enabling I2C on expansion header

I'd like to communicate with an I2C digital potentiometer (Maxim DS1803), using the I2C bus on the expansion header (pins 23 and 24). However, the only i2c busses that show up are 1 and 3, while the expansion header bus should be 2:

$ i2cdetect -l
i2c-1 unknown OMAP I2C adapter N/A
i2c-3 unknown OMAP I2C adapter N/A


I made the following change to the kernel to enable i2c-2:

1) in .config, set CONFIG_OMAP_MUX=y

2) in arch/arm/mach-omap2/board-omap3beagle.c, make these changes:

a) in omap3_beagle_i2c_init(), add:
omap_register_i2c_bus(2, 400, NULL, 0);

b) in board_mux[], add:
static struct omap_board_mux board_mux[] __initdata = {
OMAP3_MUX(I2C2_SCL, OMAP_MUX_MODE0),
OMAP3_MUX(I2C2_SDA, OMAP_MUX_MODE0),
{ .reg_offset = OMAP_MUX_TERMINATOR },
};

Now rebuild the kernel, copy it to the SD card, and reboot; and now we can see the bus:

$ i2cdetect -l
i2c-1 unknown OMAP I2C adapter N/A
i2c-3 unknown OMAP I2C adapter N/A
i2c-2 unknown OMAP I2C adapter N/A

$ sudo i2cdetect -F 2
Functionalities implemented by /dev/i2c-2:
I2C yes
SMBus Quick Command no
SMBus Send Byte yes
SMBus Receive Byte yes
SMBus Write Byte yes
SMBus Read Byte yes
SMBus Write Word yes
SMBus Read Word yes
SMBus Process Call yes
SMBus Block Write yes
SMBus Block Read no
SMBus Block Process Call no
SMBus PEC yes
I2C Block Write yes
I2C Block Read yes

And nowwe should be able to scan the bus - with the DS1803 on the bus we see:

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

2 comments:

  1. Hi Mike,
    Thanks for your blog. I am using BeagleBoard Rev C3. I too need to use the i2c-2 channel. I am using ubuntu11.10 in BeagleBoard. I understood how to enable the i2c-2 channel from your blog. But could you please let me know the step you followed to rebuild the kernel?

    Regards
    Muhamed

    ReplyDelete
  2. Hi Muhamed, it's been so long since I've worked on this platform I honestly can't remember. But it should be a simple matter of doing a "make uImage"...

    ReplyDelete