IO specialized for SPI

This commit is contained in:
Lukas Loidold 2020-04-22 10:35:58 +02:00
parent 866944fa26
commit 3141c7a858

View File

@ -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<<PB2);
Serial.begin(9600);
SPI.begin();
pinMode(MOSI, OUTPUT);
pinMode(SCK, OUTPUT);
pinMode(MISO, INPUT);
pinMode(10, OUTPUT);
digitalWrite(10,HIGH);
}
void loop() {