Skip to content

Commit 0e898d5

Browse files
vicatcufacchinm
authored andcommitted
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
1 parent 3750131 commit 0e898d5

File tree

1 file changed

+9
-1
lines changed
  • hardware/arduino/avr/libraries/SPI

1 file changed

+9
-1
lines changed

hardware/arduino/avr/libraries/SPI/SPI.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,15 @@ void SPIClass::begin()
2929
noInterrupts(); // Protect from a scheduler and prevent transactionBegin
3030
if (!initialized) {
3131
// Set SS to high so a connected chip will be "deselected" by default
32-
digitalWrite(SS, HIGH);
32+
uint8_t port = digitalPinToPort(SS);
33+
uint8_t bit = digitalPinToBitMask(SS);
34+
volatile uint8_t *reg = portModeRegister(port);
35+
36+
// if the SS pin is not already configured as an output
37+
// then set it high (to enable the internal pull-up resistor)
38+
if(!(*reg & bit)){
39+
digitalWrite(SS, HIGH);
40+
}
3341

3442
// When the SS pin is set as OUTPUT, it can be used as
3543
// a general purpose output port (it doesn't influence

0 commit comments

Comments
 (0)