From 33f5dd2024bedcb2f9036853b728d94bccdbfd47 Mon Sep 17 00:00:00 2001 From: PaulZC Date: Thu, 9 Dec 2021 13:10:36 +0000 Subject: [PATCH] Add softReset as an option for .begin --- keywords.txt | 1 + src/SparkFun_u-blox_GNSS_Arduino_Library.cpp | 82 +++++++++++++++++++- src/SparkFun_u-blox_GNSS_Arduino_Library.h | 9 ++- 3 files changed, 84 insertions(+), 8 deletions(-) diff --git a/keywords.txt b/keywords.txt index 60f06f1..3aad233 100644 --- a/keywords.txt +++ b/keywords.txt @@ -121,6 +121,7 @@ setNMEAOutputPort KEYWORD2 factoryReset KEYWORD2 hardReset KEYWORD2 +softwareResetGNSSOnly KEYWORD2 factoryDefault KEYWORD2 saveConfiguration KEYWORD2 diff --git a/src/SparkFun_u-blox_GNSS_Arduino_Library.cpp b/src/SparkFun_u-blox_GNSS_Arduino_Library.cpp index 6fd38aa..8320188 100644 --- a/src/SparkFun_u-blox_GNSS_Arduino_Library.cpp +++ b/src/SparkFun_u-blox_GNSS_Arduino_Library.cpp @@ -438,7 +438,7 @@ void SFE_UBLOX_GNSS::setPacketCfgPayloadSize(size_t payloadSize) } //Initialize the I2C port -bool SFE_UBLOX_GNSS::begin(TwoWire &wirePort, uint8_t deviceAddress, uint16_t maxWait) +bool SFE_UBLOX_GNSS::begin(TwoWire &wirePort, uint8_t deviceAddress, uint16_t maxWait, bool softReset) { commType = COMM_TYPE_I2C; _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 //New in v2.0: allocate memory for the file buffer - if required. (The user should have called setFileBufferSize already) createFileBuffer(); + //Issue a soft reset to clear the buffers + if (softReset) + softwareResetGNSSOnly(); + // Call isConnected up to three times - tests on the NEO-M8U show the CFG RATE poll occasionally being ignored bool connected = isConnected(maxWait); if (!connected) + { +#ifndef SFE_UBLOX_REDUCED_PROG_MEM + if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging + { + _debugSerial->println(F("begin: isConnected - second attempt")); + } +#endif connected = isConnected(maxWait); + } if (!connected) + { +#ifndef SFE_UBLOX_REDUCED_PROG_MEM + if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging + { + _debugSerial->println(F("begin: isConnected - third attempt")); + } +#endif connected = isConnected(maxWait); + } return (connected); } //Initialize the Serial port -bool SFE_UBLOX_GNSS::begin(Stream &serialPort, uint16_t maxWait) +bool SFE_UBLOX_GNSS::begin(Stream &serialPort, uint16_t maxWait, bool softReset) { commType = COMM_TYPE_SERIAL; _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) //New in v2.0: allocate memory for the file buffer - if required. (The user should have called setFileBufferSize already) createFileBuffer(); + //Issue a soft reset to clear the buffers + if (softReset) + softwareResetGNSSOnly(); + // Call isConnected up to three times - tests on the NEO-M8U show the CFG RATE poll occasionally being ignored bool connected = isConnected(maxWait); if (!connected) + { +#ifndef SFE_UBLOX_REDUCED_PROG_MEM + if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging + { + _debugSerial->println(F("begin: isConnected - second attempt")); + } +#endif connected = isConnected(maxWait); + } if (!connected) + { +#ifndef SFE_UBLOX_REDUCED_PROG_MEM + if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging + { + _debugSerial->println(F("begin: isConnected - third attempt")); + } +#endif connected = isConnected(maxWait); + } return (connected); } // Initialize for SPI -bool SFE_UBLOX_GNSS::begin(SPIClass &spiPort, uint8_t csPin, uint32_t spiSpeed, uint16_t maxWait) +bool SFE_UBLOX_GNSS::begin(SPIClass &spiPort, uint8_t csPin, uint32_t spiSpeed, uint16_t maxWait, bool softReset) { commType = COMM_TYPE_SPI; _spiPort = &spiPort; @@ -538,14 +578,34 @@ bool SFE_UBLOX_GNSS::begin(SPIClass &spiPort, uint8_t csPin, uint32_t spiSpeed, } } - // Call isConnected up to three times + //Issue a soft reset to clear the buffers + if (softReset) + softwareResetGNSSOnly(); + + // Call isConnected up to three times - tests on the NEO-M8U show the CFG RATE poll occasionally being ignored bool connected = isConnected(maxWait); if (!connected) + { +#ifndef SFE_UBLOX_REDUCED_PROG_MEM + if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging + { + _debugSerial->println(F("begin: isConnected - second attempt")); + } +#endif connected = isConnected(maxWait); + } if (!connected) + { +#ifndef SFE_UBLOX_REDUCED_PROG_MEM + if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging + { + _debugSerial->println(F("begin: isConnected - third attempt")); + } +#endif connected = isConnected(maxWait); + } return (connected); } @@ -5413,6 +5473,20 @@ void SFE_UBLOX_GNSS::hardReset() sendCommand(&packetCfg, 0); // don't expect ACK } +void SFE_UBLOX_GNSS::softwareResetGNSSOnly() +{ + // Issue controlled software reset (GNSS only) + packetCfg.cls = UBX_CLASS_CFG; + packetCfg.id = UBX_CFG_RST; + packetCfg.len = 4; + packetCfg.startingSpot = 0; + payloadCfg[0] = 0; // hot start + payloadCfg[1] = 0; // hot start + payloadCfg[2] = 0x02; // 0x02 = Controlled software reset (GNSS only) + payloadCfg[3] = 0; // reserved + sendCommand(&packetCfg, 0); // don't expect ACK +} + //Reset module to factory defaults //This still works but it is the old way of configuring ublox modules. See getVal and setVal for the new methods bool SFE_UBLOX_GNSS::factoryDefault(uint16_t maxWait) diff --git a/src/SparkFun_u-blox_GNSS_Arduino_Library.h b/src/SparkFun_u-blox_GNSS_Arduino_Library.h index e0f866e..e5dbb61 100644 --- a/src/SparkFun_u-blox_GNSS_Arduino_Library.h +++ b/src/SparkFun_u-blox_GNSS_Arduino_Library.h @@ -599,11 +599,11 @@ public: void setPacketCfgPayloadSize(size_t payloadSize); // Set packetCfgPayloadSize //By default use the default I2C address, and use Wire port - bool begin(TwoWire &wirePort = Wire, uint8_t deviceAddress = 0x42, uint16_t maxWait = defaultMaxWait); //Returns true if module is detected + bool begin(TwoWire &wirePort = Wire, uint8_t deviceAddress = 0x42, uint16_t maxWait = defaultMaxWait, bool softReset = false); //Returns true if module is detected //serialPort needs to be perviously initialized to correct baud rate - bool begin(Stream &serialPort, uint16_t maxWait = defaultMaxWait); //Returns true if module is detected + bool begin(Stream &serialPort, uint16_t maxWait = defaultMaxWait, bool softReset = false); //Returns true if module is detected //SPI - supply instance of SPIClass, chip select pin and SPI speed (in Hz) - bool begin(SPIClass &spiPort, uint8_t csPin, uint32_t spiSpeed, uint16_t maxWait = defaultMaxWait); + bool begin(SPIClass &spiPort, uint8_t csPin, uint32_t spiSpeed, uint16_t maxWait = defaultMaxWait, bool softReset = false); void end(void); //Stop all automatic message processing. Free all used RAM @@ -780,7 +780,8 @@ public: void factoryReset(); //Send factory reset sequence (i.e. load "default" configuration and perform hardReset) void hardReset(); //Perform a reset leading to a cold start (zero info start-up) - bool factoryDefault(uint16_t maxWait = defaultMaxWait); //Reset module to factory defaults + void softwareResetGNSSOnly(); //Controlled Software Reset (GNSS only) only restarts the GNSS tasks, without reinitializing the full system or reloading any stored configuration. + bool factoryDefault(uint16_t maxWait = defaultMaxWait); //Reset module to factory defaults //Save configuration to BBR / Flash