protect AVR SPCR & SPSR

This commit is contained in:
Felix Rusu 2018-04-04 10:36:23 -04:00
parent 66b428bb62
commit 09f09b923c
1 changed files with 6 additions and 0 deletions

View File

@ -56,8 +56,10 @@ void SPIFlash::select() {
#ifndef SPI_HAS_TRANSACTION #ifndef SPI_HAS_TRANSACTION
noInterrupts(); noInterrupts();
#endif #endif
#if defined (SPCR) && defined (SPSR)
_SPCR = SPCR; _SPCR = SPCR;
_SPSR = SPSR; _SPSR = SPSR;
#endif
#ifdef SPI_HAS_TRANSACTION #ifdef SPI_HAS_TRANSACTION
SPI.beginTransaction(_settings); SPI.beginTransaction(_settings);
@ -80,15 +82,19 @@ void SPIFlash::unselect() {
#else #else
interrupts(); interrupts();
#endif #endif
#if defined (SPCR) && defined (SPSR)
SPCR = _SPCR; SPCR = _SPCR;
SPSR = _SPSR; SPSR = _SPSR;
#endif
} }
/// setup SPI, read device ID etc... /// setup SPI, read device ID etc...
boolean SPIFlash::initialize() boolean SPIFlash::initialize()
{ {
#if defined (SPCR) && defined (SPSR)
_SPCR = SPCR; _SPCR = SPCR;
_SPSR = SPSR; _SPSR = SPSR;
#endif
pinMode(_slaveSelectPin, OUTPUT); pinMode(_slaveSelectPin, OUTPUT);
#ifdef SPI_HAS_TRANSACTION #ifdef SPI_HAS_TRANSACTION
_settings = SPISettings(4000000, MSBFIRST, SPI_MODE0); _settings = SPISettings(4000000, MSBFIRST, SPI_MODE0);