I decided to write a separate piece of sample code to play around with SPI, without any of the the Ethernet stuff. Problem is, it doesn't work!
It gets to the SPI transfer part then falls over, I see "Transferring" on the serial monitor and never the "Done" (lines 26 and 28, wrapped around the SPI.transfer on line 27).
The Ethernet2 shield is attached to the SPI but nothing else (well, scope probes are). The transfers don't happen, the SPI clock doesn't change state.
If anyone can spot the idiot mistake I've made that would be great!
The Ethernet/SPI test code I posted previously still works, so it's not a short or other daft hardware issue.
#include <SPI.h>
const int SPIbuf_Size = 100;
byte SPIbuf [SPIbuf_Size];
const int FPGA_SPI_CSpin = 4;
unsigned long current_micros;
const unsigned long looptime = 2000000;
const int Serial_Baud = 115200;
void setup() {
pinMode(FPGA_SPI_CSpin, OUTPUT);
Serial.begin(Serial_Baud);
Serial.println(F("Setup Complete"));
}
void loop() {
current_micros = micros();
for (int j = 0; j<256; j++)
{
Serial.print(F("Doing : "));
Serial.println(j);
SPIbuf[0] = j;
SPIbuf[SPIbuf_Size-1] = j;
SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE0));
digitalWrite(FPGA_SPI_CSpin, LOW);
Serial.println(F("Transferring"));
SPI.transfer (&SPIbuf, SPIbuf_Size);
Serial.println(F("Done"));
digitalWrite(FPGA_SPI_CSpin, HIGH);
SPI.endTransaction();
Serial.print(j);
Serial.print(F(" : "));
Serial.print(SPIbuf[0]);
Serial.print(F(" : "));
Serial.println(SPIbuf[SPIbuf_Size-1]);
while ((micros()- current_micros)<looptime)
{
}
}
}