Go Down

Topic: Arduino emulating multiple I2C slaves (Read 3319 times) previous topic - next topic


Hi, i'm wondering if it's possible to create an I2C proxy, that would on one side listen on multiple I2C addresses (like Wire.begin called for multiple addresses), do some processing on the data, and output them on another side.

Does the I2C protocol allow this?


As long as only a single "chip" (Arduino or other I2C device) answers to any of the 256 I2C bus addresses (byte size) then pretty much anything is possible.

Additional data following the I2C addres could include an operation code (e.g. what to do) followed by additional bytes that further qualify or provide data/parameters to this operation. This would require that you are in a position to define the protocol.

If you plan on emulating an I2C device, there is currently a limit in the I2C library for the Arduino to only respond to a single I2C bus address. As such you would not be able to emulate multi-address chips.

The AtMega hardware however supports an address mask that would allow you to respond to multiple adresses. Using this mask however would require an update/rewrite of the current I2C library.


any of the 256 I2C bus addresses (byte size)

minor correction: it's a 7 bit address, so only 128.  Some of those addresses are reserved, so the actual limit is something like 117.

Conceptually there's nothing wrong with the idea of the Arduino responding to multiple slave addresses, but it's not exactly "normal" operation, so don't expect much help from the Arduino libraries.



The I2C bus address is made up of two parts, a 7 bit device address plus a read/write bit forming an 8-bit bus address. The Phillips I2C specification reserves 16 (two groups of 8) 7-bit device addresses. Fast mode (400kHz) also defines a 10-bit (+R/W) addressing mode which is backwards compatible with 100kHz chips.

The AtMega (48/88/168/328) does not impose any restrictions on use of the 16 reserved addresses. As such - this is as the jargon goes - left for the user to implement.

Making a slave respond to multiple addresses only requires updating a single 8-bit mask register (TWAMR). Using this for practical purposes however would require a modification of the I2C library so that the address responded to is made available.


I am really interesting in doing something similar to this.  
I want to use the ardiuno to read multiple slave commands to read what is coming to 6 displays.

Currently I can read each display separately with begin(address) commands in the setup function, but only in separate sketches.

I tried to see if I could read the register TWAMR , but it just returns 0.

Is there possibly another work around?


If after "begin(address)" you set "TWAR = 0xfe", the Arduino will respond as a slave to any I2C address (irrespective of address specified in begin). There is no support in the Wire library however for letting you know what address was actually used. It will be somewhat like a telephone exchange with multilpe inbound numbers. The phone is ringing and you pick up to answer, but will not know the number the other party dialed to reach you.

Go Up