37 lines
764 B
C++
37 lines
764 B
C++
#include <SPI.h>
|
|
|
|
#define cs_pin 44 // Chip Select pin (must match the slave setup)
|
|
byte cnt = 0;
|
|
|
|
uint8_t dataToSend[256];
|
|
|
|
void setup() {
|
|
Serial.begin(115200);
|
|
Serial.println("SPI Master Starting...");
|
|
|
|
pinMode(cs_pin, OUTPUT);
|
|
digitalWrite(cs_pin, HIGH);
|
|
|
|
SPI2.begin();
|
|
}
|
|
|
|
void loop() {
|
|
|
|
for (int i = 0; i < 256; i++) {
|
|
dataToSend[i] = i;
|
|
}
|
|
dataToSend[0] = cnt;
|
|
cnt++;
|
|
if(cnt>256)cnt=0;
|
|
|
|
SPI2.beginTransaction(SPISettings(22000000, MSBFIRST, SPI_MODE0));
|
|
Serial.println("Sending data...");
|
|
digitalWrite(cs_pin, LOW);
|
|
SPI2.transfer(dataToSend, 256); // Send the whole array at once
|
|
digitalWrite(cs_pin, HIGH);
|
|
Serial.println("Data sent.");
|
|
SPI2.endTransaction();
|
|
|
|
delayMicroseconds(1000); // Wait before sending again
|
|
}
|