Core Electronics Forum

SPI Bus with multiple slaves

Hey All,

With talking to multiple slave devices, is there a preferred protocol for how the master selects the slaves?

I guess if I had 8 slave devices, I could use a 3 bit bus and have some kind of decoding logic on each slave device.

:smiley:
Gerard

4 Likes

Hi Gerard,

There’s just Chip Select (CS) - one way or another you need a dedicated CS pin for each device. You might be able to do that with some kind of logic circuit that takes a binary input and toggles a suitable pin, to save yourself some GPIO on your microcontroller, but you’ll need a pin for each device on the other side.

4 Likes

Thanks for that Oliver. I think I can get it done and will put up my schematic for comment later.

One other issue is how to send/receive digital signalling over 20, 30 or 40 metres. I guess I could use MAX232 devices as it’s all simplex transmission lines.

:slight_smile:

6 Likes

Ouch, yes SPI won’t go that far. A Differential Signalling protocol like RS485 or RS422 would probably be your best bet (assuming you need more throughput than UART can get you over RS-232).

5 Likes

Yes, I think you’re probably correct.

I’m a little annoyed with myself that I forgot about making these devices communicable! :roll_eyes:

5 Likes

Hi Gerard and Oliver.
Over that distance for reliability you would be better off with RS485 which can be half or full duplex. RS422 is pretty much the same but I think only one way, like master and slaves. They are both balanced transmission line and supposedly good for 1200 metres but I think a repeater is recommended before that limit is reached. Don’t forget to terminate the cables at the correct place(s).

RS232 using a 3 wire connection and “normal” screened cable is only suggested over 2 or 3 metres. You can get our 40 or more by using sort of “balanced” wiring techniques and very low capacitance cable. I have used it up to 70 metres plus using low cap cable and DE9 connectors with a 4 wire system but not easy to get the cable in small quantities for a start.
Cheers Bob

6 Likes

It’s been years since I messed around with RS485 so, naturally, forgot about the terminators. This is the block diagram I’m working to.

5 Likes

Hi Gerard
Don’t know much about SPI (I should try to find out I know) but it is the “Bus” bit that you need to convert to a balanced line system to use over longer distances.

Terminations. The RECEIVER END has to be terminated in 120Ω. If using RS485 in Half Duplex mode that means traffic is transmitted in both directions on the same pair so BOTH ENDS will be receivers and need the termination. Note the terminations only fitted to the ENDS of the cable.

Some adaptors I have noted are pre fitted with a 120Ω termination. This will severely overload the drivers and need to be removed. I don’t know why they do this but would be OK if only 2 devices are used. The RS485 bus can handle 32 drops if done correctly. The drivers are designed to operate into a load of 56Ω I think it is (might be 54Ω) which is 2 120Ω resistors and 32 drops all in parallel.
Cheers Bob

6 Likes

Bob,

This is pretty good…
Serial Peripheral Interface (SPI) - learn.sparkfun.com

6 Likes

Hey All,

So I added the RS485 drivers into my creation of madness.

I’m not too happy with my selection of an SN75176 which is an 8 pin DIP with one RX and one TX. On the Controller side (what used to be termed Master), I need 5 TX and one RX/TX (for COPI/CIPO signalling) .

Any suggestions for a better alternative?

3 Likes

Have a browse through Maxim’s catalogue: RS-485 and RS-422 Transceivers | Maxim Integrated

I’m sure you’ll find something.

MOSI/MISO (for Master/Slave Out/In) is the correct terminology.

I know there are some people on a vendetta to try and eliminate the use of master/slave in all technical fields because they believe the subject of human slavery (and anything that even reminds them of it) should be taboo and never discussed, but this is a communications protocol, not human slavery.

They’re well intentioned but very confused and misguided, and you’ll find yourself having to use MOSI/MISO to explain what you mean anyway (like you did here), so it’s better to just stick with the correct names upfront and prevent confusion, and not encourage the whole mess.

Technical jargon’s hard enough to learn as is.

4 Likes

Hi Oliver,

Yes, I hear you about the MISO>CIPO thing. I must admit that I never had connected the terms to human slavery.

With the RS 485/422 thing. I don’t need a high data rate so that improves my selection criteria.

Gerard

3 Likes

Hey Guys,

I had an interesting thought!

What I could do is send SS to every slave device. The first byte of transmitted data from the master instructs which of the 15 slaves is to respond. I reckon that might save 4 packages and the coding would only be marginally more complex (sending an extra byte of data)

Thoughts?

Gerard

2 Likes