2

Is it possible to use wire.h on an Arduino Uno to act as a slave for more than one address? For example I'd like it to emulate two different devices, one at I2C address 23 and the other at address 57.

I'm either looking for a way to do this directly, or to run multiple instances (each would need a different onReceive handler).

2
  • Why do you want to? That's like saying "I have a house in New York, and another in London. When someone sends a letter to the London house I want it to arrive in the New York house." That's not how addresses work.
    – Nick Gammon
    Commented Dec 7, 2016 at 8:50
  • Now you described, how my e-mails works :) Anyway I would like to do the same with i2C, as I am planning to have one master and a lot of slave devices (implemented by Ard's) and want to start with one dummy to emulate commanding all of them, then later, as I would implement the bodies and start suffering from space, pins and speed, I would transfer some devices to another HW. Then, if I improve and shorten my code I would like to move back.So having more I2C addresses on the same Arduino (and access to different would run different code/codepath) make perfect sense for me. Bad luck, I cannot.
    – gilhad
    Commented Feb 23, 2017 at 22:55

1 Answer 1

2

Is it possible to use wire.h on an Arduino Uno to act as a slave for more than one address?

The quick answer is: No!

The ATmega328 2-Wire Serial Interface has a special register for the address match in slave mode. This only allows a single address to be matched.

22.5.4 Address Match Unit

The Address Match unit checks if received address bytes match the seven-bit address in the TWI Address Register (TWAR). If the TWI General Call Recognition Enable (TWGCE) bit in the TWAR is written to one, all incoming address bits will also be compared against the General Call address. Upon an address match, the Control Unit is informed, allowing correct action to be taken. The TWI may or may not acknowledge its address, depending on settings in the TWCR. The Address Match unit is able to compare addresses even when the AVR MCU is in sleep mode, enabling the MCU to wake up if addressed by a Master. Reference, pp. 213

On an ATtiny with USI it is actually possible to implement multiple address matching as this is controlled by software.

Last, a pure software approach could be used, i.e. implement the I2C protocol with external interrupt pin and fast pin access. See Amtel Application Note AVR154. The code for this app-note can be found on github. This could be modified to allow multiple slave addresses.

Cheers!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.