SPI with multiple slaves - Page 1
Forum section: electronics / general

author: gogoman
author_rank: Regular Contributor
timestamp: August 11, 2024, 01:59:23 am
content: Hello Assume that the slaves are identical and share the same SPI I/O.Is it possible to write to all the slaves at once. To read, disable all but one slave CS, clock out its data, repeat until all the slaves are read.This is not a deep dive but a general questions,thanks gogo

author: ejeffrey
author_rank: Super Contributor
timestamp: August 11, 2024, 02:03:57 am
content: Yes you can selct multiple devices for broadcast writes. Reads obviously have to be done independently if they share MISO pins.

author: MarkF
author_rank: Super Contributor
timestamp: August 11, 2024, 02:54:35 am
content: Quote from: gogoman on August 11, 2024, 01:59:23 amFrom the way you describe what you want to do, the answer is no.Typically, the CS pin enables both read and write. Remember for each bit written, SPI reads one bit back. Therefore, you would not be able the connect all the MISO pins together. You can connect all the MOSI pins to write to all devices at once. However, you would need extra circuitry to switch the MISO pins. In which case you would still be writing while reading data.That was pretty long winded.Let's put it another way: If all you want to do is broadcast the same data to each, you can as long as you leave all the MISO pins disconnected. If however you want to have bi-directional data transfers, it's best to just do one device at a time.

author: SiliconWizard
author_rank: Super Contributor
timestamp: August 11, 2024, 04:48:22 am
content: Yep. With few exceptions (check the datasheet), the /CS pin defines the state of the MISO pin. So connecting all MISO pins together and activating all /CS pins will not be all that great.There are exceptions - some, few chips may enable the MISO buffer only after receiving a specific 'read' command - but that's relatively rare. So you'd need external circuitry to handle this. Unless you can guarantee that the state of the MISO line upon the falling edge of /CS, on this particular chip, is always going to be the same state (0 or 1, preferably 0) in all conditions, so that tying them together and enabling all chips, if you know for sure the MISO pins are not going to change state during the whole transaction, would not be a problem. I wouldn't feel really comfortable doing that myself.

author: gogoman
author_rank: Regular Contributor
timestamp: August 11, 2024, 05:10:00 am
content: Quote from: ejeffrey on August 11, 2024, 02:03:57 amdoes this make sense:that the slave miso can be or'd together. after which the data can be clocked out or each slave.When the first byte is broadcast, the miso from all the slaves should be a logic low.thanks

author: ledtester
author_rank: Super Contributor
timestamp: August 11, 2024, 05:21:48 am
content: How many devices are talking about? Are they basically the same kind of device?I could see this working...Each device shares the MOSI, CLK and CS lines. The MISO lines, however, are all assigned to different GPIO pins.You write your data using the normal SPI hardware. But to read from the devices you manually toggle the CLK line and read from the devices one bit at a time from the GPIO pins. Every CLK toggle would read in one bit from all of the devices at once.With a Raspberry PI Pico you could probably program the PIO to do the reading part - or even both the writing and reading.

author: Andreas
author_rank: Super Contributor
timestamp: August 11, 2024, 05:22:57 am
content: why not put all slaves into a "chain" (MISO out to next MISO in and read the last slave from processor)

author: m k
author_rank: Super Contributor
timestamp: August 11, 2024, 05:38:41 am
content: If not shared all can be read independently.Otherwise only one can answer at the time, how ever that is implemented.Back in the day coaxial network was like that share, one wire went through all machines.The extra function was a collision detection, where more than one simultaneous sending was detected.

author: Siwastaja
author_rank: Super Contributor
timestamp: August 11, 2024, 10:57:39 am
content: Quote from: gogoman on August 11, 2024, 05:10:00 amOrring gets rid of the short circuit (and possible destruction or misbehavior caused by it), but orring data does not usually make any sense content-wise, unless you exactly want that in a special case (e.g., each slave would share some status flags which you would OR together anyway).If you only want to write and are uninterested of what the slaves reply, you can as well leave MISOs unconnected.

author: ejeffrey
author_rank: Super Contributor
timestamp: August 11, 2024, 04:48:28 pm
content: If you need to read data back and don't want separate chip selects there are a couple of options. Some devices work like shift registers and can be daisy chained. Then "chip enable" becomes "load enable" and causes the shift register to be loaded into the active state or vice versa. Also there are other synchronous serial protocols that use addressing rather than chip selects. An example of this is the MDIO interface that Ethernet devices use to talk to and configure their PHYs. But standard SPI cant do this.