0
\$\begingroup\$

Consider that an SPI has more slaves.

Suppose if more than one slave wants to communicate with master simultaneously, then how does an SPI react in that situation? By means of priority or any other means?

If it is by priority means, then it will be done by hardware or software and how?

And also, can SPI (Master) be able to communicate with more than one slaves simultaneously?

I am novice to SPI.

\$\endgroup\$
1
  • \$\begingroup\$ Your new diagram is wrong. There must be a separate SS (Slave Select) line to each slave. However, your diagram already answers most of your questions: Only one MOSI and one MISO line means that it is impossible for the master to talk to more than one slave at once, unless all slave are receiving and transmitting the exact same data. \$\endgroup\$
    – DoxyLover
    Apr 3, 2016 at 3:53

2 Answers 2

6
\$\begingroup\$

With multiple slaves on one SPI bus, only one can communicate at a time. The master is responsible for choosing which chip that is, by manipulating the appropriate slave select line. If you have several slaves, and they may need to send messages to the master, you have several options:

  • Poll the slaves. The master cycles through the slaves regularly, checking if they want to communicate.
  • Use another wire. Some SPI chips can assert a separate connection which is not part of the SPI bus but is nonetheless connected to both the slave and the master. When the master sees this happen, it knows to contact that chip over the SPI bus. This is sometimes known as an interrupt, though it may or may not trigger an actual interrupt on the microcontroller.

There is no sense of priority beyond the basic idea that one slave is selected and all others are ignoring the bus. If you need to have a priority system, you can do that in software on the master, but it's not part of SPI.

An example of a chip I have been using recently is the AD7730. It's an ADC, and it regularly has new conversion results to pass to the master. One way to use this chip is to connect by SPI, and regularly read the status register. When one of the bits in the status register goes high, it means a new measurement is ready, and you can read it out (also over SPI). An alternate way of using it is to connect the RDY pin on the AD7730 to a GPIO pin on your master and when the measurement is ready that pin goes high. The master can then read the result over SPI.

\$\endgroup\$
11
  • \$\begingroup\$ Which means it has no priority unless we select it @Jack B \$\endgroup\$ Apr 2, 2016 at 18:30
  • 1
    \$\begingroup\$ Yes, there is no concept of priority built into SPI other than one slave is selected and all others are silent. But you can add priority at a higher layer, if that is what you need - in software, on the master. That's not part of SPI though. \$\endgroup\$
    – Jack B
    Apr 2, 2016 at 18:34
  • 1
    \$\begingroup\$ Yes, while the master is checking the status bit, no other communication can happen on the bus. With that chip, you need to check the status bit maybe 200 times a second. That leaves space in the gaps for some other communications. If that much traffic on the bus is a problem, you would need to use the other method with the extra wire. \$\endgroup\$
    – Jack B
    Apr 2, 2016 at 18:44
  • 1
    \$\begingroup\$ It's going to be chip specific. Check the datasheet for the slave you want to use. \$\endgroup\$
    – Jack B
    Apr 2, 2016 at 19:05
  • 1
    \$\begingroup\$ @Sridhar what he means is if the slave devices have an output that is asserted when they want to talk, these can be connected to GPIO inputs on the master. The master can then either poll these inputs or have interrupts triggered to active the SPI driver. If the slaves don't have such outputs, there's nothing you can do but poll over SPI. There's really not much more to say. \$\endgroup\$
    – DoxyLover
    Apr 3, 2016 at 3:57
4
\$\begingroup\$

First, a slave cannot chose to communicate with the master. All transfers are initiated by the master. You may use GPIOs to connect "interrupt" or "request" lines from the slaves but it is up to the host software to respond to these and choose the order to service the requests.

Second, no, the master cannot communicate with multiple slaves simultaneously. There is only one pair of data lines (master-to-slave and slave-to-master) so multiple simultaneous transfers is impossible. (Actually, there may be more than one line in each direction, but these are only used for parallel data to and from a single slave to speed up the transfer.)

\$\endgroup\$

Your Answer

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

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