SPI - Have slave request data from master

Hi folks,

I have an interrupt timer/counter running on a Uno board. I'm assessing one-way delay for packets on my network and I intend to use this counter as a source of time to calculate the delay. So, I thought about having three Arduino boards communicating via SPI so the two slave boards could access the counter variable on the master. However, it seems that in the standard SPI arrangement, the master device can either write data to or request data from individual devices, in which case, instead of having the slaves consulting the master, the master would have to actively send this info to the slaves (which of course is not desirable). Is there a way in which the slave can request info and get a reply from the master? I feel this is rather a very stupid question, but I'm lost here.

Thanks!

Let the master ask the slave if it has a question, get the answer to that, and respond.

You could set up the slaves to be able to interrupt the master via separate, dedicated lines. Upon an interrupt request master decodes which slave is calling and sends to that slave.

Only a master can request data. If you want a multi-master system then use I2C instead of SPI.

DrDiettrich:
Only a master can request data. If you want a multi-master system then use I2C instead of SPI.

and a master can request data telling that the slave has a request, or not?

Use what's easier to implement :slight_smile:

DrDiettrich:
Only a master can request data. If you want a multi-master system then use I2C instead of SPI.

The reason why I'm trying to use SPI is because it's faster (I need to get the info as fast as possible so I don't experience drifts between the counter values the sending and receiving hosts get). Also, my timer ticks every 20 microseconds, and adding overhead and reducing clock speed is something I really wanted to avoid.

If the slaves only need a time stamp then you can simply send clock ticks to all slaves over the same shared line. Synchronization via SPI or another Cmd line when the master starts up.

Just a thought (if you’re willing to do some direct register programming):

Use the ATmega2560 for the timer/counter. It has four hardware USARTs. Configure 2 of the USARTS as slave SPIs, update both of them with the timer/counter data.

Configure the other 2 Arduinos as SPI masters, each connected to a different USART SPI slave on the ATmega2560. In this scenario, the roles of the master and slave SPIs is reversed. Only 2 wires are need for communication to each master device.

genilsonisrael:
I'm assessing one-way delay for packets on my network and I intend to use this counter as a source of time to calculate the delay.

Be aware that the timebase on the Uno is a resonator not a quartz crystal, so it's not as accurate.

aarg:
Be aware that the timebase on the Uno is a resonator not a quartz crystal, so it's not as accurate.

That's right, but if the not so accurate timer I'm using is the same for both sending and receiving hosts, the delay will be accurate. I tried to use an RTC shield but It only provides seconds, and the 32k oscillator pin wouldn't deliver the granularity I needed either.

dlloyd:
Just a thought (if you’re willing to do some direct register programming):

Use the ATmega2560 for the timer/counter. It has four hardware USARTs. Configure 2 of the USARTS as slave SPIs, update both of them with the timer/counter data.

Configure the other 2 Arduinos as SPI masters, each connected to a different USART SPI slave on the ATmega2560. In this scenario, the roles of the master and slave SPIs is reversed. Only 2 wires are need for communication to each master device.

That’s a very interesting idea… But because I need to finish this project asap, I might give up on SPI altogether and use I2C instead :confused:

dlloyd:
Use the ATmega2560 for the timer/counter. It has four hardware USARTs. Configure 2 of the USARTS as slave SPIs, update both of them with the timer/counter data.

I could not find slave mode for the MSPIM interface :frowning:

I could not find slave mode for the MSPIM interface :frowning:

Ahh, yes, well in that case it'll take some modern technology ($2.37) working with the DxCore and Arduino IDE.
Edit: The I2C is also much improved up to "Fast mode plus" mode (1MHz).

genilsonisrael:
That's right, but if the not so accurate timer I'm using is the same for both sending and receiving hosts, the delay will be accurate. I tried to use an RTC shield but It only provides seconds, and the 32k oscillator pin wouldn't deliver the granularity I needed either.

How would you ensure that it is the same for both hosts?

aarg:
How would you ensure that it is the same for both hosts?

That's exactly the point. Both hosts will be attached to a slave Arduino, and those two slaves are supposed to request the same counter variable from the one and only timer/counter.

This may be out of left field but, is there any prohibition against enabling two slaves simultaneously and transmitting a message to both?

SPI slaves activate their MISO when enabled and thus cause a short circuit.

DrDiettrich:
SPI slaves activate their MISO when enabled and thus cause a short circuit.

Looking at the datasheet for MCP23S17 I can't tell - could this be avoided by placing two diodes thusly?

2 SPI SLAVE.png

2 SPI SLAVE.png

dougp:
This may be out of left field but, is there any prohibition against enabling two slaves simultaneously and transmitting a message to both?

Even if it is possible, it won't help. I need the slaves to request the info, not the master to actively send it to them.