diff options
| author | abel <abel.tim.t@gmail.com> | 2024-10-08 17:41:29 +0200 |
|---|---|---|
| committer | abel <abel.tim.t@gmail.com> | 2024-10-08 17:41:29 +0200 |
| commit | 5340707b87937d62c6d72197cf494d67851d05e3 (patch) | |
| tree | 6015df961f22f1850dcefb781ce1475fedab2216 /CODE/debug/comm/spi/arduino_spi_master/arduino_spi_master.ino | |
| parent | e0ee73e9de937e15fa1a60b7fe6fa081435119aa (diff) | |
| download | robotica-5340707b87937d62c6d72197cf494d67851d05e3.tar.gz robotica-5340707b87937d62c6d72197cf494d67851d05e3.zip | |
UPDATE FOLDER STUCTURE
MOET APARTE_PCB NOG VERWIJDERTEN WINDOWS HEEFT BEST VERGRENDELD
Diffstat (limited to 'CODE/debug/comm/spi/arduino_spi_master/arduino_spi_master.ino')
| -rw-r--r-- | CODE/debug/comm/spi/arduino_spi_master/arduino_spi_master.ino | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/CODE/debug/comm/spi/arduino_spi_master/arduino_spi_master.ino b/CODE/debug/comm/spi/arduino_spi_master/arduino_spi_master.ino new file mode 100644 index 0000000..248ef0f --- /dev/null +++ b/CODE/debug/comm/spi/arduino_spi_master/arduino_spi_master.ino @@ -0,0 +1,34 @@ +#include <SPI.h> +#define SS_PIN 10 +#define BAUD_RATE 19200 +#define CHAR_BUF 128 + +void setup() { + pinMode(SS_PIN, OUTPUT); + Serial.begin(BAUD_RATE); + SPI.begin(); + SPI.setBitOrder(MSBFIRST); + SPI.setClockDivider(SPI_CLOCK_DIV16); + SPI.setDataMode(SPI_MODE0); + delay(1000); // Give the OpenMV Cam time to bootup. +} + +void loop() { + int32_t len = 0; + char buff[CHAR_BUF] = {0}; + digitalWrite(SS_PIN, LOW); + delay(1); // Give the OpenMV Cam some time to setup to send data. + + if(SPI.transfer(1) == 85) { // saw sync char? + SPI.transfer(&len, 4); // get length + if (len) { + SPI.transfer(&buff, min(len, CHAR_BUF)); + len -= min(len, CHAR_BUF); + } + while (len--) SPI.transfer(0); // eat any remaining bytes + } + + digitalWrite(SS_PIN, HIGH); + Serial.print(buff); + delay(1); // Don't loop to quickly. +}
\ No newline at end of file |
