3131
3232// Setup the u-blox module for any setup (base or rover)
3333// In general we check if the setting is incorrect before writing it. Otherwise, the set commands have, on rare occasion, become
34- // corrupt. The worst is when the I2C port gets turned off or the I2C address gets borked. We should only have to configure
35- // a fresh u-blox module once and never again.
34+ // corrupt. The worst is when the I2C port gets turned off or the I2C address gets borked.
3635bool configureUbloxModule ()
3736{
3837 boolean response = true ;
38+ int maxWait = 2000 ;
39+
40+ i2cGNSS.checkUblox (); // Regularly poll to get latest data and any RTCM
41+
42+ // The first thing we do is go to 1Hz to lighten any I2C traffic from a previous configuration
43+ if (i2cGNSS.getNavigationFrequency (maxWait) != 1 )
44+ response &= i2cGNSS.setNavigationFrequency (1 , maxWait);
45+ if (response == false )
46+ Serial.println (F (" Set rate failed" ));
3947
4048#define OUTPUT_SETTING 14
4149#define INPUT_SETTING 12
@@ -65,6 +73,8 @@ bool configureUbloxModule()
6573 response &= i2cGNSS.setPortInput (COM_PORT_UART2, COM_TYPE_RTCM3); // Set the UART2 to input RTCM
6674 }
6775
76+ // Turn on RTCM over I2C port so that we can harvest RTCM over I2C and send out over WiFi
77+ // This is easier than parsing over UART because the library handles the frame detection
6878 getPortSettings (COM_PORT_I2C); // Load the settingPayload with this port's settings
6979 if (settingPayload[OUTPUT_SETTING] != (COM_TYPE_UBX | COM_TYPE_NMEA | COM_TYPE_RTCM3) || settingPayload[INPUT_SETTING] != COM_TYPE_UBX)
7080 {
@@ -101,7 +111,6 @@ bool configureUbloxModule()
101111 if (response == false )
102112 {
103113 Serial.println (F (" Module failed initial config." ));
104- return (false );
105114 }
106115
107116 // Based on current settings, update the logging options within the GNSS library
@@ -255,18 +264,20 @@ bool disableNMEASentences(uint8_t portType)
255264bool enableRTCMSentences (uint8_t portType)
256265{
257266 bool response = true ;
267+ int maxWait = 1000 ; // When I2C traffic is large during logging, give extra time
268+
258269 if (getRTCMSettings (UBX_RTCM_1005, portType) != 1 )
259- response &= i2cGNSS.enableRTCMmessage (UBX_RTCM_1005, portType, 1 ); // Enable message 1005 to output through UART2, message every second
270+ response &= i2cGNSS.enableRTCMmessage (UBX_RTCM_1005, portType, 1 , maxWait ); // Enable message 1005 to output through UART2, message every second
260271 if (getRTCMSettings (UBX_RTCM_1074, portType) != 1 )
261- response &= i2cGNSS.enableRTCMmessage (UBX_RTCM_1074, portType, 1 );
272+ response &= i2cGNSS.enableRTCMmessage (UBX_RTCM_1074, portType, 1 , maxWait );
262273 if (getRTCMSettings (UBX_RTCM_1084, portType) != 1 )
263- response &= i2cGNSS.enableRTCMmessage (UBX_RTCM_1084, portType, 1 );
274+ response &= i2cGNSS.enableRTCMmessage (UBX_RTCM_1084, portType, 1 , maxWait );
264275 if (getRTCMSettings (UBX_RTCM_1094, portType) != 1 )
265- response &= i2cGNSS.enableRTCMmessage (UBX_RTCM_1094, portType, 1 );
276+ response &= i2cGNSS.enableRTCMmessage (UBX_RTCM_1094, portType, 1 , maxWait );
266277 if (getRTCMSettings (UBX_RTCM_1124, portType) != 1 )
267- response &= i2cGNSS.enableRTCMmessage (UBX_RTCM_1124, portType, 1 );
278+ response &= i2cGNSS.enableRTCMmessage (UBX_RTCM_1124, portType, 1 , maxWait );
268279 if (getRTCMSettings (UBX_RTCM_1230, portType) != 10 )
269- response &= i2cGNSS.enableRTCMmessage (UBX_RTCM_1230, portType, 10 ); // Enable message every 10 seconds
280+ response &= i2cGNSS.enableRTCMmessage (UBX_RTCM_1230, portType, 10 , maxWait ); // Enable message every 10 seconds
270281
271282 return (response);
272283}
@@ -275,18 +286,20 @@ bool enableRTCMSentences(uint8_t portType)
275286bool disableRTCMSentences (uint8_t portType)
276287{
277288 bool response = true ;
289+ int maxWait = 1000 ; // When I2C traffic is large during logging, give extra time
290+
278291 if (getRTCMSettings (UBX_RTCM_1005, portType) != 0 )
279- response &= i2cGNSS.disableRTCMmessage (UBX_RTCM_1005, portType);
292+ response &= i2cGNSS.disableRTCMmessage (UBX_RTCM_1005, portType, maxWait );
280293 if (getRTCMSettings (UBX_RTCM_1074, portType) != 0 )
281- response &= i2cGNSS.disableRTCMmessage (UBX_RTCM_1074, portType);
294+ response &= i2cGNSS.disableRTCMmessage (UBX_RTCM_1074, portType, maxWait );
282295 if (getRTCMSettings (UBX_RTCM_1084, portType) != 0 )
283- response &= i2cGNSS.disableRTCMmessage (UBX_RTCM_1084, portType);
296+ response &= i2cGNSS.disableRTCMmessage (UBX_RTCM_1084, portType, maxWait );
284297 if (getRTCMSettings (UBX_RTCM_1094, portType) != 0 )
285- response &= i2cGNSS.disableRTCMmessage (UBX_RTCM_1094, portType);
298+ response &= i2cGNSS.disableRTCMmessage (UBX_RTCM_1094, portType, maxWait );
286299 if (getRTCMSettings (UBX_RTCM_1124, portType) != 0 )
287- response &= i2cGNSS.disableRTCMmessage (UBX_RTCM_1124, portType);
300+ response &= i2cGNSS.disableRTCMmessage (UBX_RTCM_1124, portType, maxWait );
288301 if (getRTCMSettings (UBX_RTCM_1230, portType) != 0 )
289- response &= i2cGNSS.disableRTCMmessage (UBX_RTCM_1230, portType);
302+ response &= i2cGNSS.disableRTCMmessage (UBX_RTCM_1230, portType, maxWait );
290303 return (response);
291304}
292305
@@ -349,7 +362,7 @@ uint8_t getRTCMSettings(uint8_t msgID, uint8_t portID)
349362 customCfg.len = 2 ;
350363 customCfg.startingSpot = 0 ; // Always set the startingSpot to zero (unless you really know what you are doing)
351364
352- uint16_t maxWait = 250 ; // Wait for up to 250ms (Serial may need a lot longer e.g. 1100)
365+ uint16_t maxWait = 1250 ; // Wait for up to 1250ms (Serial may need a lot longer e.g. 1100)
353366
354367 settingPayload[0 ] = UBX_RTCM_MSB;
355368 settingPayload[1 ] = msgID;
0 commit comments