From 0be173050e0ca524b0cce62acb118114689c32f0 Mon Sep 17 00:00:00 2001 From: Paul <5690545+PaulZC@users.noreply.github.com> Date: Sat, 25 Jul 2020 13:10:50 +0100 Subject: [PATCH] Changes by PaulZC --- .../Example22_PowerOff/Example22_PowerOff.ino | 17 +++--- keywords.txt | 4 +- src/SparkFun_Ublox_Arduino_Library.cpp | 59 +++++++++---------- src/SparkFun_Ublox_Arduino_Library.h | 8 ++- 4 files changed, 46 insertions(+), 42 deletions(-) diff --git a/examples/Example22_PowerOff/Example22_PowerOff.ino b/examples/Example22_PowerOff/Example22_PowerOff.ino index d1c8b45..90ae355 100644 --- a/examples/Example22_PowerOff/Example22_PowerOff.ino +++ b/examples/Example22_PowerOff/Example22_PowerOff.ino @@ -32,12 +32,12 @@ SFE_UBLOX_GPS myGPS; // define a digital pin capable of driving HIGH and LOW #define WAKEUP_PIN 5 -// interrupt pin mapping -#define GPS_RX 0 -#define GPS_INT0 1 -#define GPS_INT1 2 -#define GPS_SPI_CS 3 - +// Possible GNSS interrupt pins for powerOffWithInterrupt are: +// VAL_RXM_PMREQ_WAKEUPSOURCE_UARTRX = uartrx +// VAL_RXM_PMREQ_WAKEUPSOURCE_EXTINT0 = extint0 (default) +// VAL_RXM_PMREQ_WAKEUPSOURCE_EXTINT1 = extint1 +// VAL_RXM_PMREQ_WAKEUPSOURCE_SPICS = spics +// These values can be or'd (|) together to enable interrupts on multiple pins void wakeUp() { @@ -55,6 +55,7 @@ void wakeUp() { void setup() { pinMode(WAKEUP_PIN, OUTPUT); + digitalWrite(WAKEUP_PIN, LOW); Serial.begin(115200); while (!Serial); //Wait for user to open terminal @@ -62,6 +63,8 @@ void setup() { Wire.begin(); + //myGPS.enableDebugging(); // Enable debug messages + if (myGPS.begin() == false) //Connect to the Ublox module using Wire port { Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing.")); @@ -72,7 +75,7 @@ void setup() { Serial.println("-- Powering off module for 20s --"); myGPS.powerOff(20000); - // myGPS.powerOffWithInterrupt(20000, GPS_INT0); + //myGPS.powerOffWithInterrupt(20000, VAL_RXM_PMREQ_WAKEUPSOURCE_EXTINT0); delay(10000); diff --git a/keywords.txt b/keywords.txt index 72d4636..0b5d1d5 100644 --- a/keywords.txt +++ b/keywords.txt @@ -139,8 +139,8 @@ setDynamicModel KEYWORD2 getDynamicModel KEYWORD2 powerSaveMode KEYWORD2 getPowerSaveMode KEYWORD2 -powerOff KEYWORD2 -powerOffWithInterrupt KEYWORD2 +powerOff KEYWORD2 +powerOffWithInterrupt KEYWORD2 configureMessage KEYWORD2 enableMessage KEYWORD2 diff --git a/src/SparkFun_Ublox_Arduino_Library.cpp b/src/SparkFun_Ublox_Arduino_Library.cpp index a0da8cd..4a5857e 100644 --- a/src/SparkFun_Ublox_Arduino_Library.cpp +++ b/src/SparkFun_Ublox_Arduino_Library.cpp @@ -2596,6 +2596,11 @@ boolean SFE_UBLOX_GPS::powerOff(uint32_t durationInMs, uint16_t maxWait) payloadCfg[2] = (durationInMs >> (8*2)) & 0xff; payloadCfg[3] = (durationInMs >> (8*3)) & 0xff; + payloadCfg[4] = 0x02; //Flags : set the backup bit + payloadCfg[5] = 0x00; //Flags + payloadCfg[6] = 0x00; //Flags + payloadCfg[7] = 0x00; //Flags + if (maxWait != 0) { // check for "not acknowledged" command @@ -2614,7 +2619,7 @@ boolean SFE_UBLOX_GPS::powerOff(uint32_t durationInMs, uint16_t maxWait) // NOTE: Querying the device before the duration is complete, for example by "getLatitude()" will wake it up! // Returns true if command has not been not acknowledged. // Returns false if command has not been acknowledged or maxWait = 0. -boolean SFE_UBLOX_GPS::powerOffWithInterrupt(uint32_t durationInMs, uint8_t wakeupPin, boolean forceWhileUsb, uint16_t maxWait) +boolean SFE_UBLOX_GPS::powerOffWithInterrupt(uint32_t durationInMs, uint32_t wakeupSources, boolean forceWhileUsb, uint16_t maxWait) { // use durationInMs = 0 for infinite duration if (_printDebug == true) @@ -2631,7 +2636,11 @@ boolean SFE_UBLOX_GPS::powerOffWithInterrupt(uint32_t durationInMs, uint8_t wake packetCfg.startingSpot = 0; payloadCfg[0] = 0x00; // message version - // bytes 1-3 are reserved + + // bytes 1-3 are reserved - and must be set to zero + payloadCfg[1] = 0x00; + payloadCfg[2] = 0x00; + payloadCfg[3] = 0x00; // duration // big endian to little endian, switch byte order @@ -2641,49 +2650,35 @@ boolean SFE_UBLOX_GPS::powerOffWithInterrupt(uint32_t durationInMs, uint8_t wake payloadCfg[7] = (durationInMs >> (8*3)) & 0xff; // flags - payloadCfg[8] = 0x00; - payloadCfg[9] = 0x00; - payloadCfg[10] = 0x00; // disables USB interface when powering off, defaults to true if (forceWhileUsb) { - payloadCfg[11] = 0x04; + payloadCfg[8] = 0x06; // force | backup } else { - payloadCfg[11] = 0x02; + payloadCfg[8] = 0x02; // backup only (leave the force bit clear - module will stay on if USB is connected) } - // wakeUpSources - payloadCfg[12] = 0x00; - payloadCfg[13] = 0x00; - payloadCfg[14] = 0x00; - - // wakeupPin mapping, defaults to EXINT0, limited to one pin for now - // last byte of wakeUpSources - uint8_t terminatingByte; - - switch (wakeupPin) - { - case 0: // UART RX - terminatingByte = 0x08; // 0000 1000 - break; + payloadCfg[9] = 0x00; + payloadCfg[10] = 0x00; + payloadCfg[11] = 0x00; - case 1: // EXINT 0 - terminatingByte = 0x20; // 0010 0000 - break; + // wakeUpSources - case 2: // EXINT 1 - terminatingByte = 0x40; // 0100 0000 - break; + // wakeupPin mapping, defaults to VAL_RXM_PMREQ_WAKEUPSOURCE_EXTINT0 - case 3: // SPI CS - terminatingByte = 0x80; // 1000 0000 - break; - } + // Possible values are: + // VAL_RXM_PMREQ_WAKEUPSOURCE_UARTRX + // VAL_RXM_PMREQ_WAKEUPSOURCE_EXTINT0 + // VAL_RXM_PMREQ_WAKEUPSOURCE_EXTINT1 + // VAL_RXM_PMREQ_WAKEUPSOURCE_SPICS - payloadCfg[15] = terminatingByte; + payloadCfg[12] = (wakeupSources >> (8*0)) & 0xff; + payloadCfg[13] = (wakeupSources >> (8*1)) & 0xff; + payloadCfg[14] = (wakeupSources >> (8*2)) & 0xff; + payloadCfg[15] = (wakeupSources >> (8*3)) & 0xff; if (maxWait != 0) { diff --git a/src/SparkFun_Ublox_Arduino_Library.h b/src/SparkFun_Ublox_Arduino_Library.h index 50265bf..96c0e0a 100644 --- a/src/SparkFun_Ublox_Arduino_Library.h +++ b/src/SparkFun_Ublox_Arduino_Library.h @@ -407,6 +407,12 @@ const uint32_t VAL_CFG_SUBSEC_ANTCONF = 0x00000400; // antConf - antenna config const uint32_t VAL_CFG_SUBSEC_LOGCONF = 0x00000800; // logConf - logging configuration const uint32_t VAL_CFG_SUBSEC_FTSCONF = 0x00001000; // ftsConf - FTS configuration (FTS products only) +// Bitfield wakeupSources for UBX_RXM_PMREQ +const uint32_t VAL_RXM_PMREQ_WAKEUPSOURCE_UARTRX = 0x00000008; // uartrx +const uint32_t VAL_RXM_PMREQ_WAKEUPSOURCE_EXTINT0 = 0x00000020; // extint0 +const uint32_t VAL_RXM_PMREQ_WAKEUPSOURCE_EXTINT1 = 0x00000040; // extint1 +const uint32_t VAL_RXM_PMREQ_WAKEUPSOURCE_SPICS = 0x00000080; // spics + enum dynModel // Possible values for the dynamic platform model, which provide more accuract position output for the situation. Description extracted from ZED-F9P Integration Manual { DYN_MODEL_PORTABLE = 0, //Applications with low acceleration, e.g. portable devices. Suitable for most situations. @@ -642,7 +648,7 @@ class SFE_UBLOX_GPS boolean powerSaveMode(bool power_save = true, uint16_t maxWait = 1100); uint8_t getPowerSaveMode(uint16_t maxWait = 1100); // Returns 255 if the sendCommand fails boolean powerOff(uint32_t durationInMs, uint16_t maxWait = 1100); - boolean powerOffWithInterrupt(uint32_t durationInMs, uint8_t wakeupPin = 1, boolean forceWhileUsb = true, uint16_t maxWait = 1100); + boolean powerOffWithInterrupt(uint32_t durationInMs, uint32_t wakeupSources = VAL_RXM_PMREQ_WAKEUPSOURCE_EXTINT0, boolean forceWhileUsb = true, uint16_t maxWait = 1100); //Change the dynamic platform model using UBX-CFG-NAV5 boolean setDynamicModel(dynModel newDynamicModel = DYN_MODEL_PORTABLE, uint16_t maxWait = 1100);