Skip to content

Commit 60a183f

Browse files
authored
Merge pull request #68 from sparkfun/release_candidate
v3.1.8 - Adds "auto" support for UBX-MON-COMMS
2 parents bb33fa9 + d28022a commit 60a183f

File tree

8 files changed

+543
-7
lines changed

8 files changed

+543
-7
lines changed

examples/Basics/Example34_I2C_Serial_Passthrough/Example34_I2C_Serial_Passthrough.ino

+11-3
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ uint8_t uartI2cRingBuffer[ringBufferSize];
5050
uint16_t uartI2cBufferHead = 0;
5151
uint16_t uartI2cBufferTail = 0;
5252

53-
const unsigned long uartI2cSendInterval_ms = 50;
53+
const unsigned long uartI2cSendInterval_ms = 5;
5454
unsigned long uartI2cLastSend_ms = 0;
5555
const uint16_t uartI2cSendLimit = 16;
5656

57-
const unsigned long i2cUartSendInterval_ms = 50;
57+
const unsigned long i2cUartSendInterval_ms = 5;
5858
unsigned long i2cUartLastSend_ms = 0;
5959
const uint16_t i2cUartSendLimit = 16;
6060

@@ -66,12 +66,19 @@ const uint16_t i2cReadLimit = 16;
6666
void setup()
6767
{
6868

69-
delay(1000); // Wait for ESP32 to start up
69+
delay(2000); // Wait for ESP32 and GNSS to start up
7070

7171
mySerial.begin(115200); // Baud rate for u-center
7272

7373
myWire.begin(); // Start I2C
7474
myWire.setClock(400000); // 400kHz
75+
76+
// Give I2C a kickstart - if needed. Request UBX-MON-VER
77+
const uint8_t pollUbxMonVer[] = { 0xB5, 0x62, 0x0A, 0x04, 0x00, 0x00, 0x0E, 0x34 };
78+
for (int i = 0; i < (sizeof(pollUbxMonVer) / sizeof(uint8_t)); i++) {
79+
addToUartI2cBuffer(pollUbxMonVer[i]);
80+
}
81+
7582
} // /setup
7683

7784
void loop()
@@ -147,6 +154,7 @@ void loop()
147154
i2cUartLastSend_ms = millis();
148155
}
149156
}
157+
150158
} // /loop
151159

152160
// Read how many bytes are available in the GNSS I2C buffer.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
/*
2+
Configuring the GNSS to automatically send MON COMMS reports over I2C and display them using a callback
3+
By: Paul Clark
4+
SparkFun Electronics
5+
Date: Novenber 4th, 2024
6+
License: MIT. See license file for more information.
7+
8+
This example shows how to configure the u-blox GNSS to send MON COMMS reports automatically
9+
and access the data via a callback. No more polling!
10+
11+
Feel like supporting open source hardware?
12+
Buy a board from SparkFun!
13+
ZED-F9P RTK2: https://www.sparkfun.com/products/15136
14+
15+
Hardware Connections:
16+
Plug a Qwiic cable into the GPS and a BlackBoard
17+
If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425)
18+
Open the serial monitor at 115200 baud to see the output
19+
*/
20+
21+
#include <Wire.h> //Needed for I2C to GPS
22+
23+
#include <SparkFun_u-blox_GNSS_v3.h> //http://librarymanager/All#SparkFun_u-blox_GNSS_v3
24+
SFE_UBLOX_GNSS myGNSS;
25+
26+
// Callback: newMONCOMMS will be called when new MON COMMS data arrives
27+
// See u-blox_structs.h for the full definition of UBX_MON_COMMS_data_t
28+
// _____ You can use any name you like for the callback. Use the same name when you call setAutoMONCOMMScallback
29+
// / _____ This _must_ be UBX_MON_COMMS_data_t
30+
// | / _____ You can use any name you like for the struct
31+
// | | /
32+
// | | |
33+
void newMONCOMMS(UBX_MON_COMMS_data_t *ubxDataStruct)
34+
{
35+
Serial.println();
36+
37+
Serial.print(F("New MON COMMS data received. It contains data for "));
38+
Serial.print(ubxDataStruct->header.nPorts);
39+
if (ubxDataStruct->header.nPorts == 1)
40+
Serial.println(F(" port."));
41+
else
42+
Serial.println(F(" ports."));
43+
44+
// Mimic the data shown in u-center
45+
for (uint8_t port = 0; port < ubxDataStruct->header.nPorts; port++) // For each port
46+
{
47+
bool known = true;
48+
switch (ubxDataStruct->port[port].portId) // Check the port ID is valid
49+
{
50+
case COM_PORT_ID_I2C:
51+
case COM_PORT_ID_UART1:
52+
case COM_PORT_ID_UART2:
53+
case COM_PORT_ID_USB:
54+
case COM_PORT_ID_SPI:
55+
break;
56+
default:
57+
known = false;
58+
break;
59+
}
60+
if (!known)
61+
break; // Skip if port ID is not known
62+
63+
switch (ubxDataStruct->port[port].portId) // Print the port ID
64+
{
65+
case COM_PORT_ID_I2C:
66+
Serial.print(F("I2C "));
67+
break;
68+
case COM_PORT_ID_UART1:
69+
Serial.print(F("UART1 "));
70+
break;
71+
case COM_PORT_ID_UART2:
72+
Serial.print(F("UART2 "));
73+
break;
74+
case COM_PORT_ID_USB:
75+
Serial.print(F("USB "));
76+
break;
77+
case COM_PORT_ID_SPI:
78+
Serial.print(F("SPI "));
79+
break;
80+
default:
81+
Serial.print(F("UNKNOWN "));
82+
//Serial.printf("0x%04X ", ubxDataStruct->port[port].portId);
83+
break;
84+
}
85+
86+
Serial.print(": txBytes ");
87+
String txBytes = String(ubxDataStruct->port[port].txBytes);
88+
Serial.print(txBytes);
89+
for (int i = 0; i < 10 - txBytes.length(); i++)
90+
Serial.print(" ");
91+
92+
Serial.print(" : rxBytes ");
93+
String rxBytes = String(ubxDataStruct->port[port].rxBytes);
94+
Serial.print(rxBytes);
95+
for (int i = 0; i < 10 - rxBytes.length(); i++)
96+
Serial.print(" ");
97+
98+
for (int i = 0; i < 4; i++)
99+
{
100+
if (ubxDataStruct->header.protIds[i] < 0xFF)
101+
{
102+
switch (ubxDataStruct->header.protIds[i])
103+
{
104+
case 0:
105+
Serial.print(F(" : UBX "));
106+
break;
107+
case 1:
108+
Serial.print(F(" : NMEA "));
109+
break;
110+
case 2:
111+
Serial.print(F(" : RTCM2 "));
112+
break;
113+
case 5:
114+
Serial.print(F(" : RTCM3 "));
115+
break;
116+
case 6:
117+
Serial.print(F(" : SPARTN "));
118+
break;
119+
default:
120+
Serial.print(F(" : UNKNOWN "));
121+
break;
122+
}
123+
String msgs = String(ubxDataStruct->port[port].msgs[i]);
124+
Serial.print(msgs);
125+
for (int i = 0; i < 5 - msgs.length(); i++)
126+
Serial.print(" ");
127+
}
128+
}
129+
130+
Serial.print(" : skipped ");
131+
Serial.print(ubxDataStruct->port[port].skipped);
132+
133+
Serial.println();
134+
}
135+
}
136+
137+
void setup()
138+
{
139+
Serial.begin(115200);
140+
while (!Serial); //Wait for user to open terminal
141+
Serial.println("SparkFun u-blox Example");
142+
143+
Wire.begin();
144+
145+
//myGNSS.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial
146+
//myGNSS.enableDebugging(Serial, true); // Uncomment this line to enable only the major debug messages on Serial
147+
148+
if (myGNSS.begin() == false) //Connect to the u-blox module using Wire port
149+
{
150+
Serial.println(F("u-blox GNSS not detected at default I2C address. Please check wiring. Freezing."));
151+
while (1);
152+
}
153+
154+
myGNSS.setI2COutput(COM_TYPE_NMEA | COM_TYPE_UBX); //Set the I2C port to output NMEA and UBX
155+
myGNSS.saveConfigSelective(VAL_CFG_SUBSEC_IOPORT); //Save (only) the communications port settings to flash and BBR
156+
157+
myGNSS.setNavigationFrequency(1); //Produce one solution per second
158+
159+
// Just to prove we can, poll the MON COMMS data manually
160+
Serial.println("Polling MON COMMS data:");
161+
UBX_MON_COMMS_data_t portInfo;
162+
if (myGNSS.getCommsPortInfo(&portInfo))
163+
newMONCOMMS(&portInfo); // Call the callback manually to print the data
164+
else
165+
Serial.println("getCommsPortInfo failed!");
166+
167+
// Now enable automatic (periodic) MON COMMS messages with callback to newMONCOMMS
168+
myGNSS.setAutoMONCOMMScallbackPtr(&newMONCOMMS);
169+
}
170+
171+
void loop()
172+
{
173+
myGNSS.checkUblox(); // Check for the arrival of new data and process it.
174+
myGNSS.checkCallbacks(); // Check if any callbacks are waiting to be processed.
175+
176+
Serial.print(".");
177+
delay(50);
178+
}

keywords.txt

+9
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ setESFAutoAlignment KEYWORD2
233233

234234
getRFinformation KEYWORD2
235235

236+
getCommsPortInfo KEYWORD2
236237
getHWstatus KEYWORD2
237238
getAntennaStatus KEYWORD2
238239
getHW2status KEYWORD2
@@ -538,6 +539,14 @@ assumeAutoMONHW KEYWORD2
538539
flushMONHW KEYWORD2
539540
logMONHW KEYWORD2
540541

542+
getMONCOMMS KEYWORD2
543+
setAutoMONCOMMS KEYWORD2
544+
setAutoMONCOMMSrate KEYWORD2
545+
setAutoMONCOMMScallbackPtr KEYWORD2
546+
assumeAutoMONCOMMS KEYWORD2
547+
flushMONCOMMS KEYWORD2
548+
logMONCOMMS KEYWORD2
549+
541550
getEsfAlignment KEYWORD2
542551
getESFALG KEYWORD2
543552
setAutoESFALG KEYWORD2

library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=SparkFun u-blox GNSS v3
2-
version=3.1.7
2+
version=3.1.8
33
author=SparkFun Electronics <[email protected]>
44
maintainer=SparkFun Electronics <sparkfun.com>
55
sentence=Library for I2C, Serial and SPI Communication with u-blox GNSS modules<br/><br/>

src/u-blox_Class_and_ID.h

+8
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,14 @@ const uint8_t COM_PORT_UART2 = 2;
344344
const uint8_t COM_PORT_USB = 3;
345345
const uint8_t COM_PORT_SPI = 4;
346346

347+
// Port IDs used by MON-COMMS
348+
// UBX-18010802 - R15 also documents 0x0101 and 0x0200 - both are "Reserved"
349+
const uint16_t COM_PORT_ID_I2C = 0x0000; // Port IDs used by MON-COMMS
350+
const uint16_t COM_PORT_ID_UART1 = 0x0100;
351+
const uint16_t COM_PORT_ID_UART2 = 0x0201;
352+
const uint16_t COM_PORT_ID_USB = 0x0300;
353+
const uint16_t COM_PORT_ID_SPI = 0x0400;
354+
347355
const uint8_t COM_TYPE_UBX = (1 << 0);
348356
const uint8_t COM_TYPE_NMEA = (1 << 1);
349357
const uint8_t COM_TYPE_RTCM3 = (1 << 5);

0 commit comments

Comments
 (0)