aboutsummaryrefslogtreecommitdiff
path: root/libraries/SPI
diff options
context:
space:
mode:
authorVictor Aprea <victor.aprea@wickeddevice.com>2015-02-15 17:56:48 -0500
committerMartino Facchin <m.facchin@arduino.cc>2015-03-18 10:37:40 +0100
commit8fcf5c94067a052c2c7ead3c2ebcd1381ed37888 (patch)
tree6d97f0e74d1bf295c84ad7d6c410b651fa5fb4d0 /libraries/SPI
parent1da3da02ff9a1629fa419bce143062f9bb7d6f40 (diff)
Do not influence state of SS if it's already been set to an output previously, e.g. by user sketch
squashes and closes PR #2659
Diffstat (limited to 'libraries/SPI')
-rw-r--r--libraries/SPI/SPI.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/libraries/SPI/SPI.cpp b/libraries/SPI/SPI.cpp
index 9e7a116..af14e07 100644
--- a/libraries/SPI/SPI.cpp
+++ b/libraries/SPI/SPI.cpp
@@ -29,7 +29,15 @@ void SPIClass::begin()
noInterrupts(); // Protect from a scheduler and prevent transactionBegin
if (!initialized) {
// Set SS to high so a connected chip will be "deselected" by default
- digitalWrite(SS, HIGH);
+ uint8_t port = digitalPinToPort(SS);
+ uint8_t bit = digitalPinToBitMask(SS);
+ volatile uint8_t *reg = portModeRegister(port);
+
+ // if the SS pin is not already configured as an output
+ // then set it high (to enable the internal pull-up resistor)
+ if(!(*reg & bit)){
+ 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