I'm neck deep learning about all of this and am trying to understand at a high level how I will be able to connect multiple Arduinos using SPI, and the timing involved. The examples I've seen with an Arduino as a slave, seem to have the slave code just looping forever until the master sends it a command. And it seems to require a virtually instantaneous response from the slave.
In my case, one of the duties of the slave is to turn on and then immediately turn off a solenoid (via a relay, via a shift register.) It is very important that the slave be able to turn off the solenoid very quickly after turning it on -- only a fraction of a second or the solenoid can burn out (this is a hobby project, automatically controlling model trains.)
I'm not really clear if the SPI interface triggers an actual interrupt in the slave, or if it is the duty of the slave to simply be at the ever-ready awaiting input. Please clarify as I seem to have read it both ways on various posts.
My concern is that if the master sends a command to the slave at the moment that the slave has turned on the solenoid, but before turning it off -- whether an actual interrupt or some looping code that is constantly checking for input from the master -- I have a problem. If SPI triggers an interrupt, then my slave won't get to finish the job of turning off the solenoid. On the other hand, if the slave doesn't check the Slave Select line until it has turned of the solenoid, then it may have missed some of the data that the master has been sending -- and with no built-in acknowledgment or error checking to know otherwise.
I have some ideas on how to deal with this, such as dedicating another I/O line that the slave will control and the master can check, so the master does not try to transmit until it knows the slave is idle...and also to send back the command (actually data) to the master so the master can confirm that it's the same as the data that was sent..but I'm probably just overlooking something fundamental.
Thanks so much for any replies to my questions!
Randy