49 lines
1.0 KiB
C++
49 lines
1.0 KiB
C++
#include <SPI.h>
|
|
|
|
uint8_t spiRx[256]; // Array to store received data
|
|
volatile int spiRxIdx = 0; // Index to track how many items are in spiRx
|
|
volatile int spiRxComplete = 0; // Flag to indicate when data is ready for printing
|
|
|
|
char buffer[2048]; // Character buffer to store formatted data
|
|
int indexbuf = 0; // Track current position in buffer
|
|
|
|
|
|
#include "SPI2Slave_T4.h"
|
|
|
|
|
|
SPI2Slave_T4<&SPI2, SPI_8_BITS> mySPI;
|
|
|
|
//IntervalTimer SPI_transfer;
|
|
|
|
void setup() {
|
|
Serial.begin(921600);
|
|
SPI.end();
|
|
SPI1.end();
|
|
|
|
SPI2.begin();
|
|
mySPI.begin();
|
|
mySPI.swapPins(true);
|
|
|
|
//SPI_transfer.begin(ReceiveData, 10); // run every 10 microseconds
|
|
|
|
}
|
|
|
|
void loop() {
|
|
if (spiRxComplete) {
|
|
indexbuf = 0;
|
|
for (int i = 0; i < spiRxIdx; i++) {
|
|
indexbuf += snprintf(buffer + indexbuf, sizeof(buffer) - indexbuf, "%02X ", (unsigned int)spiRx[i]);
|
|
}
|
|
// Print the formatted buffer at once
|
|
Serial.println(buffer);
|
|
|
|
// Reset for the next round of data
|
|
spiRxComplete = 0;
|
|
spiRxIdx = 0;
|
|
}
|
|
delayMicroseconds(1);
|
|
}
|
|
|
|
void ReceiveData() {
|
|
}
|