Skip to content

Commit 32bb703

Browse files
committed
Fix #355
1 parent fcaf7ca commit 32bb703

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

Firmware/RTK_Everywhere/Begin.ino

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,19 @@ void beginVersion()
483483
}
484484
}
485485

486+
void beginSPI(bool force) // Call after beginBoard
487+
{
488+
static bool started = false;
489+
490+
bool spiNeeded = present.ethernet_ws5500 || present.microSd;
491+
492+
if (force || (spiNeeded && !started))
493+
{
494+
SPI.begin(pin_SCK, pin_POCI, pin_PICO);
495+
started = true;
496+
}
497+
}
498+
486499
void beginSD()
487500
{
488501
if (present.microSd == false)
@@ -624,7 +637,7 @@ void resetSPI()
624637
sdDeselectCard();
625638

626639
// Flush SPI interface
627-
SPI.begin(pin_SCK, pin_POCI, pin_PICO);
640+
beginSPI(true);
628641
SPI.beginTransaction(SPISettings(400000, MSBFIRST, SPI_MODE0));
629642
for (int x = 0; x < 10; x++)
630643
SPI.transfer(0XFF);
@@ -634,7 +647,7 @@ void resetSPI()
634647
sdSelectCard();
635648

636649
// Flush SD interface
637-
SPI.begin(pin_SCK, pin_POCI, pin_PICO);
650+
beginSPI(true);
638651
SPI.beginTransaction(SPISettings(400000, MSBFIRST, SPI_MODE0));
639652
for (int x = 0; x < 10; x++)
640653
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)