Implements the SPI byte protocol on Arduino to exchange bytes with a FPGA. Written in C for Intel Arduino 101. This page continues the protocol description of the Math Talk series. This short section shows an Arduino implementation of a SPI master. The Arduino can be either an Arduino 101 or an Arduino UNO R3 that has been modified to run on 3.3V as described in the hardware section.
Arduino as Master
The Arduino is blessed with a support library for the serial peripheral interface. This greatly aids the implementation. The code shown below was tested with both types of Arduino. For the slave we used an Altera or Xilinx based FPGA implementation as described on the next page. Refer to the first part of this article for details about the physical connection. In particular, once more, please read the part about 3.3V versus 5V when using an Arduino UNO R3.
Sources
The SPI library makes it very straightforward to implement a SPI master. You can clone this project from:
-
SPI Master implementation,
arduino-spi_byte.ino
The Arduino sends an alternating pattern of 0xAA and 0x55 to the FPGA. On the FPGA, LED[0] will be on when it receives 0xAA. Consequentially it will blink with 10% duty cycle. The FPGA always returns 0x55, what is displayed on the serial port.
Traces
Logic analyzer traces of the Arduino communicating with the FPGA. We see the SS
going active, and the FPGA sending a byte over MISO to the Arduino. The data is sampled on the rising edge of SCLK
.
Zoomed out, we see the Arduino receiving three bytes from the FPGA.