I have one master and three slave devices and i need to send data to all the slaves at a time.is that possible if so how to check which slave has recieved the data first
2 Answers 2
The I2C protocol implements the general call/broadcast address for this purpose. If you send data to the address 0
(zero), this is interpreted as general call by all slaves. All slaves, that can receive data, will respond by pulling the SDA line to low in the acknowledgement cycle (the timing is set up by the masters clock so all slaves will do it at the same time, thus no problem with garbled data). Note, that you cannot read from the general call address, since then all slaves might transmit at the same time. As the Atmega328P
s (the microcontroller on the Arduino Uno) datasheet states:
Note that transmitting the general call address followed by a Read bit is meaningless, as this would cause contention if several slaves started transmitting different data.
I think the Wire
library does not do any read operations on the general call address to prevent this, so this would not block up the I2C bus.
how to check which slave has recieved the first
Not, because all slaves receive the data at the same time. The I2C bus is much like the IP protocol in this topic. A master/sender is sending out packages of data with the address of the intended target. But it is up to the slaves/receivers to decide, on which address they want to listen. So on every I2C transmission you are sending data over the bus, that could be read by all slaves. Only that in normal operation a slave will decide to only listen to the bus, when it sees it's own address (or the general call address).
In the IP protocol there is something called "broadcast address" when a packet contains this address all devices read it. You can do the same with i2c. Each slave has it's own address, but you can program them to also look for a "broadcast address" of your choosing. A single master can then send a single i2c message that will be read by all slaves at the same time.