@@ -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
54185492bool SFE_UBLOX_GNSS::factoryDefault(uint16_t maxWait)
0 commit comments