The SPI connection between Photon (master) and Arduino (slave) seems not to work as expected.
I am trying with the following code.
Photon master:
void setup()
{
pinMode(A2, OUTPUT);
SPI.begin(SPI_MODE_MASTER, A2);
SPI.setBitOrder(MSBFIRST);
SPI.setClockDividerReference(SPI_CLK_ARDUINO);
SPI.setClockDivider(SPI_CLOCK_DIV16);
SPI.setDataMode(SPI_MODE0);
Serial.begin(9600);
}
void loop()
{
digitalWrite(A2, LOW);
SPI.transfer(0x5A);
digitalWrite(A2, HIGH);
Serial.println(0x5A);
Serial.println("Sending...");
delay(5000);
}
Arduino slave:
#include<SPI.h>
volatile boolean received;
volatile byte receivedData;
ISR (SPI_STC_vect) //Inerrrput routine function
{
receivedData = SPDR; // Get the received data from SPDR register
received = true; // Sets received as True
}
void setup()
{
Serial.begin(115200);
pinMode(MISO,OUTPUT); //Sets MISO as OUTPUT
SPCR |= _BV(SPE); //Turn on SPI in Slave Mode
received = false;
SPI.attachInterrupt(); //Activate SPI Interuupt
}
void loop()
{
if(received) {
received = false;
Serial.print(receivedData, HEX);
}
}
Interruption doesn’t happen on Arduino. Is there anything missing in my code?