diff options
| author | Jörg Biemann <joerg@Jorgs-MacBook-Pro.local> | 2012-07-15 17:14:05 +0200 |
|---|---|---|
| committer | Jörg Biemann <joerg@Jorgs-MacBook-Pro.local> | 2012-07-15 17:14:05 +0200 |
| commit | 55c3682837e9f525caff885592c101a949def947 (patch) | |
| tree | d128bf7932d65f714d77cbcd3eab6f7a71af8ddc | |
initial import
SPI Save for controling LEDs in Kirmesbuden
Signed-off-by: Jörg Biemann <joerg@Jorgs-MacBook-Pro.local>
| -rw-r--r-- | Blinkme_spi.ino | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/Blinkme_spi.ino b/Blinkme_spi.ino new file mode 100644 index 0000000..44ae27d --- /dev/null +++ b/Blinkme_spi.ino @@ -0,0 +1,87 @@ + + + +#include <SPI.h> + +// * CS - to digital pin 10 (SS pin) +// * SDI - to digital pin 11 (MOSI pin) +// * SDI - to digitak 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; + + + +void setup() { + Serial.begin (115200); // debugging + 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(0, OUTPUT); + pinMode(1, OUTPUT); + pinMode(2, OUTPUT); + pinMode(3, OUTPUT); + + // ... und so weiter + + + // Initialize SPI + // SPI.begin(); +} + +//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; + if (c == '\n') + { + process_it = true; + } + } +} + + +void loop() +{ + + //Verarbeitung der empfangenen Nachricht + if (process_it == true) + { + recieve_buff[pos]=0; + Serial.println (recieve_buff); + pos = 0; + process_it == false; + } + +Serial.println("huhu"); + +} + |
