Tuesday, May 1, 2012

I2C Driver for the Raspberry Pi

I'm currently working on making a post on my blog writing a driver for the I2C buss controller(s) on the BCM2835 SoC that powers the Raspberry Pi.  In a previous post, I mentioned the RoboCutter lawn robot my son and I are (sometimes) working on.  I want it to have inclinometer, accelerometer and magnetic compass inputs and the only affordable, module level products I've found and like so far speak I2C.  As I also said in a previous post, the R-Pi should be great as a high level controller for Mr. RoboCutter, but, R-Pi's SoC brain doesn't have a Linux driver for I2C at this point (that I know of), so I'm digging in to try to create one.

So far I've:
  • Set up a cross-compiler toolchain to compile code for the Pi on x86 boxes I have on hand.
  • Got the BCM2835 peripheral datasheet at ready reference
  • Started coding a driver by examining existing Linux I2C drivers and using parts of a couple of them as templates.  Having and having read and used the "Linux Device Drivers" book should help ;)
  • Found two or three people who already have a Raspberry Pi who are willing and able to test driver code.
Currently I've had a couple of restarts on the coding effort and am currently suffering a "single Dad" episode while my wife is out of the country for a couple of weeks.  Still making some progress and I'm really looking forward to getting my own Rubus-3.14159265 *and* getting it talking to some cool sensors!


  1. sounds good. I have a Raspberry Pi and I2C slave hardware, so I could test it. Do you have anything I can compile?

  2. BTW: maybe it is a good idea to discuss the development of the I2C driver here, looks like other people have started with it, too: http://www.raspberrypi.org/forum/projects-and-collaboration-general/linux-device-drivers-for-rapberry-pi-on-board-io/

  3. How is it going? I'd like to have a driver, otherwise I will develop my own and this could take a very long time because I have never developed a Linux driver before :D

    1. Slowly, or in fits and starts is how its going. I'm still learning about platform drivers and I2C buss drivers in that context in the bits of time that I can allocate to it. My wife got back from abroad, but now its my turn to head out of the country on business, for a week this time. I plan to work on it in the hotel in the evenings... I often have more time on the road than at home ;)

      That said, I will not be offended at all if someone else who is more agile, has more time or whatever, can make a working driver before I can. It's a learning experience for me and that's always good. If it can be a learning experience for you or anyone else who wants to give it a shot, go for it. The first one to the finish line makes us all winners :)

  4. I2C and SPI is working: http://www.bootc.net/archives/2012/05/19/i2c-and-the-raspberry-pi/ A pre-compiled kernel, with 1-wire as a goodie, is available here: http://www.raspberrypi.org/phpBB3/viewtopic.php?p=86172#p86172