Author Topic: SPI with multiple slaves  (Read 560 times)

0 Members and 1 Guest are viewing this topic.

Offline gogomanTopic starter

  • Regular Contributor
  • *
  • Posts: 123
SPI with multiple slaves
« on: August 11, 2024, 01:59:23 am »
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
 

Online ejeffrey

  • Super Contributor
  • ***
  • Posts: 3868
  • Country: us
Re: SPI with multiple slaves
« Reply #1 on: August 11, 2024, 02:03:57 am »
Yes you can selct multiple devices for broadcast writes.  Reads obviously have to be done independently if they share MISO pins.
 

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 2630
  • Country: us
Re: SPI with multiple slaves
« Reply #2 on: August 11, 2024, 02:54:35 am »
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.

From 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.
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 15168
  • Country: fr
Re: SPI with multiple slaves
« Reply #3 on: August 11, 2024, 04:48:22 am »
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.
 

Offline gogomanTopic starter

  • Regular Contributor
  • *
  • Posts: 123
Re: SPI with multiple slaves
« Reply #4 on: August 11, 2024, 05:10:00 am »
Yes you can selct multiple devices for broadcast writes.  Reads obviously have to be done independently if they share MISO pins.

does 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
 

Offline ledtester

  • Super Contributor
  • ***
  • Posts: 3218
  • Country: us
Re: SPI with multiple slaves
« Reply #5 on: August 11, 2024, 05:21:48 am »
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.


 

Offline Andreas

  • Super Contributor
  • ***
  • Posts: 3286
  • Country: de
Re: SPI with multiple slaves
« Reply #6 on: August 11, 2024, 05:22:57 am »
why not put all slaves into a "chain" (MISO out to next MISO in and read the last slave from processor)
 

Offline m k

  • Super Contributor
  • ***
  • Posts: 2372
  • Country: fi
Re: SPI with multiple slaves
« Reply #7 on: August 11, 2024, 05:38:41 am »
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.
Advance-Aneng-Appa-AVO-Beckman-Danbridge-Data Tech-Fluke-General Radio-H. W. Sullivan-Heathkit-HP-Kaise-Kyoritsu-Leeds & Northrup-Mastech-REO-Simpson-Sinclair-Tektronix-Tokyo Rikosha-Topward-Triplett-Tritron-YFE
(plus lesser brands from the work shop of the world)
 

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 8643
  • Country: fi
Re: SPI with multiple slaves
« Reply #8 on: August 11, 2024, 10:57:39 am »
does this make sense:
that the slave miso can be or'd  together.  after which the data can be clocked out or each slave.

Orring 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.
 

Online ejeffrey

  • Super Contributor
  • ***
  • Posts: 3868
  • Country: us
Re: SPI with multiple slaves
« Reply #9 on: August 11, 2024, 04:48:28 pm »
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.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf