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.
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.
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.
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
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
I could not find slave mode for the MSPIM interface
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.