aboutsummaryrefslogtreecommitdiff
path: root/libraries/SPI/SPI.cpp
diff options
context:
space:
mode:
authorCristian Maglie <c.maglie@bug.st>2012-06-26 00:51:35 +0200
committerCristian Maglie <c.maglie@bug.st>2012-06-26 00:51:35 +0200
commit79521e1a15f4d8778b07477cf1f61b6c0e74b7b9 (patch)
tree421853a5f6634228bb601d9ff7506f949095aadd /libraries/SPI/SPI.cpp
parent386e059e7e6b4703e800b1b9154d52cd9b280d3e (diff)
parent2ef2f9d5c78ad4a1d265b7386e13c41d41ba410a (diff)
Merged upstream Arduino master branch
Diffstat (limited to 'libraries/SPI/SPI.cpp')
-rw-r--r--libraries/SPI/SPI.cpp27
1 files changed, 16 insertions, 11 deletions
diff --git a/libraries/SPI/SPI.cpp b/libraries/SPI/SPI.cpp
index 42915df..5e48073 100644
--- a/libraries/SPI/SPI.cpp
+++ b/libraries/SPI/SPI.cpp
@@ -14,27 +14,32 @@
SPIClass SPI;
void SPIClass::begin() {
- // Set direction register for SCK and MOSI pin.
- // MISO pin automatically overrides to INPUT.
+
+ // Set SS to high so a connected chip will be "deselected" by default
+ digitalWrite(SS, HIGH);
+
// When the SS pin is set as OUTPUT, it can be used as
// a general purpose output port (it doesn't influence
// SPI operations).
-
- pinMode(SCK, OUTPUT);
- pinMode(MOSI, OUTPUT);
pinMode(SS, OUTPUT);
-
- digitalWrite(SCK, LOW);
- digitalWrite(MOSI, LOW);
- digitalWrite(SS, HIGH);
- // Warning: if the SS pin ever becomes a LOW INPUT then SPI
- // automatically switches to Slave, so the data direction of
+ // Warning: if the SS pin ever becomes a LOW INPUT then SPI
+ // automatically switches to Slave, so the data direction of
// the SS pin MUST be kept as OUTPUT.
SPCR |= _BV(MSTR);
SPCR |= _BV(SPE);
+
+ // Set direction register for SCK and MOSI pin.
+ // MISO pin automatically overrides to INPUT.
+ // By doing this AFTER enabling SPI, we avoid accidentally
+ // clocking in a single bit since the lines go directly
+ // from "input" to SPI control.
+ // http://code.google.com/p/arduino/issues/detail?id=888
+ pinMode(SCK, OUTPUT);
+ pinMode(MOSI, OUTPUT);
}
+
void SPIClass::end() {
SPCR &= ~_BV(SPE);
}