1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-30 16:24:09 +03:00

Moving SPI pin initialization from constructor to begin() function. That way, the SPI library won't alter any pin states unless / until you call begin().

This commit is contained in:
David A. Mellis
2010-08-07 21:24:49 +00:00
parent 08feacbb40
commit b89d8a9c11
5 changed files with 20 additions and 23 deletions

View File

@ -13,8 +13,7 @@
SPIClass SPI;
SPIClass::SPIClass()
{
void SPIClass::begin() {
// Set direction register for SCK and MOSI pin.
// MISO pin automatically overrides to INPUT.
// When the SS pin is set as OUTPUT, it can be used as
@ -29,12 +28,15 @@ SPIClass::SPIClass()
digitalWrite(MOSI, LOW);
digitalWrite(SS, HIGH);
SPCR = _BV(SPE) | _BV(MSTR);
// 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(SPE) | _BV(MSTR);
SPCR |= _BV(MSTR);
SPCR |= _BV(SPE);
}
void SPIClass::end() {
SPCR &= ~_BV(SPE);
}
void SPIClass::setBitOrder(uint8_t bitOrder)