Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix for bug 888: Allow the SPI library to support different modes and other subtle issues #95

Merged
merged 2 commits into from

2 participants

@gandrewstone

Tested using qt1110 (mode 3) on a mega and WS5100 (webserver example sketch) chips on a etherten.

@damellis damellis merged commit a363686 into arduino:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 5, 2012
  1. @gandrewstone

    fix SPI init issues as described http://code.google.com/p/arduino/iss…

    gandrewstone authored
    …ues/detail?id=888.  Tested using qt1110 (mode 3) on a mega and WS5100 (webserver example sketch) chips on a etherten
Commits on Jun 6, 2012
  1. @gandrewstone
This page is out of date. Refresh to see the latest.
Showing with 16 additions and 11 deletions.
  1. +16 −11 libraries/SPI/SPI.cpp
View
27 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);
}
Something went wrong with that request. Please try again.