I'm having a lot of trouble getting my boron (development board) to receive SPI data in slave mode from an OpenMV camera. The camera module (RT1062) is just sending numbers for now, but I'd like for it to eventually send images. Here's the set up;
Boron's SCK
=> D2
is connected to the OpenMV's SCK (Pin P2)
Boron's MOSI
=> D3
is connected to the OpenMV's MOSI (Pin P0)
Boron's MISO
=> D4
is connected to the OpenMV's MISO (Pin P1)
Boron's D5
(SS) is connected to the OpenMV's SS (Pin P3)
The link to the OpenMV's pinout is also here OpenMV's pinout and guide
The OpenMV is just sending the number 4 to the Particle, but for some reason, the Particle is not able to read the data coming through. I followed all the instructions here Particle SPI reference, but nothing is working. I'm linking both sets of code below. Please help!
Particle Boron Code - SPI Slave Mode
#include <SPI.h>
SYSTEM_THREAD(ENABLED);
// Define the SPI object and pins
#define SPI1_SS_PIN D5
char receivedData[4];
void setup() {
// Initialize serial for debugging
Serial.begin(9600);
while (!Serial) { ; } // Wait for serial to be ready
// Initialize SPI1
SPI1.begin(SPI_MODE_SLAVE, SPI1_SS_PIN);
pinMode(SPI1_SS_PIN, INPUT_PULLUP);
}
void loop() {
if (digitalRead(SPI1_SS_PIN) == LOW) {
// SPI slave read
SPI1.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE0));
for (int i = 0; i < 4; i++) {
receivedData[i] = SPI1.transfer(0xFF);
}
SPI1.endTransaction();
// Debugging: Print received data as raw bytes
Serial.print("Received data: ");
for (int i = 0; i < 4; i++) {
Serial.print(receivedData[i], HEX);
Serial.print(" ");
}
Serial.println();
// Format the data for publishing
String dataStr = String::format("%02X %02X %02X %02X", receivedData[0], receivedData[1], receivedData[2], receivedData[3]);
Serial.println("Formatted data: " + dataStr);
// Publish the formatted data to the Particle Cloud
bool success = Particle.publish("ReceivedData", dataStr);
Serial.println("Publish success: " + String(success));
}
}
OpenMV Code - Micropython
import time
from machine import SPI, Pin
import urandom # For generating random numbers
# Setup SPI
spi = SPI(1, baudrate=1000000, polarity=0, phase=0, firstbit=SPI.MSB)
cs = Pin("P3", Pin.OUT)
cs.value(1)
def send_numbers():
#numbers = [urandom.getrandbits(8) for i in range(4)] # Generate 4 random bytes
number = 4
time.sleep(4)
cs.value(0)
spi.write(bytearray(number))
cs.value(1)
print("Sent numbers:", number) # Debugging line
while True:
send_numbers()
time.sleep(1)