Arduino SPI Master Communicating To Electron Slave

I'm not sure, but I'd suspect the SPI.onSelect() is hooking up a FALLING edge interrupt on that pin. So the function hooked up should be treated like any other ISR, which means all global variables manipulated therein have to be marked volatile as they can mutate out of normal code flow.

And in addition, not only your while(1) can pose a problem, but all your loops that might be running longer than 10 seconds. In such loops the least you need to have is a Particle.process() call.
e.g.

  while(!select_state) Particle.process();

BTW, AFAIK if you don't provide a callback function to SPI.transfer() the command will be executed synchronous.

https://docs.particle.io/reference/firmware/photon/#transfer-void-void-size_t-std-function-

Since your code waits for completion anyway, let this rather do the system, which does it best.

1 Like