About

This topic covers how to connect I2C device to Carambola. For this tutorial I will use PCF8575 16 bit I/O expander.

Schematics

In order to connect I2C device I will need few passive components. See attached schematics.

There is also power selection jumper (5V or 3.3V) and SPI pin header. Discard these for this subject.

Preparing Carambola

Kernel modules
  I2C support
    kmod-i2c-gpio
Utilities
  i2c-tools package

Testing

Connect to Carambola with fresh firmware and type i2cdetect -y 0. You should see something like:

root@OpenWrt:/# i2cdetect -y 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: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --   

Read data

root@OpenWrt:/# i2cget -y 0 0x20 0x00 w
0xffff  

Write data

root@OpenWrt:/# i2cset -y 0 0x20 0x00 0xff

Issues

These utilities were written to work with I2C memory devices and lack of full I2C support. Biggest issue - it is possible only communicate with devices that have 2 bytes in I2C protocol. Although I2C on hardware level supports up to 7 (I am not exactly sure right now) bytes for both directions.