Change masters with i2c?

Is it possible to switch an Arduino from master to slave while running?

An Arduinbo can act as I2C slave, master or both - all at the same time (sequentially that is). This just depends on the Wire library functions you call. Bus arbitration is handled by the AtMega microcontroller. You can however not send data to yourself.

The downside to using multiple masters on a bus is that writing as a master may be delayed due to bus contention (time to write is no longer predictable).

Both? How do you do that?

To use Arduino as a slave:

  • Call begin with an address
  • Register a handler for onRecieve/onRequest or both

To use Arduino as a master:

  • Call begin (with or without an address)
  • Call requestFrom (read operation)
  • Call beginTransmission, send, endTransmission (write operation)

To use Arduino as a master and slave

  • Do both of above (call begin one time only and with an address)

I had no idea you could do both at the same time. That should simplify things a lot. I'm looking forward to playing with that.

Thanks, Norm