Skip to content
This repository was archived by the owner on Jan 28, 2021. It is now read-only.

Commit 79679f8

Browse files
committed
Add getVal8/16/32. Add a bunch of keys.
1 parent 55bb4a2 commit 79679f8

File tree

6 files changed

+262
-52
lines changed

6 files changed

+262
-52
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
Configuring port settings using the newer getVal/setVal methods
3+
By: Nathan Seidle
4+
SparkFun Electronics
5+
Date: October 23rd, 2020
6+
License: MIT. See license file for more information but you can
7+
basically do whatever you want with this code.
8+
9+
This example shows how to query a u-blox module for its UART1 settings and
10+
then change them if the settings aren't what we want.
11+
12+
Note: getVal/setVal/delVal are only support in u-blox protocol versions 27 and higher.
13+
14+
Feel like supporting open source hardware?
15+
Buy a board from SparkFun!
16+
ZED-F9P RTK2: https://www.sparkfun.com/products/15136
17+
NEO-M8P RTK: https://www.sparkfun.com/products/15005
18+
SAM-M8Q: https://www.sparkfun.com/products/15106
19+
20+
Hardware Connections:
21+
Plug a Qwiic cable into the GPS and a RedBoard
22+
If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425)
23+
Open the serial monitor at 115200 baud to see the output
24+
*/
25+
26+
#include <Wire.h> //Needed for I2C to GPS
27+
28+
#include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_Ublox_GPS
29+
SFE_UBLOX_GPS myGPS;
30+
31+
void setup()
32+
{
33+
Serial.begin(115200);
34+
while (!Serial)
35+
; //Wait for user to open terminal
36+
Serial.println("SparkFun u-blox Example");
37+
38+
Wire.begin();
39+
40+
if (myGPS.begin() == false) //Connect to the Ublox module using Wire port
41+
{
42+
Serial.println(F("u-blox GPS not detected at default I2C address. Please check wiring. Freezing."));
43+
while (1)
44+
;
45+
}
46+
47+
//Read the settings from RAM (what the module is running right now, not BBR, Flash, or default)
48+
uint8_t currentUART1Setting_ubx = myGPS.getVal8(UBLOX_CFG_UART1INPROT_UBX);
49+
uint8_t currentUART1Setting_nmea = myGPS.getVal8(UBLOX_CFG_UART1INPROT_NMEA);
50+
uint8_t currentUART1Setting_rtcm3 = myGPS.getVal8(UBLOX_CFG_UART1INPROT_RTCM3X);
51+
52+
Serial.print("currentUART1Setting_ubx: ");
53+
Serial.println(currentUART1Setting_ubx);
54+
Serial.print("currentUART1Setting_nmea: ");
55+
Serial.println(currentUART1Setting_nmea);
56+
Serial.print("currentUART1Setting_rtcm3: ");
57+
Serial.println(currentUART1Setting_rtcm3);
58+
59+
//Check if NMEA and RTCM are enabled for UART1
60+
if (currentUART1Setting_ubx == 0 || currentUART1Setting_nmea == 0)
61+
{
62+
Serial.println("Updating UART1 configuration");
63+
64+
//setVal sets the values for RAM, BBR, and Flash automatically so no .saveConfiguration() is needed
65+
bool response = true;
66+
response &= myGPS.setVal8(UBLOX_CFG_UART1INPROT_UBX, 1); //Enable UBX on UART1 Input
67+
response &= myGPS.setVal8(UBLOX_CFG_UART1INPROT_NMEA, 1); //Enable NMEA on UART1 Input
68+
response &= myGPS.setVal8(UBLOX_CFG_UART1INPROT_RTCM3X, 0); //Disable RTCM on UART1 Input
69+
70+
if (response == false)
71+
Serial.println("SetVal failed");
72+
else
73+
Serial.println("SetVal succeeded");
74+
}
75+
else
76+
Serial.println("Nothing to change");
77+
78+
Serial.println("Done");
79+
}
80+
81+
void loop()
82+
{
83+
}

examples/ZED-F9P/Example6_GetVal/Example6_GetVal.ino

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*
2-
Send UBX binary commands to enable RTCM sentences on Ublox ZED-F9P module
2+
Get a device's I2C address using advanced getVal method
33
By: Nathan Seidle
44
SparkFun Electronics
55
Date: January 9th, 2019
66
License: MIT. See license file for more information but you can
77
basically do whatever you want with this code.
88
9-
Ublox changed how to configure their modules in 2019. As of version 23 of the UBX protocol the
9+
u-blox changed how to configure their modules in 2019. As of version 23 of the UBX protocol the
1010
UBX-CFG commands are deprecated; they still work, they just recommend using VALSET, VALGET, and VALDEL
1111
commands instead. This example shows how to use this new command structure.
1212
@@ -32,27 +32,31 @@ long lastTime = 0; //Simple local timer. Limits amount if I2C traffic to Ublox m
3232
void setup()
3333
{
3434
Serial.begin(115200);
35-
while (!Serial); //Wait for user to open terminal
36-
Serial.println("Ublox getVal example");
35+
while (!Serial)
36+
; //Wait for user to open terminal
37+
Serial.println("u-blox getVal example");
3738

3839
Wire.begin();
3940
Wire.setClock(400000); //Increase I2C clock speed to 400kHz
4041

4142
if (myGPS.begin() == false) //Connect to the Ublox module using Wire port
4243
{
43-
Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing."));
44-
while (1);
44+
Serial.println(F("u-blox GPS not detected at default I2C address. Please check wiring. Freezing."));
45+
while (1)
46+
;
4547
}
4648

4749
myGPS.enableDebugging(); //Enable debug messages over Serial (default)
4850
//myGPS.enableDebugging(SerialUSB); //Enable debug messages over Serial USB
4951

50-
uint8_t currentI2Caddress = myGPS.getVal8(0x20510001);
52+
#define UBLOX_CFG_I2C_ADDRESS 0x20510001
53+
54+
uint8_t currentI2Caddress = myGPS.getVal8(UBLOX_CFG_I2C_ADDRESS);
5155
Serial.print("Current I2C address (should be 0x42): 0x");
5256
Serial.println(currentI2Caddress >> 1, HEX); //Ublox module returns a shifted 8-bit address. Make it 7-bit unshifted.
5357

54-
while(1);
55-
58+
while (1)
59+
;
5660
}
5761

5862
void loop()
@@ -83,4 +87,4 @@ void loop()
8387

8488
Serial.println();
8589
}
86-
}
90+
}

keywords.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ setUART2Output KEYWORD2
6464
setUSBOutput KEYWORD2
6565
setSPIOutput KEYWORD2
6666

67+
getVal KEYWORD2
6768
getVal8 KEYWORD2
69+
getVal16 KEYWORD2
70+
getVal32 KEYWORD2
6871
setVal KEYWORD2
6972
setVal8 KEYWORD2
7073
setVal16 KEYWORD2

src/SparkFun_Ublox_Arduino_Library.cpp

Lines changed: 52 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
This is a library written for the Ublox ZED-F9P and NEO-M8P-2
33
SparkFun sells these at its website: www.sparkfun.com
44
Do you like this library? Help support SparkFun. Buy a board!
5+
https://www.sparkfun.com/products/16481
56
https://www.sparkfun.com/products/15136
67
https://www.sparkfun.com/products/15005
78
https://www.sparkfun.com/products/15733
@@ -1639,32 +1640,11 @@ boolean SFE_UBLOX_GPS::factoryDefault(uint16_t maxWait)
16391640
return (sendCommand(&packetCfg, maxWait) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK
16401641
}
16411642

1642-
//Given a group, ID and size, return the value of this config spot
1643-
//The 32-bit key is put together from group/ID/size. See other getVal to send key directly.
1644-
//Configuration of modern Ublox modules is now done via getVal/setVal/delVal, ie protocol v27 and above found on ZED-F9P
1645-
uint8_t SFE_UBLOX_GPS::getVal8(uint16_t group, uint16_t id, uint8_t size, uint8_t layer, uint16_t maxWait)
1646-
{
1647-
//Create key
1648-
uint32_t key = 0;
1649-
key |= (uint32_t)id;
1650-
key |= (uint32_t)group << 16;
1651-
key |= (uint32_t)size << 28;
1652-
1653-
if (_printDebug == true)
1654-
{
1655-
_debugSerial->print(F("key: 0x"));
1656-
_debugSerial->print(key, HEX);
1657-
_debugSerial->println();
1658-
}
1659-
1660-
return getVal8(key, layer, maxWait);
1661-
}
1662-
1663-
//Given a key, return its value
1643+
//Given a key, load the payload with data that can then be extracted to 8, 16, or 32 bits
16641644
//This function takes a full 32-bit key
16651645
//Default layer is RAM
1666-
//Configuration of modern Ublox modules is now done via getVal/setVal/delVal, ie protocol v27 and above found on ZED-F9P
1667-
uint8_t SFE_UBLOX_GPS::getVal8(uint32_t key, uint8_t layer, uint16_t maxWait)
1646+
//Configuration of modern u-blox modules is now done via getVal/setVal/delVal, ie protocol v27 and above found on ZED-F9P
1647+
sfe_ublox_status_e SFE_UBLOX_GPS::getVal(uint32_t key, uint8_t layer, uint16_t maxWait)
16681648
{
16691649
packetCfg.cls = UBX_CLASS_CFG;
16701650
packetCfg.id = UBX_CFG_VALGET;
@@ -1710,17 +1690,61 @@ uint8_t SFE_UBLOX_GPS::getVal8(uint32_t key, uint8_t layer, uint16_t maxWait)
17101690
_debugSerial->print(F("getVal8: sendCommand returned: "));
17111691
_debugSerial->println(statusString(retVal));
17121692
}
1713-
if (retVal != SFE_UBLOX_STATUS_DATA_RECEIVED) // We are expecting data and an ACK
1714-
return (0); //If command send fails then bail
17151693

17161694
//Verify the response is the correct length as compared to what the user called (did the module respond with 8-bits but the user called getVal32?)
17171695
//Response is 8 bytes plus cfg data
17181696
//if(packet->len > 8+1)
17191697

1720-
//Pull the requested value from the response
1721-
//Response starts at 4+1*N with the 32-bit key so the actual data we're looking for is at 8+1*N
1698+
//The response is now sitting in payload, ready for extraction
1699+
return (retVal);
1700+
}
1701+
1702+
//Given a key, return its value
1703+
//This function takes a full 32-bit key
1704+
//Default layer is RAM
1705+
//Configuration of modern Ublox modules is now done via getVal/setVal/delVal, ie protocol v27 and above found on ZED-F9P
1706+
uint8_t SFE_UBLOX_GPS::getVal8(uint32_t key, uint8_t layer, uint16_t maxWait)
1707+
{
1708+
if (getVal(key, layer, maxWait) != SFE_UBLOX_STATUS_DATA_RECEIVED)
1709+
return (0);
1710+
17221711
return (extractByte(8));
17231712
}
1713+
uint16_t SFE_UBLOX_GPS::getVal16(uint32_t key, uint8_t layer, uint16_t maxWait)
1714+
{
1715+
if (getVal(key, layer, maxWait) != SFE_UBLOX_STATUS_DATA_RECEIVED)
1716+
return (0);
1717+
1718+
return (extractInt(8));
1719+
}
1720+
uint32_t SFE_UBLOX_GPS::getVal32(uint32_t key, uint8_t layer, uint16_t maxWait)
1721+
{
1722+
if (getVal(key, layer, maxWait) != SFE_UBLOX_STATUS_DATA_RECEIVED)
1723+
return (0);
1724+
1725+
return (extractLong(8));
1726+
}
1727+
1728+
//Given a group, ID and size, return the value of this config spot
1729+
//The 32-bit key is put together from group/ID/size. See other getVal to send key directly.
1730+
//Configuration of modern Ublox modules is now done via getVal/setVal/delVal, ie protocol v27 and above found on ZED-F9P
1731+
uint8_t SFE_UBLOX_GPS::getVal8(uint16_t group, uint16_t id, uint8_t size, uint8_t layer, uint16_t maxWait)
1732+
{
1733+
//Create key
1734+
uint32_t key = 0;
1735+
key |= (uint32_t)id;
1736+
key |= (uint32_t)group << 16;
1737+
key |= (uint32_t)size << 28;
1738+
1739+
if (_printDebug == true)
1740+
{
1741+
_debugSerial->print(F("key: 0x"));
1742+
_debugSerial->print(key, HEX);
1743+
_debugSerial->println();
1744+
}
1745+
1746+
return getVal8(key, layer, maxWait);
1747+
}
17241748

17251749
//Given a key, set a 16-bit value
17261750
//This function takes a full 32-bit key

src/SparkFun_Ublox_Arduino_Library.h

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
This is a library written for the Ublox ZED-F9P and NEO-M8P-2
33
SparkFun sells these at its website: www.sparkfun.com
44
Do you like this library? Help support SparkFun. Buy a board!
5+
https://www.sparkfun.com/products/16481
56
https://www.sparkfun.com/products/15136
67
https://www.sparkfun.com/products/15005
78
https://www.sparkfun.com/products/15733
@@ -555,21 +556,25 @@ class SFE_UBLOX_GPS
555556
//General configuration (used only on protocol v27 and higher - ie, ZED-F9P)
556557
//It is probably safe to assume that users of the ZED-F9P will be using I2C / Qwiic.
557558
//If they are using Serial then the higher baud rate will also help. So let's leave maxWait set to 250ms.
559+
sfe_ublox_status_e getVal(uint32_t keyID, uint8_t layer = VAL_LAYER_RAM, uint16_t maxWait = 250); //Load payload with response
560+
uint8_t getVal8(uint32_t keyID, uint8_t layer = VAL_LAYER_RAM, uint16_t maxWait = 250); //Returns the value at a given key location
561+
uint16_t getVal16(uint32_t keyID, uint8_t layer = VAL_LAYER_RAM, uint16_t maxWait = 250); //Returns the value at a given key location
562+
uint32_t getVal32(uint32_t keyID, uint8_t layer = VAL_LAYER_RAM, uint16_t maxWait = 250); //Returns the value at a given key location
558563
uint8_t getVal8(uint16_t group, uint16_t id, uint8_t size, uint8_t layer = VAL_LAYER_RAM, uint16_t maxWait = 250); //Returns the value at a given group/id/size location
559-
uint8_t getVal8(uint32_t keyID, uint8_t layer = VAL_LAYER_RAM, uint16_t maxWait = 250); //Returns the value at a given group/id/size location
560-
uint8_t setVal(uint32_t keyID, uint16_t value, uint8_t layer = VAL_LAYER_ALL, uint16_t maxWait = 250); //Sets the 16-bit value at a given group/id/size location
561-
uint8_t setVal8(uint32_t keyID, uint8_t value, uint8_t layer = VAL_LAYER_ALL, uint16_t maxWait = 250); //Sets the 8-bit value at a given group/id/size location
562-
uint8_t setVal16(uint32_t keyID, uint16_t value, uint8_t layer = VAL_LAYER_ALL, uint16_t maxWait = 250); //Sets the 16-bit value at a given group/id/size location
563-
uint8_t setVal32(uint32_t keyID, uint32_t value, uint8_t layer = VAL_LAYER_ALL, uint16_t maxWait = 250); //Sets the 32-bit value at a given group/id/size location
564-
uint8_t newCfgValset8(uint32_t keyID, uint8_t value, uint8_t layer = VAL_LAYER_BBR); //Define a new UBX-CFG-VALSET with the given KeyID and 8-bit value
565-
uint8_t newCfgValset16(uint32_t keyID, uint16_t value, uint8_t layer = VAL_LAYER_BBR); //Define a new UBX-CFG-VALSET with the given KeyID and 16-bit value
566-
uint8_t newCfgValset32(uint32_t keyID, uint32_t value, uint8_t layer = VAL_LAYER_BBR); //Define a new UBX-CFG-VALSET with the given KeyID and 32-bit value
567-
uint8_t addCfgValset8(uint32_t keyID, uint8_t value); //Add a new KeyID and 8-bit value to an existing UBX-CFG-VALSET ubxPacket
568-
uint8_t addCfgValset16(uint32_t keyID, uint16_t value); //Add a new KeyID and 16-bit value to an existing UBX-CFG-VALSET ubxPacket
569-
uint8_t addCfgValset32(uint32_t keyID, uint32_t value); //Add a new KeyID and 32-bit value to an existing UBX-CFG-VALSET ubxPacket
570-
uint8_t sendCfgValset8(uint32_t keyID, uint8_t value, uint16_t maxWait = 250); //Add the final KeyID and 8-bit value to an existing UBX-CFG-VALSET ubxPacket and send it
571-
uint8_t sendCfgValset16(uint32_t keyID, uint16_t value, uint16_t maxWait = 250); //Add the final KeyID and 16-bit value to an existing UBX-CFG-VALSET ubxPacket and send it
572-
uint8_t sendCfgValset32(uint32_t keyID, uint32_t value, uint16_t maxWait = 250); //Add the final KeyID and 32-bit value to an existing UBX-CFG-VALSET ubxPacket and send it
564+
565+
uint8_t setVal(uint32_t keyID, uint16_t value, uint8_t layer = VAL_LAYER_ALL, uint16_t maxWait = 250); //Sets the 16-bit value at a given group/id/size location
566+
uint8_t setVal8(uint32_t keyID, uint8_t value, uint8_t layer = VAL_LAYER_ALL, uint16_t maxWait = 250); //Sets the 8-bit value at a given group/id/size location
567+
uint8_t setVal16(uint32_t keyID, uint16_t value, uint8_t layer = VAL_LAYER_ALL, uint16_t maxWait = 250); //Sets the 16-bit value at a given group/id/size location
568+
uint8_t setVal32(uint32_t keyID, uint32_t value, uint8_t layer = VAL_LAYER_ALL, uint16_t maxWait = 250); //Sets the 32-bit value at a given group/id/size location
569+
uint8_t newCfgValset8(uint32_t keyID, uint8_t value, uint8_t layer = VAL_LAYER_BBR); //Define a new UBX-CFG-VALSET with the given KeyID and 8-bit value
570+
uint8_t newCfgValset16(uint32_t keyID, uint16_t value, uint8_t layer = VAL_LAYER_BBR); //Define a new UBX-CFG-VALSET with the given KeyID and 16-bit value
571+
uint8_t newCfgValset32(uint32_t keyID, uint32_t value, uint8_t layer = VAL_LAYER_BBR); //Define a new UBX-CFG-VALSET with the given KeyID and 32-bit value
572+
uint8_t addCfgValset8(uint32_t keyID, uint8_t value); //Add a new KeyID and 8-bit value to an existing UBX-CFG-VALSET ubxPacket
573+
uint8_t addCfgValset16(uint32_t keyID, uint16_t value); //Add a new KeyID and 16-bit value to an existing UBX-CFG-VALSET ubxPacket
574+
uint8_t addCfgValset32(uint32_t keyID, uint32_t value); //Add a new KeyID and 32-bit value to an existing UBX-CFG-VALSET ubxPacket
575+
uint8_t sendCfgValset8(uint32_t keyID, uint8_t value, uint16_t maxWait = 250); //Add the final KeyID and 8-bit value to an existing UBX-CFG-VALSET ubxPacket and send it
576+
uint8_t sendCfgValset16(uint32_t keyID, uint16_t value, uint16_t maxWait = 250); //Add the final KeyID and 16-bit value to an existing UBX-CFG-VALSET ubxPacket and send it
577+
uint8_t sendCfgValset32(uint32_t keyID, uint32_t value, uint16_t maxWait = 250); //Add the final KeyID and 32-bit value to an existing UBX-CFG-VALSET ubxPacket and send it
573578

574579
//Functions used for RTK and base station setup
575580
//It is probably safe to assume that users of the RTK will be using I2C / Qwiic. So let's leave maxWait set to 250ms.

0 commit comments

Comments
 (0)