Saturday 23 November 2013

Using the second I2C bus on Raspberry PI

Hello again!
Today I am really excited because I am a big step closer to finishing the hardware part of the project.
But since I use this blog as a form of documentation, on this post I will concentrate on how the second i2c port of the raspberry PI can be used.

Just for the record, I need a second I2C bus because I want to use two compasses for which I cannot change the I2C ID.

Version 1 of the Raspberry Pi Model B had I2C#0 coming out on the GPIO. The SoC has an additional I2C bus that on Raspberry Version 1 was very hard to bring out.

Version 2 of Raspberry Model B and all Model As have I2C#1 connected on GPIO, and the I2C#0 accessible through the connector P5:
(this is a Model A but is the same for Model B too)
The P5 connector pins are actually missing, so the easiest way of take advantage of the I2C#0 is by adding the a 2x4 block of connector pins:
Although now the connector for I2C is available, it is still unusable because there are a couple of pull-up resistors missing.
One can find what is missing by comparing the schematics for I2C#0 and I2C#1 which can be found here:
Connector GPIO P1 has these resistors:
 which are missing from connector GPIO P5:
So we add them, that is, add 1.8K pullup resistors to pins 3 & 4 of connector P5 (the other side of the resistors should be connected to 3.3V). The easiest way for me to do that was using an external miniature PCB, someone might want to do a permanent modification to the RaspberryPI.
Now the hardware bit is ready, but we still can't use the I2C#0.
This is because the I2C functionality is an alternative to the default mode of the P5 pins, so somehow the SoC has to be told to activate I2C on these pins.
There are quite a few ways to do that, for various reasons I decided to use the HiPi Library, as described here.  
After installing the HiPi package (using the manual process described here), the I2C#0 can be activated by issuing the command:
hipi-i2c e 0 1
At this point we are ready to start using the second I2C bus on the Raspberry PI!

REFERENCES:
Raspberry PI Version 1 Schematics
Raspberry PI Version 2 Schematics
HiPi Perl Modules for Raspberry PI





No comments:

Post a Comment