2323// ------------------------------------------------------------------------------
2424#ifndef SOFTWARE_SPI
2525#ifdef USE_SPI_LIB
26+
27+ #ifndef SDCARD_SPI
28+ #define SDCARD_SPI SPI
29+ #endif
30+
2631#include < SPI.h>
2732static SPISettings settings;
2833#endif
@@ -34,7 +39,7 @@ static void spiSend(uint8_t b) {
3439 while (!(SPSR & (1 << SPIF)))
3540 ;
3641#else
37- SPI .transfer (b);
42+ SDCARD_SPI .transfer (b);
3843#endif
3944}
4045/* * Receive a byte from the card */
@@ -43,7 +48,7 @@ static uint8_t spiRec(void) {
4348 spiSend (0XFF );
4449 return SPDR;
4550#else
46- return SPI .transfer (0xFF );
51+ return SDCARD_SPI .transfer (0xFF );
4752#endif
4853}
4954#else // SOFTWARE_SPI
@@ -164,7 +169,7 @@ void Sd2Card::chipSelectHigh(void) {
164169#ifdef USE_SPI_LIB
165170 if (chip_select_asserted) {
166171 chip_select_asserted = 0 ;
167- SPI .endTransaction ();
172+ SDCARD_SPI .endTransaction ();
168173 }
169174#endif
170175}
@@ -173,7 +178,7 @@ void Sd2Card::chipSelectLow(void) {
173178#ifdef USE_SPI_LIB
174179 if (!chip_select_asserted) {
175180 chip_select_asserted = 1 ;
176- SPI .beginTransaction (settings);
181+ SDCARD_SPI .beginTransaction (settings);
177182 }
178183#endif
179184 digitalWrite (chipSelectPin_, LOW);
@@ -265,18 +270,18 @@ uint8_t Sd2Card::init(uint8_t sckRateID, uint8_t chipSelectPin) {
265270 // clear double speed
266271 SPSR &= ~(1 << SPI2X);
267272#else // USE_SPI_LIB
268- SPI .begin ();
273+ SDCARD_SPI .begin ();
269274 settings = SPISettings (250000 , MSBFIRST, SPI_MODE0);
270275#endif // USE_SPI_LIB
271276#endif // SOFTWARE_SPI
272277
273278 // must supply min of 74 clock cycles with CS high.
274279#ifdef USE_SPI_LIB
275- SPI .beginTransaction (settings);
280+ SDCARD_SPI .beginTransaction (settings);
276281#endif
277282 for (uint8_t i = 0 ; i < 10 ; i++) spiSend (0XFF );
278283#ifdef USE_SPI_LIB
279- SPI .endTransaction ();
284+ SDCARD_SPI .endTransaction ();
280285#endif
281286
282287 chipSelectLow ();
0 commit comments