Upload files to "spi_receive"

This commit is contained in:
Adema 2025-05-12 07:08:03 +02:00
commit d4db9babdf

View File

@ -0,0 +1,37 @@
uint32_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 "SPISlave_T4.h"
SPISlave_T4<&SPI, SPI_8_BITS> mySPI;
IntervalTimer SPI_transfer;
void setup() {
Serial.begin(921600);
mySPI.begin();
mySPI.swapPins(true);
SPI_transfer.begin(ReceiveData, 10); // run every 10000 microseconds
}
void loop() {
// Other loop code can go here (if necessary)
}
void ReceiveData() {
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;
}
}