Skip to content

Commit 33f5dd2

Browse files
committed
Add softReset as an option for .begin
1 parent 7c79921 commit 33f5dd2

3 files changed

+84
-8
lines changed

keywords.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ setNMEAOutputPort KEYWORD2
121121

122122
factoryReset KEYWORD2
123123
hardReset KEYWORD2
124+
softwareResetGNSSOnly KEYWORD2
124125
factoryDefault KEYWORD2
125126

126127
saveConfiguration KEYWORD2

src/SparkFun_u-blox_GNSS_Arduino_Library.cpp

Lines changed: 78 additions & 4 deletions
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)
441+
bool SFE_UBLOX_GNSS::begin(TwoWire &wirePort, uint8_t deviceAddress, uint16_t maxWait, bool softReset)
442442
{
443443
commType = COMM_TYPE_I2C;
444444
_i2cPort = &wirePort; //Grab which port the user wants us to use
@@ -460,20 +460,40 @@ 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+
463467
// Call isConnected up to three times - tests on the NEO-M8U show the CFG RATE poll occasionally being ignored
464468
bool connected = isConnected(maxWait);
465469

466470
if (!connected)
471+
{
472+
#ifndef SFE_UBLOX_REDUCED_PROG_MEM
473+
if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging
474+
{
475+
_debugSerial->println(F("begin: isConnected - second attempt"));
476+
}
477+
#endif
467478
connected = isConnected(maxWait);
479+
}
468480

469481
if (!connected)
482+
{
483+
#ifndef SFE_UBLOX_REDUCED_PROG_MEM
484+
if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging
485+
{
486+
_debugSerial->println(F("begin: isConnected - third attempt"));
487+
}
488+
#endif
470489
connected = isConnected(maxWait);
490+
}
471491

472492
return (connected);
473493
}
474494

475495
//Initialize the Serial port
476-
bool SFE_UBLOX_GNSS::begin(Stream &serialPort, uint16_t maxWait)
496+
bool SFE_UBLOX_GNSS::begin(Stream &serialPort, uint16_t maxWait, bool softReset)
477497
{
478498
commType = COMM_TYPE_SERIAL;
479499
_serialPort = &serialPort; //Grab which port the user wants us to use
@@ -485,20 +505,40 @@ bool SFE_UBLOX_GNSS::begin(Stream &serialPort, uint16_t maxWait)
485505
//New in v2.0: allocate memory for the file buffer - if required. (The user should have called setFileBufferSize already)
486506
createFileBuffer();
487507

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

491515
if (!connected)
516+
{
517+
#ifndef SFE_UBLOX_REDUCED_PROG_MEM
518+
if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging
519+
{
520+
_debugSerial->println(F("begin: isConnected - second attempt"));
521+
}
522+
#endif
492523
connected = isConnected(maxWait);
524+
}
493525

494526
if (!connected)
527+
{
528+
#ifndef SFE_UBLOX_REDUCED_PROG_MEM
529+
if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging
530+
{
531+
_debugSerial->println(F("begin: isConnected - third attempt"));
532+
}
533+
#endif
495534
connected = isConnected(maxWait);
535+
}
496536

497537
return (connected);
498538
}
499539

500540
// Initialize for SPI
501-
bool SFE_UBLOX_GNSS::begin(SPIClass &spiPort, uint8_t csPin, uint32_t spiSpeed, uint16_t maxWait)
541+
bool SFE_UBLOX_GNSS::begin(SPIClass &spiPort, uint8_t csPin, uint32_t spiSpeed, uint16_t maxWait, bool softReset)
502542
{
503543
commType = COMM_TYPE_SPI;
504544
_spiPort = &spiPort;
@@ -538,14 +578,34 @@ bool SFE_UBLOX_GNSS::begin(SPIClass &spiPort, uint8_t csPin, uint32_t spiSpeed,
538578
}
539579
}
540580

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

544588
if (!connected)
589+
{
590+
#ifndef SFE_UBLOX_REDUCED_PROG_MEM
591+
if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging
592+
{
593+
_debugSerial->println(F("begin: isConnected - second attempt"));
594+
}
595+
#endif
545596
connected = isConnected(maxWait);
597+
}
546598

547599
if (!connected)
600+
{
601+
#ifndef SFE_UBLOX_REDUCED_PROG_MEM
602+
if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging
603+
{
604+
_debugSerial->println(F("begin: isConnected - third attempt"));
605+
}
606+
#endif
548607
connected = isConnected(maxWait);
608+
}
549609

550610
return (connected);
551611
}
@@ -5413,6 +5473,20 @@ void SFE_UBLOX_GNSS::hardReset()
54135473
sendCommand(&packetCfg, 0); // don't expect ACK
54145474
}
54155475

5476+
void SFE_UBLOX_GNSS::softwareResetGNSSOnly()
5477+
{
5478+
// Issue controlled software reset (GNSS only)
5479+
packetCfg.cls = UBX_CLASS_CFG;
5480+
packetCfg.id = UBX_CFG_RST;
5481+
packetCfg.len = 4;
5482+
packetCfg.startingSpot = 0;
5483+
payloadCfg[0] = 0; // hot start
5484+
payloadCfg[1] = 0; // hot start
5485+
payloadCfg[2] = 0x02; // 0x02 = Controlled software reset (GNSS only)
5486+
payloadCfg[3] = 0; // reserved
5487+
sendCommand(&packetCfg, 0); // don't expect ACK
5488+
}
5489+
54165490
//Reset module to factory defaults
54175491
//This still works but it is the old way of configuring ublox modules. See getVal and setVal for the new methods
54185492
bool SFE_UBLOX_GNSS::factoryDefault(uint16_t maxWait)

src/SparkFun_u-blox_GNSS_Arduino_Library.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -599,11 +599,11 @@ class SFE_UBLOX_GNSS
599599
void setPacketCfgPayloadSize(size_t payloadSize); // Set packetCfgPayloadSize
600600

601601
//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); //Returns true if module is detected
602+
bool begin(TwoWire &wirePort = Wire, uint8_t deviceAddress = 0x42, uint16_t maxWait = defaultMaxWait, bool softReset = false); //Returns true if module is detected
603603
//serialPort needs to be perviously initialized to correct baud rate
604-
bool begin(Stream &serialPort, uint16_t maxWait = defaultMaxWait); //Returns true if module is detected
604+
bool begin(Stream &serialPort, uint16_t maxWait = defaultMaxWait, bool softReset = false); //Returns true if module is detected
605605
//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);
606+
bool begin(SPIClass &spiPort, uint8_t csPin, uint32_t spiSpeed, uint16_t maxWait = defaultMaxWait, bool softReset = false);
607607

608608
void end(void); //Stop all automatic message processing. Free all used RAM
609609

@@ -780,7 +780,8 @@ class SFE_UBLOX_GNSS
780780

781781
void factoryReset(); //Send factory reset sequence (i.e. load "default" configuration and perform hardReset)
782782
void hardReset(); //Perform a reset leading to a cold start (zero info start-up)
783-
bool factoryDefault(uint16_t maxWait = defaultMaxWait); //Reset module to factory defaults
783+
void softwareResetGNSSOnly(); //Controlled Software Reset (GNSS only) only restarts the GNSS tasks, without reinitializing the full system or reloading any stored configuration.
784+
bool factoryDefault(uint16_t maxWait = defaultMaxWait); //Reset module to factory defaults
784785

785786
//Save configuration to BBR / Flash
786787

0 commit comments

Comments
 (0)