Well I2C was the obvious next candidate for a driver. Another active Raspberry Pi coder, Frank Buss, wrote some nice driver code but sadly didn’t integrate it with Linux’s own i2c driver framework. It worked, though not as I wanted it. He did the hard work. I then took his code (with his permission of course) and wrote a Linux i2c driver for it today. It works! You can grab it at:
This tree contains the latest SPI and I2C code. Here’s how to use it:
- Build a kernel from my tree with
- Boot your new kernel. The module should automatically load.
- Bind some I2C devices to the bus (see below).
When your kernel boots, you should see something like this in dmesg:
[ 61.322300] i2c i2c-0: adapter [bcm2708_i2c.0] registered [ 61.329530] bcm2708_i2c bcm2708_i2c.0: BSC0 Controller at 0x20205000 (irq 79) [ 61.341100] i2c i2c-1: adapter [bcm2708_i2c.1] registered [ 61.347581] bcm2708_i2c bcm2708_i2c.1: BSC1 Controller at 0x20804000 (irq 79)
At this point you can
modprobe i2c-dev to play with
/dev/i2c-0 from userspace (look for
i2c-tools for example), or use some kernel drivers.
I have a TI TMP102 attached to my Raspberry Pi, so I used it like this:
raspberrypi bootc # echo tmp102 0x48 > /sys/class/i2c-adapter/i2c-0/new_device raspberrypi bootc # sensors tmp102-i2c-0-48 Adapter: bcm2708_i2c.0 temp1: +21.6°C (high = +160.0°C, hyst = +150.0°C)
And again with a Maxim DS1307 RTC:
raspberrypi bootc # echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-0/new_device raspberrypi bootc # hwclock -r Sat 19 May 2012 23:15:24 BST -0.525475 seconds
You may have noticed the driver registers two I2C busses. One is the the BSC0 bus that has pins on the GPIO connector, the other is BSC1 which has pins on the camera connector.