Configure any GPIO to work as I2C

General programming chat and advice for beginners

8 posts
by azelez » Wed Feb 13, 2013 1:58 pm
Intro:
--------
I am using the Raspberry PI for one of my projects.

In this project I need two different I2C interfaces to run simultaneously. I know how to set the GPIO-0 and GPIO-1 to work as I2C (There is tutorials everywhere).
Also the RPi Low-level peripherialsit says that any GPIO can work as I2C.

Question:
-------------
How do I configure other GPIO's (Others than GPIO-0 and GPIO-1) to work as I2C also? How can I have to different I2C interfaces in parallel. (I know I need to add pull-up resistors, but I don't know how to setup the linux shell or and how to program it in C). Can someone explain me in easy steps how this is done?

Thanks,
Adrian.
Posts: 3
Joined: Wed Feb 13, 2013 1:54 pm
by rickseiden » Wed Feb 13, 2013 8:05 pm
I thought you could just attach the other devices to the same i2c pins via a breadboard, and it would recognize all the i2c devices by address? Why do you need to run multiple i2c interfaces? (Maybe because you have multiple devices with the same address?)
There are 10 types of people in this world. Those that understand binary, and those that don't.
Posts: 398
Joined: Thu Aug 02, 2012 12:21 pm
Location: Buffalo, NY, USA
by joan » Wed Feb 13, 2013 8:09 pm
rickseiden wrote:I thought you could just attach the other devices to the same i2c pins...

That's what I do. Common sda, scl, ground, for each i2c device.
User avatar
Posts: 6377
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK
by techpaul » Thu Feb 14, 2013 2:16 am
azelez wrote:...Also the RPi Low-level peripherialsit says that any GPIO can work as I2C.

Care to give the exact section you are referring to for that statement?
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/
Posts: 1510
Joined: Sat Jul 14, 2012 6:40 pm
Location: Reading, UK
by azelez » Thu Feb 14, 2013 7:43 am
techpaul wrote:
azelez wrote:...Also the RPi Low-level peripherialsit says that any GPIO can work as I2C.

Care to give the exact section you are referring to for that statement?


Hi,
I read in the following link http://elinux.org/Rpi_Low-level_peripherals, there is a line there as follows:
"All the GPIO pins can be reconfigured to provide alternate functions, SPI, PWM, I²C and so"
this is found under section: "General Purpose Input/Output (GPIO)"
Maybe I did not understand correctly the explanation, but that is what is written. Am I wrong?
Thanks for the help,
Adrian.
Posts: 3
Joined: Wed Feb 13, 2013 1:54 pm
by azelez » Thu Feb 14, 2013 7:47 am
joan wrote:
rickseiden wrote:I thought you could just attach the other devices to the same i2c pins...

That's what I do. Common sda, scl, ground, for each i2c device.


Hi,
This is what I am doing, I am using the I2C for sensors and for controller also, I have around 6 sensors currently and 2 controllers.
The sensors some time get stuck, and then all the I2C is stuck, I want in those cases to be able to still send command to the controllers.
I want another I2C interface to make my project less prompt to problems.
Adrian.
Posts: 3
Joined: Wed Feb 13, 2013 1:54 pm
by bgreat » Thu Feb 14, 2013 1:12 pm
Each GPIO pin can be programmed for a specific subset of the available alternate functions. You can refer to BCM2835 ARM Peripherals - Raspberry Pi for the detailed specifics.

Enjoy!
Bill
User avatar
Posts: 235
Joined: Mon Jan 23, 2012 2:09 pm
by techpaul » Thu Feb 14, 2013 3:08 pm
azelez wrote:
techpaul wrote:
azelez wrote:...Also the RPi Low-level peripherialsit says that any GPIO can work as I2C.

Care to give the exact section you are referring to for that statement?


Hi,
I read in the following link http://elinux.org/Rpi_Low-level_peripherals, there is a line there as follows:
"All the GPIO pins can be reconfigured to provide alternate functions, SPI, PWM, I²C and so"
this is found under section: "General Purpose Input/Output (GPIO)"
Maybe I did not understand correctly the explanation, but that is what is written. Am I wrong?
Thanks for the help,
Adrian.

Yes they can all be used in many ways, SOME can be I2C, which is a bus and EACH can easly support about 120 devices as long as they are on separate addresses, you are only limited by the I2C addressing range each device supports.

See other comment(s) about that
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/
Posts: 1510
Joined: Sat Jul 14, 2012 6:40 pm
Location: Reading, UK