Hi everybody. I’m trying to connect two Photons via SPI. Photon1 is the master and Photon2 the slave. I have read the SPI Firmware and there’s an example of how to use it, but I want to do a much simplier example… I’m just sending a 0 or 1 with the Master and I’m not sure if my code is OK…
const int dataLED = A1;
int slaveSelected; //Flag
uint8_t transferData;
void onSelect(uint8_t state) { //Slave Handler
if (state == 0) { //Slave selected
slaveSelected = 0;
}
else { //Slave not selected
slaveSelected = 1;
}
}
void setup() {
Serial.begin(9600);
SPI.onSelect(onSelect); //Register a Handler to get called when SS changes state
SPI.begin(SPI_MODE_SLAVE); //Configures SS, SCK and MOSI as inputs and MISO as output
pinMode(dataLED, OUTPUT);
}
void loop() {
if (slaveSelected == 0) {
SPI.transfer(transferData); //Transfer data from Master
if (transferData >= 1) { //Master sent "1"
digitalWrite(dataLED, HIGH);
}
else { //Master sent "0"
digitalWrite(dataLED, LOW);
}
}
}