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.

[AVR] need Help to communication with multiple slave using SPI

Status
Not open for further replies.

Prayuktibid

Newbie level 6
Joined
Mar 30, 2017
Messages
12
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
148
I want to communicate with multiple slaves using SPI protocol. I takes different SlaveSelect lines for respective slave.. I have very beginner in this field I don't understand how to proceed... but I have tested data transfer between single master and single slave before going to multiple slaves.
I made a plan that I will do it by SPI interrupt Instead of SPI polling.. here the problem I dont understand how to handle interrupt ISR for each slave... please give some suggestion with example code.
Here my schematics..
AVR SPI.jpg
 

Hi,

The only difference for a multiple slave system is, that the slave need to disable (high z) it's MISO line when not active.

Klaus
 

Actually in my case It is bidirectional data transfer for each slave.. a slave can send data to master whenever it want and also for master.. master can send data to any slave whenever it wants and master should receive data from any slave when a slave send data to it by interruption . how can I handle these interruption for each slave?
 

Hi,

per SPI definition the device that generates the clock and generates the SPI_select signals is the MASTER.

SPI isn´t designed for multi master mode. Therefore you may encounter some problems you have to solve.

So there are some questions, they need to be answered before starting hardware design and before writing code.
* How did you organize bus arbitration?
* how do you prevent short circuit on all the signal lines?
* how do yo prevent signal lines from floating?
* how do you handle SCK enable and disbale?
* how do you handle chip select control?

****

All in all I don´t think it´s a good idea to use SPI as multi master bus.
I´d use I2C for this.

Klaus
 

The solution for SPI is use 1 microcontroller as a master, the rest as slaves. To implement random access to the spi from slaves, you can use gpio and make ISR on the master MCU (1 line for SS and 1 line for interrupt request per each slave). Transmitting from slave to slave in this case is possible, but rather complex.
The other solution might be daisy-chain scheme, that would reduce number of SS lines, but anyway there must be a master. The bigger network, the bigger latency, but imho daisy-chain will be more effective compared to the first one.
In any case both of them will require a lot of programming. If you're a beginner, it will be very difficult to make it works.
I2C is much easier to use for multi-master communication (moreover, atmega has very convenient twi module for that).

What is the purpose of your communication? Data rate?
 

you can use gpio and make ISR on the master MCU (1 line for SS and 1 line for interrupt request per each slave).
can I use 1 line for both cases(as SS as interrupt)?
like this photo.jpg
and another question for interrupt I have to use simple GPIO interrupt instead of SPI interrupt?
 

Hi,

I don't think it's a good Idea to use one line for both.
But if you do so, then you need a weak pullup and the ICs only drive the line LOW, never HIGH.

Interrupt:
It doesn't need to be a true interrupt. But such a signal often just is called "interrupt" line.(from slave to master)
Depending on your desired reaction time it may be OK if the master polls the lines.

Klaus
 

can I use 1 line for both cases(as SS as interrupt)?
At least not easily.

Besides using open drain logic with pull-up, as suggestes by KlausST, the slave can't assert the "interrupt" statically. It could pulse it low, but you need to handle the possible collision caused by the master starting a regular slave access at the same time.
 

Atmega has rather simple pin schematics, in fact only totem-pole for output, so there may be a situation when both devices will be configured as outputs, and both will drive line to opposite levels causing shorts.
There is another pitfall for single line besides pulling-up lines. Imagine that the master is already transferring data with one slave. At this time another slave drives SS/INT line low. The second slave will start reading not his transmission. The master will have to handle the collision by breaking current transfer, and slaves also will have to be able to process this situation.

So single line is barely suitable for that. I wouldn't recommend that.
 

Hi,

Atmega has rather simple pin schematics, in fact only totem-pole for output,

Most AtMega pins can be configured as:
* output, LOW (recommended here)
* output, HIGH
* input, pullup (recommended here)
* input, high-Z

Klaus
 

Most AtMega pins can be configured as:
* output, LOW (recommended here)
* output, HIGH
* input, pullup (recommended here)
* input, high-Z

If never make pin as output high (PORTxn always low and external pull-up) then you won't get short. But in any case output configuration is totem-pole only. I compare that with xmega that has huge amount of pin configuration (including wired-AND configuration).
But yes, I agree this is possible.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top