Skip to content

Commit 986cdce

Browse files
committed
Add assumeSuccess as a parameter for .begin
If you are using Serial, and the module is already outputting messages at high navigation rate, .begin can often fail due to traffic congestion. You can: - use a long maxWait (5 seconds seems to work well) - use a short maxWait and set assumeSuccess to true
1 parent 33f5dd2 commit 986cdce

File tree

2 files changed

+40
-20
lines changed

2 files changed

+40
-20
lines changed

src/SparkFun_u-blox_GNSS_Arduino_Library.cpp

+36-17
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ void SFE_UBLOX_GNSS::setPacketCfgPayloadSize(size_t payloadSize)
438438
}
439439

440440
//Initialize the I2C port
441-
bool SFE_UBLOX_GNSS::begin(TwoWire &wirePort, uint8_t deviceAddress, uint16_t maxWait, bool softReset)
441+
bool SFE_UBLOX_GNSS::begin(TwoWire &wirePort, uint8_t deviceAddress, uint16_t maxWait, bool assumeSuccess)
442442
{
443443
commType = COMM_TYPE_I2C;
444444
_i2cPort = &wirePort; //Grab which port the user wants us to use
@@ -460,10 +460,6 @@ bool SFE_UBLOX_GNSS::begin(TwoWire &wirePort, uint8_t deviceAddress, uint16_t ma
460460
//New in v2.0: allocate memory for the file buffer - if required. (The user should have called setFileBufferSize already)
461461
createFileBuffer();
462462

463-
//Issue a soft reset to clear the buffers
464-
if (softReset)
465-
softwareResetGNSSOnly();
466-
467463
// Call isConnected up to three times - tests on the NEO-M8U show the CFG RATE poll occasionally being ignored
468464
bool connected = isConnected(maxWait);
469465

@@ -489,11 +485,22 @@ bool SFE_UBLOX_GNSS::begin(TwoWire &wirePort, uint8_t deviceAddress, uint16_t ma
489485
connected = isConnected(maxWait);
490486
}
491487

488+
if ((!connected ) && assumeSuccess) // Advanced users can assume success if required. Useful if the port is outputting messages at high navigation rate.
489+
{
490+
#ifndef SFE_UBLOX_REDUCED_PROG_MEM
491+
if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging
492+
{
493+
_debugSerial->println(F("begin: third attempt failed. Assuming success..."));
494+
}
495+
#endif
496+
return (true);
497+
}
498+
492499
return (connected);
493500
}
494501

495502
//Initialize the Serial port
496-
bool SFE_UBLOX_GNSS::begin(Stream &serialPort, uint16_t maxWait, bool softReset)
503+
bool SFE_UBLOX_GNSS::begin(Stream &serialPort, uint16_t maxWait, bool assumeSuccess)
497504
{
498505
commType = COMM_TYPE_SERIAL;
499506
_serialPort = &serialPort; //Grab which port the user wants us to use
@@ -505,10 +512,6 @@ bool SFE_UBLOX_GNSS::begin(Stream &serialPort, uint16_t maxWait, bool softReset)
505512
//New in v2.0: allocate memory for the file buffer - if required. (The user should have called setFileBufferSize already)
506513
createFileBuffer();
507514

508-
//Issue a soft reset to clear the buffers
509-
if (softReset)
510-
softwareResetGNSSOnly();
511-
512515
// Call isConnected up to three times - tests on the NEO-M8U show the CFG RATE poll occasionally being ignored
513516
bool connected = isConnected(maxWait);
514517

@@ -534,11 +537,22 @@ bool SFE_UBLOX_GNSS::begin(Stream &serialPort, uint16_t maxWait, bool softReset)
534537
connected = isConnected(maxWait);
535538
}
536539

540+
if ((!connected ) && assumeSuccess) // Advanced users can assume success if required. Useful if the port is outputting messages at high navigation rate.
541+
{
542+
#ifndef SFE_UBLOX_REDUCED_PROG_MEM
543+
if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging
544+
{
545+
_debugSerial->println(F("begin: third attempt failed. Assuming success..."));
546+
}
547+
#endif
548+
return (true);
549+
}
550+
537551
return (connected);
538552
}
539553

540554
// Initialize for SPI
541-
bool SFE_UBLOX_GNSS::begin(SPIClass &spiPort, uint8_t csPin, uint32_t spiSpeed, uint16_t maxWait, bool softReset)
555+
bool SFE_UBLOX_GNSS::begin(SPIClass &spiPort, uint8_t csPin, uint32_t spiSpeed, uint16_t maxWait, bool assumeSuccess)
542556
{
543557
commType = COMM_TYPE_SPI;
544558
_spiPort = &spiPort;
@@ -578,10 +592,6 @@ bool SFE_UBLOX_GNSS::begin(SPIClass &spiPort, uint8_t csPin, uint32_t spiSpeed,
578592
}
579593
}
580594

581-
//Issue a soft reset to clear the buffers
582-
if (softReset)
583-
softwareResetGNSSOnly();
584-
585595
// Call isConnected up to three times - tests on the NEO-M8U show the CFG RATE poll occasionally being ignored
586596
bool connected = isConnected(maxWait);
587597

@@ -607,6 +617,17 @@ bool SFE_UBLOX_GNSS::begin(SPIClass &spiPort, uint8_t csPin, uint32_t spiSpeed,
607617
connected = isConnected(maxWait);
608618
}
609619

620+
if ((!connected ) && assumeSuccess) // Advanced users can assume success if required. Useful if the port is outputting messages at high navigation rate.
621+
{
622+
#ifndef SFE_UBLOX_REDUCED_PROG_MEM
623+
if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging
624+
{
625+
_debugSerial->println(F("begin: third attempt failed. Assuming success..."));
626+
}
627+
#endif
628+
return (true);
629+
}
630+
610631
return (connected);
611632
}
612633

@@ -9702,9 +9723,7 @@ bool SFE_UBLOX_GNSS::getNavigationFrequencyInternal(uint16_t maxWait)
97029723
return (true);
97039724

97049725
if (retVal == SFE_UBLOX_STATUS_DATA_OVERWRITTEN)
9705-
{
97069726
return (true);
9707-
}
97089727

97099728
return (false);
97109729
}

src/SparkFun_u-blox_GNSS_Arduino_Library.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -598,12 +598,13 @@ class SFE_UBLOX_GNSS
598598
//New in v2.0: allow the payload size for packetCfg to be changed
599599
void setPacketCfgPayloadSize(size_t payloadSize); // Set packetCfgPayloadSize
600600

601+
//Begin communication with the GNSS. Advanced users can assume success if required. Useful if the port is already outputting messages at high navigation rate.
601602
//By default use the default I2C address, and use Wire port
602-
bool begin(TwoWire &wirePort = Wire, uint8_t deviceAddress = 0x42, uint16_t maxWait = defaultMaxWait, bool softReset = false); //Returns true if module is detected
603+
bool begin(TwoWire &wirePort = Wire, uint8_t deviceAddress = 0x42, uint16_t maxWait = defaultMaxWait, bool assumeSuccess = false); //Returns true if module is detected
603604
//serialPort needs to be perviously initialized to correct baud rate
604-
bool begin(Stream &serialPort, uint16_t maxWait = defaultMaxWait, bool softReset = false); //Returns true if module is detected
605+
bool begin(Stream &serialPort, uint16_t maxWait = defaultMaxWait, bool assumeSuccess = false); //Returns true if module is detected
605606
//SPI - supply instance of SPIClass, chip select pin and SPI speed (in Hz)
606-
bool begin(SPIClass &spiPort, uint8_t csPin, uint32_t spiSpeed, uint16_t maxWait = defaultMaxWait, bool softReset = false);
607+
bool begin(SPIClass &spiPort, uint8_t csPin, uint32_t spiSpeed, uint16_t maxWait = defaultMaxWait, bool assumeSuccess = false);
607608

608609
void end(void); //Stop all automatic message processing. Free all used RAM
609610

0 commit comments

Comments
 (0)