mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-18 07:52:14 +01:00
fix SPI init issues as described http://code.google.com/p/arduino/issues/detail?id=888. Tested using qt1110 (mode 3) on a mega and WS5100 (webserver example sketch) chips on a etherten
This commit is contained in:
parent
308d907694
commit
a41c1233ba
@ -14,27 +14,34 @@
|
|||||||
SPIClass SPI;
|
SPIClass SPI;
|
||||||
|
|
||||||
void SPIClass::begin() {
|
void SPIClass::begin() {
|
||||||
// Set direction register for SCK and MOSI pin.
|
|
||||||
// MISO pin automatically overrides to INPUT.
|
// Set SS to high because many users use this as chip-select
|
||||||
|
// and most chips "select" when SS is high. If your chip
|
||||||
|
// does not, you can set it back to LOW after begin() is called.
|
||||||
|
digitalWrite(SS, HIGH);
|
||||||
|
|
||||||
// When the SS pin is set as OUTPUT, it can be used as
|
// When the SS pin is set as OUTPUT, it can be used as
|
||||||
// a general purpose output port (it doesn't influence
|
// a general purpose output port (it doesn't influence
|
||||||
// SPI operations).
|
// SPI operations).
|
||||||
|
|
||||||
pinMode(SCK, OUTPUT);
|
|
||||||
pinMode(MOSI, OUTPUT);
|
|
||||||
pinMode(SS, 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
|
// Warning: if the SS pin ever becomes a LOW INPUT then SPI
|
||||||
// automatically switches to Slave, so the data direction of
|
// automatically switches to Slave, so the data direction of
|
||||||
// the SS pin MUST be kept as OUTPUT.
|
// the SS pin MUST be kept as OUTPUT.
|
||||||
SPCR |= _BV(MSTR);
|
SPCR |= _BV(MSTR);
|
||||||
SPCR |= _BV(SPE);
|
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() {
|
void SPIClass::end() {
|
||||||
SPCR &= ~_BV(SPE);
|
SPCR &= ~_BV(SPE);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user