Hallo zusammen,
ich versuche gerade eine SPI-Kommunikation zwischen einem Arduino
Mega2560 und einem Arduino UNO über einen LTC4332 zu realisieren und ich
habe aktuell das Problem das ich auf der "Local"-Seite die Daten per SPI
einlese die ich gesendet habe, obwohl meine "Remote"-Seite keine Daten
zurückschickt.
Auf der "Remote"-Seite wird der Text "hallo.." ausgegeben, was korrekt
ist. Auf der "Local"-Seite bekomme ich als Ausgabe folgendes:
1 | 0
|
2 | 10
|
3 | 104
|
4 | 97
|
5 | 108
|
6 | 108
|
7 | 111
|
8 | 46
|
Der Code für die "Local"-Seite schaut folgendermaßen aus:
1 | #include <SPI.h>
|
2 |
|
3 | #define SPI_CS 53
|
4 |
|
5 | void setup()
|
6 | {
|
7 | pinMode(SPI_CS, OUTPUT);
|
8 |
|
9 | digitalWrite(SPI_CS, HIGH);
|
10 |
|
11 | Serial.begin(115200);
|
12 |
|
13 | SPI.begin();
|
14 | SPI.setDataMode(SPI_MODE0);
|
15 |
|
16 | digitalWrite(SPI_CS, LOW);
|
17 | SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE0));
|
18 | Serial.println(SPI.transfer('h'));
|
19 | Serial.println(SPI.transfer('a'));
|
20 | Serial.println(SPI.transfer('l'));
|
21 | Serial.println(SPI.transfer('l'));
|
22 | Serial.println(SPI.transfer('o'));
|
23 | Serial.println(SPI.transfer('.'));
|
24 | Serial.println(SPI.transfer('.'));
|
25 | Serial.println(SPI.transfer('\n'));
|
26 | digitalWrite(SPI_CS, HIGH);
|
27 | }
|
28 |
|
29 | void loop()
|
30 | {
|
31 | delay(1000);
|
32 | }
|
Der Code für die "Remote"-Seite wie folgt:
1 | #include <SPI.h>
|
2 |
|
3 | char buf [100];
|
4 | volatile byte pos;
|
5 | volatile boolean process_it;
|
6 |
|
7 | void setup(void)
|
8 | {
|
9 | Serial.begin(9600);
|
10 |
|
11 | SPCR |= bit(SPE);
|
12 | pinMode(MISO, OUTPUT);
|
13 |
|
14 | pos = 0;
|
15 | process_it = false;
|
16 |
|
17 | SPI.attachInterrupt();
|
18 | }
|
19 |
|
20 | ISR(SPI_STC_vect)
|
21 | {
|
22 | byte c = SPDR;
|
23 |
|
24 | if (pos < (sizeof (buf) - 1))
|
25 | buf [pos++] = c;
|
26 |
|
27 | if (c == '\n')
|
28 | process_it = true;
|
29 | }
|
30 |
|
31 | void loop (void)
|
32 | {
|
33 | if(process_it)
|
34 | {
|
35 | buf [pos] = 0;
|
36 | Serial.println(buf);
|
37 | pos = 0;
|
38 | process_it = false;
|
39 | }
|
40 | }
|
Ich verstehe nicht woher das Problem kommt. Hat jemand eine Idee?
Vielen Dank