Hi Everyone,
I went through the SPI by Aidan. It’s pretty straightforward.
One question I have is whether there is a recommended protocol for handling/ returning data from the Slave side of things?
Any thoughts?
Gerard
Hi Everyone,
I went through the SPI by Aidan. It’s pretty straightforward.
One question I have is whether there is a recommended protocol for handling/ returning data from the Slave side of things?
Any thoughts?
Gerard
Hey @Gerard163258!
From what I gather SPI device functionality is not baked directly into the Arduino Libraries. However, you can implement a basic SPI device by reading data directly out of the SPI data register. A simple example is documented in this Stack Exchange thread.
If you’re not married to the idea of SPI specifically and just want to play around with making a smart device, we’ve covered setting up an Arduino as an I2C device before in this episode of The Factory.
This shows how we create a complex device that can be written to and read from. In this case we can issue commands to the I2C module (a buzzer) to play a tone, for a specified duration. The working source code is in the GitHub repo (both the Arduino Code for the I2C responder, and the Python driver for the I2C Initiator).
Thanks Michael,
That does complicate things a bit. In my comms protocol between Master and Slave, the data traffic is pretty light on so I could go with SPI.
I also did testing with I2C but made the SPI choice as it seemed more simple at the time. I could redo the PCB to go I2C.
Actually, I’m debating whether to just make my Master device a Pi rather than an Atmega328 (Arduino). Probably a tad more expensive with the Pi but then I don’t need to worry about a LAN connection plus a few other things with the Atmega CPU.
PCB fab is so quick and cheap these days (I use NextPCB) that it’s easy to redo a PCB.
Gerard