From d4db9babdf4bd654dcfe35e6421b2e07abbea56b Mon Sep 17 00:00:00 2001 From: Adema Date: Mon, 12 May 2025 07:08:03 +0200 Subject: [PATCH] Upload files to "spi_receive" --- spi_receive/spi_receive.ino | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 spi_receive/spi_receive.ino diff --git a/spi_receive/spi_receive.ino b/spi_receive/spi_receive.ino new file mode 100644 index 0000000..06a7303 --- /dev/null +++ b/spi_receive/spi_receive.ino @@ -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; + } +}