From 3141c7a8589de99a288fb435bba632f7c50d8197 Mon Sep 17 00:00:00 2001 From: Lukas Loidold Date: Wed, 22 Apr 2020 10:35:58 +0200 Subject: [PATCH] IO specialized for SPI --- main.cpp | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/main.cpp b/main.cpp index 4a2ce87..22f6c56 100644 --- a/main.cpp +++ b/main.cpp @@ -11,8 +11,8 @@ #include "arduino_core/ArduinoCore-avr/libraries/SPI/src/SPI.h" //Define which port to use for the SPI Chip Select -#define CS_PORT PORTC -#define CS_DDR DDRC +#define CS_PORT PORTB +#define CS_DDR DDRB #define RING_BUFFER_SIZE 100 #define MAX_PACKET_LENGTH 100 @@ -47,11 +47,21 @@ void sendData(uint8_t *data, size_t len) { } void transferSPI(uint8_t address, uint8_t *data, size_t datalen) { - SPI.beginTransaction(SPISettings(14000000, MSBFIRST, SPI_MODE3)); - CS_PORT = ~address; - SPI.transfer(data, datalen); + SPI.beginTransaction(SPISettings(100000, MSBFIRST, SPI_MODE3)); + //CS_PORT = ~address; + digitalWrite(10, LOW); + //included + for (size_t i = 0; i < datalen; i++) + { + Serial.print("SentData is: ");Serial.println(data[i]); + data[i] = SPI.transfer(data[i]); + Serial.print("Back from n-1 ");Serial.println(data[i]); + + } + //SPI.transfer(data, datalen); delay(100); - CS_PORT = 0xff; + digitalWrite(10, HIGH); + //CS_PORT = 0xff; SPI.endTransaction(); } @@ -159,10 +169,17 @@ void serialEvent() { } void setup() { - CS_DDR = 0xff; - CS_PORT = 0xff; + //CS_DDR = 0xff; + //CS_PORT = 0xff; + + //CS_DDR |= (1<<); + //CS_PORT |= (1<