User avatar
w4mmp
Posts: 43
Joined: Thu Mar 26, 2015 3:11 pm

RPi 4 - Using alternate I2C

Tue Jan 21, 2020 4:47 pm

Hello,

Background. We are working on a project that incorporates a Audio-Injector hat. Among the pins it uses are the primary I2C pins. However we also have other I2C devices we need to access. So the question is, may the RPi 4 have two active I2C buses? We were hoping to use the pins that may be used for I2C - SDA/SCL-6 or SDA/SCL -4. If this is the case, how are these pins configured to use the I2C function verses the default GPIO function.

Regards,
Ron
73,
Ron / W4MMP

dgordon42
Posts: 777
Joined: Tue Aug 13, 2013 6:55 pm
Location: Dublin, Ireland

Re: RPi 4 - Using alternate I2C

Wed Jan 22, 2020 1:54 pm

You can run several I2c buses at the same time, details on how to configure the buses and GPIO pins are in the file '/boot/overlays/README' on your Pi.

Note that only GPIOs 2 & 3 (physical pins 3 & 5) have pull up resistors fitted on the Pi itself. To use any other pins you will need to have pull up resistors to the Pi's 3.3V line.

Hope this helps,
Dave.

User avatar
w4mmp
Posts: 43
Joined: Thu Mar 26, 2015 3:11 pm

Re: RPi 4 - Using alternate I2C

Wed Jan 22, 2020 4:22 pm

Hi Dave,
Thanks so much! Yes, adding dtoverlay=i2c5 to config.txt activated the i2c 5 buss. I2cdetect finds and reports the connected devices. Now to find an I2C library that handles buses other than the primary buss. I normally use an easy to use and well documented library offered by http://www.airspayce.com/mikem/bcm2835/ but I have my doubts I can use it without source code modification.

Thanks again,
Ron
73,
Ron / W4MMP

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7909
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: RPi 4 - Using alternate I2C

Wed Jan 22, 2020 4:55 pm

w4mmp wrote:
Wed Jan 22, 2020 4:22 pm
Thanks so much! Yes, adding dtoverlay=i2c5 to config.txt activated the i2c 5 buss. I2cdetect finds and reports the connected devices. Now to find an I2C library that handles buses other than the primary buss. I normally use an easy to use and well documented library offered by http://www.airspayce.com/mikem/bcm2835/ but I have my doubts I can use it without source code modification.
I really can not recommend using a userspace library that tries mapping the I2C registers directly and poking them. There is a kernel driver for the I2C peripheral for a reason - it provides a central place for all arbitration. If you use bcm2835 or similar from two applications then they will interfere with each other in very bad ways.

Having a quick look on the Google Group for that library, https://groups.google.com/forum/#!topic ... KqolkcDwKc confirms exactly the same thing.

Memory says pigpio does use the kernel driver for I2C access so is probably a better bet. I'd expect i2cOpen to take a bus number of 5 fairly happily.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

User avatar
joan
Posts: 14688
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: RPi 4 - Using alternate I2C

Wed Jan 22, 2020 6:02 pm

pigpio does use the standard Linux driver for I2C. However pigpio also uses at least one of the PWM/PCM peripherals so may not be a good choice for an audio application.

You don't have to use the bcm2835 library functions for I2C. There is nothing to stop you using the Linux I2C driver from a C program linked with the bcm2835 library.

User avatar
w4mmp
Posts: 43
Joined: Thu Mar 26, 2015 3:11 pm

Re: RPi 4 - Using alternate I2C

Wed Jan 22, 2020 6:26 pm

Hi,
I will give pigpio a go first and see what happens with the audio hat. The hat uses dtoverlay=audioinjector-wm8731-audio.

There might be just a touch of confusion (due to my confusion).
We will not be accessing the audio hat directly. The application accesses the hat via Port Audio using the ALSA API. Again the reason for the need to access a second I2C buss for access to other I2C devices in our design.

I can see I have a bit to learn. I have used I2C extensively in other projects but not on the RPi. I'm sure I can pull all this together after my learning curve.
73,
Ron / W4MMP

Return to “Interfacing (DSI, CSI, I2C, etc.)”