blob: 3943fe368be620a068936f57ae61ee52c2fd8416 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
#include <SPI.h>
// * CS - to digital pin 10 (SS pin)
// * SDI - to digital pin 11 (MOSI pin)
// * SDI - to digital pin 12 (MISO pin)
// * CLK - to digital pin 13 (SCK pin)
// Vorbereitungen um als Slave Daten zu empfangen
char recieve_buff [100];
volatile byte pos;
volatile boolean process_it;
// PINS fuer SPI
const int slaveSelectPin = 10;
const int miso = 12;
const int mosi = 11;
const int ledPin = 2;
void setup() {
pinMode(slaveSelectPin, INPUT);
pinMode(miso, OUTPUT);
// SPI als Slave aktivieren
SPCR |= _BV(SPE);
// interrupt vorbereitung
pos =0; //recieve Buffer leer
process_it = false;
SPI.attachInterrupt();
// initialize the digital pin as an output.
pinMode(ledPin, OUTPUT);
digitalWrite (ledPin, HIGH);
delay(1000);
digitalWrite (ledPin, LOW);
}
//PINS/Bitmask fuer LEDs
int LED0 = 0x01;
int LED1 = 0x02;
int LED2 = 0x04;
int LED3 = 0x08;
int PWM_BASE = 15;
ISR (SPI_STC_vect)
{
byte c = SPDR;
if (pos < sizeof recieve_buff)
{
recieve_buff[pos++] = c;
process_it = true;
}
}
void loop()
{
//Verarbeitung der empfangenen Nachricht
if (process_it == true)
{
if (recieve_buff[pos] == 0x31)
digitalWrite (ledPin, HIGH);
else if (recieve_buff[pos] == 0x30)
digitalWrite (ledPin, LOW);
process_it == false;
pos = 0;
}
}
|