From 0aec45afbcbc09930e42e81b5b66e48320bb3542 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Mon, 2 Aug 2010 22:33:11 +0000 Subject: [PATCH] Moving SPI pin definitions into core (from SPI library): SS, MISO, MOSI, and SCK. --- hardware/arduino/cores/arduino/pins_arduino.h | 12 +++++++++ libraries/SPI/SPI.cpp | 25 +++++++------------ 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/hardware/arduino/cores/arduino/pins_arduino.h b/hardware/arduino/cores/arduino/pins_arduino.h index c7e40fda6..2e335655d 100644 --- a/hardware/arduino/cores/arduino/pins_arduino.h +++ b/hardware/arduino/cores/arduino/pins_arduino.h @@ -49,6 +49,18 @@ #define TIMER5B 15 #define TIMER5C 16 +#if defined(__AVR_ATmega1280__) +const static uint8_t SS = 53; +const static uint8_t MOSI = 51; +const static uint8_t MISO = 50; +const static uint8_t SCK = 52; +#else +const static uint8_t SS = 10; +const static uint8_t MOSI = 11; +const static uint8_t MISO = 12; +const static uint8_t SCK = 13; +#endif + // On the ATmega1280, the addresses of some of the port registers are // greater than 255, so we can't store them in uint8_t's. extern const uint16_t PROGMEM port_to_mode_PGM[]; diff --git a/libraries/SPI/SPI.cpp b/libraries/SPI/SPI.cpp index 2c6ba9d80..ade6f5f39 100644 --- a/libraries/SPI/SPI.cpp +++ b/libraries/SPI/SPI.cpp @@ -8,34 +8,27 @@ * published by the Free Software Foundation. */ +#include "pins_arduino.h" #include "SPI.h" SPIClass SPI; SPIClass::SPIClass() { -#if defined(__AVR_ATmega1280__) - // PBx - const static byte SS = 0; - const static byte MOSI = 2; - const static byte MISO = 3; - const static byte SCK = 1; -#else - // PBx - const static byte SS = 2; - const static byte MOSI = 3; - const static byte MISO = 4; - const static byte SCK = 5; -#endif - // Set direction register for SCK and MOSI pin. // MISO pin automatically overrides to INPUT. // When the SS pin is set as OUTPUT, it can be used as // a general purpose output port (it doesn't influence // SPI operations). - DDRB |= _BV(SCK) | _BV(MOSI) | _BV(SS); - PORTB &= ~(_BV(SCK) | _BV(MOSI) | _BV(SS)); + pinMode(SCK, OUTPUT); + pinMode(MOSI, OUTPUT); + pinMode(SS, OUTPUT); + + digitalWrite(SCK, LOW); + digitalWrite(MOSI, LOW); + digitalWrite(SS, LOW); + SPCR = _BV(SPE) | _BV(MSTR); // Warning: if the SS pin ever becomes a LOW INPUT then SPI