Skip to content

Commit

Permalink
Merge pull request #375 from sparkfun/Fix_#355
Browse files Browse the repository at this point in the history
Fix #355
  • Loading branch information
nseidle committed Jun 20, 2024
2 parents fcaf7ca + 8c49438 commit 494cc24
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
18 changes: 15 additions & 3 deletions Firmware/RTK_Everywhere/Begin.ino
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,6 @@ void beginBoard()

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

Expand Down Expand Up @@ -483,6 +482,19 @@ void beginVersion()
}
}

void beginSPI(bool force) // Call after beginBoard
{
static bool started = false;

bool spiNeeded = present.ethernet_ws5500 || present.microSd;

if (force || (spiNeeded && !started))
{
SPI.begin(pin_SCK, pin_POCI, pin_PICO);
started = true;
}
}

void beginSD()
{
if (present.microSd == false)
Expand Down Expand Up @@ -624,7 +636,7 @@ void resetSPI()
sdDeselectCard();

// Flush SPI interface
SPI.begin(pin_SCK, pin_POCI, pin_PICO);
beginSPI(true);
SPI.beginTransaction(SPISettings(400000, MSBFIRST, SPI_MODE0));
for (int x = 0; x < 10; x++)
SPI.transfer(0XFF);
Expand All @@ -634,7 +646,7 @@ void resetSPI()
sdSelectCard();

// Flush SD interface
SPI.begin(pin_SCK, pin_POCI, pin_PICO);
beginSPI(true);
SPI.beginTransaction(SPISettings(400000, MSBFIRST, SPI_MODE0));
for (int x = 0; x < 10; x++)
SPI.transfer(0XFF);
Expand Down
5 changes: 5 additions & 0 deletions Firmware/RTK_Everywhere/RTK_Everywhere.ino
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ unsigned long syncRTCInterval = 1000; // To begin, sync RTC every second. Interv
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#include <SPI.h> //Built-in

void beginSPI(bool force = false); // Header

#include "SdFat.h" //http://librarymanager/All#sdfat_exfat by Bill Greiman. Currently uses v2.1.1
SdFat *sd;

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

DMW_b("beginSPI");
beginSPI(); // Begin SPI as needed

DMW_b("beginFS");
beginFS(); // Start the LittleFS file system in the spiffs partition

Expand Down
1 change: 0 additions & 1 deletion Firmware/RTK_Everywhere/SD.ino
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ bool sdCardPresent(void)

bool sdCardPresentSoftwareTest()
{
SPI.begin(pin_SCK, pin_POCI, pin_PICO);
SPI.setClockDivider(SPI_CLOCK_DIV2);
SPI.setDataMode(SPI_MODE0);
SPI.setBitOrder(MSBFIRST);
Expand Down

0 comments on commit 494cc24

Please sign in to comment.