Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Communication between a master and multiple slaves at the same time using SPI

Status
Not open for further replies.

ponnus

Full Member level 2
Joined
Mar 17, 2011
Messages
142
Helped
8
Reputation
16
Reaction score
8
Trophy points
1,298
Location
Cochin, INDIA
Activity points
2,226
Hai friends,
I am working on PIC USB starter kit II. I want to connect two devices to a single SPI port of my PIC. I read that the master can communicate to multiple slaves. Can I transfer data to both the slaves simultaneously? Please help me.......
 

With SPI you chain devices together, the Data Out from one goes into the Data In to the next, the data out from the last device in the chain returning back to the master.

The data is clocked through all the devices.

With two slaves, you would write two bytes, the first byte would end up in device number two in the chain, the secound byte would end up in device number one in the chain.
 
  • Like
Reactions: ponnus

    ponnus

    Points: 2
    Helpful Answer Positive Rating
Hai,
Did you mean daisy chain? So, inorder to push the last byte to the second slave, I've to send one extra byte at the end. So, is it not able to send data to multiple slaves using same data lines and different chip selects?
 

If you have chip selects, then the devices can be connected in parallel.
Otherwise they are daisy chained.
 

You can use a parallel configuration with multiple CS.
You can write the data in all devices by asserting all CS, but you need to connect (at least) one protection resistor between each device serial data out and microcontroller serial data in (the problem is that all selected devices will drive a line on the same time). For proper read operations only one device should be selected.
 
  • Like
Reactions: ponnus

    ponnus

    Points: 2
    Helpful Answer Positive Rating
So, is it not able to send data to multiple slaves using same data lines and different chip selects?
Of course it's possible. But you didn't ask clearly.

It should be also noticed, that daisy chain operation isn't supported by all SPI slaves. Using separate chip selects is the standard method to a connect multiple devices to a SPI bus. It gives also an option, to write identical data to multiple devices simultaneously, if multi enabled slave SDO aren't an issue.
 
  • Like
Reactions: ponnus

    ponnus

    Points: 2
    Helpful Answer Positive Rating
Hai,
I want to write to both slaves at the same time, but reading is not needed simultaneously. So, when I write to both slaves both slaves will push the same number of bytes back to the Pic. Then, how the protection resistor help the device from overvoltage. Is the resistor should be such that the voltage on the SDI line at Pic side is the sum of voltages of slave SDO lines. I am using +3.3V to drive all the devices. What amount of resistance should I use? Does it depend on the current?
 

Hai,
... I am using +3.3V to drive all the devices. What amount of resistance should I use? Does it depend on the current?
Theoretically you should not exceed current limit for device serial data out (3.3Volts / Resistor value < current maxim).
In general 1k -4k7 should work.
 
  • Like
Reactions: ponnus

    ponnus

    Points: 2
    Helpful Answer Positive Rating
Hai,
Sorry, I am back again.
Now, I've connected two spi modules to my Pic32 master. I've done communication with one of the spi module.

Whenever the master sends a byte, it will be received by both modules and the first module is pushing a byte back to the master.This is working fine.

In the second slave, I've disabled the SDO pin and slave select is also not enabled. But I'm receiving only the first byte from the master. So, do I need to push one byte to master from this slave also?

Thanks
 

Hai,
I just want to send data to both slaves simultaneously. Can I set PIC24 spi slave as receiver only?
Thanks
 

Hai,
I've set PIC32 as SPI master and PIC24 as SPI slave. I'm trying to send data from master to slave.
When I do it step by step, I'm getting all the bytes at the slave side.
But when I run the program continuously (sending an array of bytes), I'm getting only first two bytes.
The third byte I'm sending is a zero. Is that a problem?
Can anyone help me please....
 

I just want to send data to both slaves simultaneously. Can I set PIC24 spi slave as receiver only?
I don't think that "send data simulataneously" describes your setup correctly. You say you have individual chip selects, so you are sending to one slave at a time, not two.

The problem description is also vague. What may happen is that you are writing data to the SPI transmit buffer or even multiple bytes to the FIFO, depending on the SPI setup with hasn't been clearly described. But the chip select is released before all data has been send.
 

hai,
My first slave is a flash memory and second is PIC24.
I can communicate with flash memory. It's fine.

my aim is that, whenever I transfer a byte, it should be received by both modules.
Now,I'm doing it in such a way that, when the master sends a byte, both the modules receive it and the first slave will push a byte back to the master. After getting this byte, master sends the next byte.

When I tried it step by step, I am getting all the bytes at PIC24 (second slave). But when I run it continuously, only first two bytes are received.
I'm using SPI interrupts to receive data at PIC24
Thank you
 
Last edited:

Hai,
i've solved it. The problem was due to slow clock speed of the slave. So, SPI slave buffer was overflowing. Now I've increased the clock speed and is working well.

Thanks for your help..
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top