Skip to content

Commit 494cc24

Browse files
authored
Merge pull request #375 from sparkfun/Fix_#355
Fix #355
2 parents fcaf7ca + 8c49438 commit 494cc24

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

Firmware/RTK_Everywhere/Begin.ino

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,6 @@ void beginBoard()
324324

325325
// In the fullness of time, pin_Cellular_PWR_ON will (probably) be controlled by the Cellular Library
326326
DMW_if systemPrintf("pin_Cellular_PWR_ON: %d\r\n", pin_Cellular_PWR_ON);
327-
digitalWrite(pin_Cellular_PWR_ON, LOW);
328327
pinMode(pin_Cellular_PWR_ON, OUTPUT);
329328
digitalWrite(pin_Cellular_PWR_ON, LOW);
330329

@@ -483,6 +482,19 @@ void beginVersion()
483482
}
484483
}
485484

485+
void beginSPI(bool force) // Call after beginBoard
486+
{
487+
static bool started = false;
488+
489+
bool spiNeeded = present.ethernet_ws5500 || present.microSd;
490+
491+
if (force || (spiNeeded && !started))
492+
{
493+
SPI.begin(pin_SCK, pin_POCI, pin_PICO);
494+
started = true;
495+
}
496+
}
497+
486498
void beginSD()
487499
{
488500
if (present.microSd == false)
@@ -624,7 +636,7 @@ void resetSPI()
624636
sdDeselectCard();
625637

626638
// Flush SPI interface
627-
SPI.begin(pin_SCK, pin_POCI, pin_PICO);
639+
beginSPI(true);
628640
SPI.beginTransaction(SPISettings(400000, MSBFIRST, SPI_MODE0));
629641
for (int x = 0; x < 10; x++)
630642
SPI.transfer(0XFF);
@@ -634,7 +646,7 @@ void resetSPI()
634646
sdSelectCard();
635647

636648
// Flush SD interface
637-
SPI.begin(pin_SCK, pin_POCI, pin_PICO);
649+
beginSPI(true);
638650
SPI.beginTransaction(SPISettings(400000, MSBFIRST, SPI_MODE0));
639651
for (int x = 0; x < 10; x++)
640652
SPI.transfer(0XFF);

Firmware/RTK_Everywhere/RTK_Everywhere.ino

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ unsigned long syncRTCInterval = 1000; // To begin, sync RTC every second. Interv
202202
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
203203
#include <SPI.h> //Built-in
204204

205+
void beginSPI(bool force = false); // Header
206+
205207
#include "SdFat.h" //http://librarymanager/All#sdfat_exfat by Bill Greiman. Currently uses v2.1.1
206208
SdFat *sd;
207209

@@ -1004,6 +1006,9 @@ void setup()
10041006
DMW_b("beginBoard");
10051007
beginBoard(); // Set all pin numbers and pin initial states
10061008

1009+
DMW_b("beginSPI");
1010+
beginSPI(); // Begin SPI as needed
1011+
10071012
DMW_b("beginFS");
10081013
beginFS(); // Start the LittleFS file system in the spiffs partition
10091014

Firmware/RTK_Everywhere/SD.ino

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ bool sdCardPresent(void)
138138

139139
bool sdCardPresentSoftwareTest()
140140
{
141-
SPI.begin(pin_SCK, pin_POCI, pin_PICO);
142141
SPI.setClockDivider(SPI_CLOCK_DIV2);
143142
SPI.setDataMode(SPI_MODE0);
144143
SPI.setBitOrder(MSBFIRST);

0 commit comments

Comments
 (0)