hendrixjl
Posts: 50
Joined: Sun Nov 04, 2012 9:22 pm
Location: Huntsville, Alabama, USA

Setting alternate function for GPIO pins

Sun Feb 03, 2013 2:26 am

I understand that GPIO 28 and 29 (on P5) have ALT0 configuration of i2c sda0 and scl0 (rev 2 boards). How - under the raspbian linux with the GPIO configuration - can I select the ALT0 function for these two pins?

hendrixjl
Posts: 50
Joined: Sun Nov 04, 2012 9:22 pm
Location: Huntsville, Alabama, USA

Re: Setting alternate function for GPIO pins

Sun Feb 03, 2013 2:58 am

To be more clear.... I would like to be able to use the i2c libraries under linux. For instance, I would like to do
i2cdetect -y 0
and detect it.

User avatar
bgreat
Posts: 235
Joined: Mon Jan 23, 2012 2:09 pm

Re: Setting alternate function for GPIO pins

Sun Feb 03, 2013 5:53 am

You need to remove the I2C interface from the driver module blacklist, then reboot your Raspberry Pi.

Edit /etc/modprobe.d/raspi-blacklsit.conf:

Code: Select all

# blacklist spi and i2c by default (many users don't need them)

blacklist spi-bcm2708
blacklist i2c-bcm2708
Add a '#' as the first character on the "blacklist i2c-bcm2708" to remove the i2c from the blacklist and enable loading of the i2c driver.

New file:

Code: Select all

# blacklist spi and i2c by default (many users don't need them)

blacklist spi-bcm2708
#blacklist i2c-bcm2708
Reboot, the i2c module will be loaded, and you will be able to use the i2c functionality.

Enjoy!
Bill

User avatar
[email protected]
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: Setting alternate function for GPIO pins

Sun Feb 03, 2013 10:24 am

hendrixjl wrote:To be more clear.... I would like to be able to use the i2c libraries under linux. For instance, I would like to do
i2cdetect -y 0
and detect it.
You don't need to do anything - I2C is fully supported "as is", and the existing pins (GPIO 0 & 1 on a Rev 1, 2 & 3 on a Rev 2) already have 1.8KΩ pull-ups on the Pi board explicitly for I2C.

The easist way (IMO) to get going is to fetch & install my wiringPi libraries and 'gpio' utility, then

gpio load i2c

then you can:

i2cdeect -y 0 # Pi Rev 1
or
i2cdetect -y 1 #Pi Rev 2

e.g.:

Code: Select all

[email protected] ~ $ gpio load i2c
[email protected] ~ $ i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: 20 21 -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                         
(This is a Pi with 2 x mcp23017's installed)

If you don't want to use my gpio command, then either put the 2 modules in /etc/modules (and/or remove them from the blacklist), or sudo modprobe them when you need to. A handy side-effect of my gpio command is that it will change the ownership of the I2C devices in /dev/ so you can use them from your programs without being root.

-Gordon
--
Gordons projects: https://projects.drogon.net/

hendrixjl
Posts: 50
Joined: Sun Nov 04, 2012 9:22 pm
Location: Huntsville, Alabama, USA

Re: Setting alternate function for GPIO pins

Sun Feb 03, 2013 1:29 pm

Thanks for the replies, but I'm asking about bus 0 on connector P5 (rev 2 board) pins 2 and 3. I wanted to open up another i2c bus.

User avatar
[email protected]
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: Setting alternate function for GPIO pins

Sun Feb 03, 2013 1:38 pm

hendrixjl wrote:Thanks for the replies, but I'm asking about bus 0 on connector P5 (rev 2 board) pins 2 and 3. I wanted to open up another i2c bus.
OK.

You'll need to write a program to do it, or hack it into wiringPi (or one of the other libriaries) to do it for you. If you set them to ALT0 function, then you'll should have i2c device 0 (as well as i2c 1). If you want to hack it into wiringPi, then have a look in wiringPi.c, in the pinMode() function. I don't know if you have to take pins 0 & 1 out of ALT0 mode though - you may have to experiment...

However AIUI, the foundation have reserved I2C bus 0 for the camera on Rev 2 boards (or was it the display?), so if you use it, you probably can't use that interface at the same time...

-Gordon
--
Gordons projects: https://projects.drogon.net/

Ragu3l
Posts: 17
Joined: Thu Feb 07, 2013 9:29 pm

Re: Setting alternate function for GPIO pins

Tue Feb 12, 2013 10:55 pm

Hi hendrixjl

Did you get this working?
I too am interesting in using i2c-0 and have not yet been able to get it working

Cheers

hendrixjl
Posts: 50
Joined: Sun Nov 04, 2012 9:22 pm
Location: Huntsville, Alabama, USA

Re: Setting alternate function for GPIO pins

Wed Feb 13, 2013 12:11 am

No, I never got it working.

Return to “C/C++”