forked from mohr/ArduinoIO
Compare commits
5 Commits
SPIFunctio
...
c346d1b27d
Author | SHA1 | Date | |
---|---|---|---|
c346d1b27d | |||
a0dc6f1017 | |||
9302f11e15 | |||
cf6253216f | |||
bf94f8332b |
4
.gitmodules
vendored
4
.gitmodules
vendored
@ -1,3 +1,3 @@
|
|||||||
[submodule "arduino_core"]
|
[submodule "arduino"]
|
||||||
path = arduino_core
|
path = arduino_core
|
||||||
url = https://egit.irs.uni-stuttgart.de/mohr/arduino_core.git
|
url = https://egit.irs.uni-stuttgart.de/eive/arduino_core.git
|
||||||
|
12
Makefile
Normal file
12
Makefile
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
TARGET = ArduinoIO
|
||||||
|
# The C source files
|
||||||
|
SRC =
|
||||||
|
# The C++ source files
|
||||||
|
PSRC += main.cpp
|
||||||
|
PSRC += $(wildcard helper/*.cpp)
|
||||||
|
PSRC += arduino_core/ArduinoCore-avr/libraries/SPI/src/SPI.cpp
|
||||||
|
# extra Arduino libraries
|
||||||
|
ARDLIBS =
|
||||||
|
|
||||||
|
# this line includes the Makefile.base
|
||||||
|
include arduino_core/arduino-base.mk
|
51
main.cpp
51
main.cpp
@ -11,8 +11,8 @@
|
|||||||
#include "arduino_core/ArduinoCore-avr/libraries/SPI/src/SPI.h"
|
#include "arduino_core/ArduinoCore-avr/libraries/SPI/src/SPI.h"
|
||||||
|
|
||||||
//Define which port to use for the SPI Chip Select
|
//Define which port to use for the SPI Chip Select
|
||||||
#define CS_PORT PORTB
|
#define CS_PORT PORTC
|
||||||
#define CS_DDR DDRB
|
#define CS_DDR DDRC
|
||||||
|
|
||||||
#define RING_BUFFER_SIZE 100
|
#define RING_BUFFER_SIZE 100
|
||||||
#define MAX_PACKET_LENGTH 100
|
#define MAX_PACKET_LENGTH 100
|
||||||
@ -43,26 +43,15 @@ void sendData(uint8_t *data, size_t len) {
|
|||||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial.write(buffer, writtenLen);
|
Serial.write(buffer, writtenLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
void transferSPI(uint8_t address, uint8_t *data, size_t datalen) {
|
void transferSPI(uint8_t address, uint8_t *data, size_t datalen) {
|
||||||
SPI.beginTransaction(SPISettings(100000, MSBFIRST, SPI_MODE3));
|
SPI.beginTransaction(SPISettings(14000000, MSBFIRST, SPI_MODE3));
|
||||||
//CS_PORT = ~address;
|
CS_PORT = ~address;
|
||||||
digitalWrite(10, LOW);
|
SPI.transfer(data, datalen);
|
||||||
//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);
|
delay(100);
|
||||||
digitalWrite(10, HIGH);
|
CS_PORT = 0xff;
|
||||||
//CS_PORT = 0xff;
|
|
||||||
SPI.endTransaction();
|
SPI.endTransaction();
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -78,14 +67,14 @@ void handlePacket(uint8_t *packet, size_t packetLen) {
|
|||||||
|
|
||||||
|
|
||||||
if (crc != 0) {
|
if (crc != 0) {
|
||||||
//Serial.println("invalid Checksum");
|
Serial.println("invalid Checksum");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t payloadLen = (packet[2] << 8) | packet[3];
|
uint16_t payloadLen = (packet[2] << 8) | packet[3];
|
||||||
|
|
||||||
if (payloadLen != packetLen - 6) {
|
if (payloadLen != packetLen - 6) {
|
||||||
//Serial.println("invalid len");
|
Serial.println("invalid len");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,11 +89,14 @@ void handlePacket(uint8_t *packet, size_t packetLen) {
|
|||||||
//echo the data back, no need to change the header fields, they are the same
|
//echo the data back, no need to change the header fields, they are the same
|
||||||
//checksum will be written by sendData()
|
//checksum will be written by sendData()
|
||||||
//check reply:
|
//check reply:
|
||||||
|
Serial.println("Data response check: ");
|
||||||
|
for(size_t i =0; i< packetLen; i++){
|
||||||
|
Serial.print("packet nr ");Serial.print(i);Serial.print(" ");Serial.println(packet[i]);
|
||||||
|
}
|
||||||
sendData(packet, packetLen);
|
sendData(packet, packetLen);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
//Serial.println("invalid command");
|
Serial.println("invalid command");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,13 +113,13 @@ void handleNewData() {
|
|||||||
size_t firstSTXinRawData = 0;
|
size_t firstSTXinRawData = 0;
|
||||||
while ((firstSTXinRawData < rawDataSize)
|
while ((firstSTXinRawData < rawDataSize)
|
||||||
&& (rawData[firstSTXinRawData] != DleEncoder::STX)) {
|
&& (rawData[firstSTXinRawData] != DleEncoder::STX)) {
|
||||||
//Serial.println(rawData[firstSTXinRawData]);
|
Serial.println(rawData[firstSTXinRawData]);
|
||||||
firstSTXinRawData++;
|
firstSTXinRawData++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rawData[firstSTXinRawData] != DleEncoder::STX) {
|
if (rawData[firstSTXinRawData] != DleEncoder::STX) {
|
||||||
//there is no STX in our data, throw it away...
|
//there is no STX in our data, throw it away...
|
||||||
//Serial.println("NO STX");
|
Serial.println("NO STX");
|
||||||
ringBuffer.deleteData(rawDataSize);
|
ringBuffer.deleteData(rawDataSize);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -167,17 +159,10 @@ void serialEvent() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
//CS_DDR = 0xff;
|
CS_DDR = 0xff;
|
||||||
//CS_PORT = 0xff;
|
CS_PORT = 0xff;
|
||||||
|
|
||||||
//CS_DDR |= (1<<);
|
|
||||||
//CS_PORT |= (1<<PB2);
|
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
pinMode(MOSI, OUTPUT);
|
SPI.begin();
|
||||||
pinMode(SCK, OUTPUT);
|
|
||||||
pinMode(MISO, INPUT);
|
|
||||||
pinMode(10, OUTPUT);
|
|
||||||
digitalWrite(10,HIGH);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
5
makefile
5
makefile
@ -1,5 +0,0 @@
|
|||||||
TARGET = ArduinoIO
|
|
||||||
SRC = # the C source files
|
|
||||||
PSRC = main.cpp $(wildcard helper/*.cpp) arduino_core/ArduinoCore-avr/libraries/SPI/src/SPI.cpp # the C++ source files
|
|
||||||
ARDLIBS = # extra Arduino libraries
|
|
||||||
include arduino_core/arduino-base.mk # this line includes the Makefile.base
|
|
Reference in New Issue
Block a user