diff options
author | Cristian Maglie <c.maglie@bug.st> | 2012-06-27 13:51:16 +0200 |
---|---|---|
committer | Cristian Maglie <c.maglie@bug.st> | 2012-06-27 13:51:16 +0200 |
commit | 2d2050eabeaff7109ba89fdd0100556c981cf373 (patch) | |
tree | 1f6d9725b59aa02e5400a8117eeec3206d88047d /libraries/SPI | |
parent | 324023a67afd1691f12ead4388d7cdf1a9d1a6ef (diff) | |
parent | 31c24577835b0a9c7a1291ffbda1b61d96818511 (diff) |
Merged master
Diffstat (limited to 'libraries/SPI')
-rw-r--r-- | libraries/SPI/SPI.cpp | 27 |
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); } |