ilaam
Posts: 30
Joined: Fri Mar 28, 2014 9:20 am

Can RPi have many I2C addresses?

Mon Mar 31, 2014 8:52 am

Hi,
I am trying to use RPi to emulate a set of sensors ( a set of slaves). So I need to make it run in I2C slave mode and it should have more than one I2C address (an address per sensor). I wont be using any sensor, it is the RPi that commuicate with a master shipset and responds every time as a different sensor.
To summarize, is it possible to assign many I2C addresses to the RPi ?
Thank you :)

User avatar
FTrevorGowen
Forum Moderator
Forum Moderator
Posts: 5621
Joined: Mon Mar 04, 2013 6:12 pm
Location: Bristol, U.K.
Contact: Website

Re: Can RPi have many I2C addresses?

Mon Mar 31, 2014 9:02 am

ilaam wrote:Hi,
I am trying to use RPi to emulate a set of sensors ( a set of slaves). So I need to make it run in I2C slave mode and it should have more than one I2C address (an address per sensor). I wont be using any sensor, it is the RPi that commuicate with a master shipset and responds every time as a different sensor.
To summarize, is it possible to assign many I2C addresses to the RPi ?
Thank you :)
AFAIK, No, because the RPi always works as an I2C master ie., IIRC, cannot** be used as an I2C slave.
Trev.
** except, perhaps, by writing your own I2C "driver" and not using the supplied kernel modules.
Still running Raspbian Jessie or Stretch on some older Pi's (an A, B1, 2xB2, B+, P2B, 3xP0, P0W, 2xP3A+, P3B+, P3B, B+, and a A+) but Buster on the P4B's. See: https://www.cpmspectrepi.uk/raspberry_pi/raspiidx.htm

User avatar
Richard-TX
Posts: 1549
Joined: Tue May 28, 2013 3:24 pm
Location: North Texas

Re: Can RPi have many I2C addresses?

Mon Mar 31, 2014 9:58 am

By leveraging I2C bus expanders/switches, the number of sensors/devices/ports the Rpi can address is more than adequate for almost any need. I recently came up with a realistic count assuming some 8x i2c switches and mpc23017 port expanders. The # of ports/sensors were up in the 2,000 + range. You might think about reversing your application's the I2C data flow.

You might try thinking about a tcp/i2c gateway. Ethernet is at least 100 times faster than I2c and possibly 1000 times faster. Performance? Done right, you wouldn't know the difference if the i2c bus was local or remote.

If you use multicast in your gateway software, then addressing multiple Rpis on a lan becomes trivial as you don't need to know the ip address of every remote Rpi in advance.
Richard
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:
http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-09-27/2013-09-25-wheezy-raspbian.zip

hampi
Posts: 223
Joined: Fri May 31, 2013 11:29 am
Contact: Website

Re: Can RPi have many I2C addresses?

Mon Mar 31, 2014 5:20 pm

ilaam wrote:To summarize, is it possible to assign many I2C addresses to the RPi ?
Easiest way is to use PiPIC, but you need to add more assembly code lines to it to match different I2C addresses. Now it matches only to one address, which is what you normally need. The code is called pic12si2c.asm and you need to look at lines 448 - 458 in the present version.

Return to “Beginners”