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

Commit 2a8f45d

Browse files
authored
Merge pull request #33 from sparkfun/higherDatarate
Higher datarate. Fix for CRC issues
2 parents 45e987c + b17e600 commit 2a8f45d

File tree

5 files changed

+319
-28
lines changed

5 files changed

+319
-28
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
Getting time and date using Ublox commands
3+
By: davidallenmann
4+
SparkFun Electronics
5+
Date: April 16th, 2019
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 Ublox module for the current time and date. We also
10+
turn off the NMEA output on the I2C port. This decreases the amount of I2C traffic
11+
dramatically.
12+
13+
Leave NMEA parsing behind. Now you can simply ask the module for the datums you want!
14+
15+
Feel like supporting open source hardware?
16+
Buy a board from SparkFun!
17+
ZED-F9P RTK2: https://www.sparkfun.com/products/15136
18+
NEO-M8P RTK: https://www.sparkfun.com/products/15005
19+
SAM-M8Q: https://www.sparkfun.com/products/15106
20+
21+
Hardware Connections:
22+
Plug a Qwiic cable into the GPS and a BlackBoard
23+
If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425)
24+
Open the serial monitor at 115200 baud to see the output
25+
*/
26+
27+
#include <Wire.h> //Needed for I2C to GPS
28+
29+
#include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_Ublox_GPS
30+
SFE_UBLOX_GPS myGPS;
31+
32+
long lastTime = 0; //Simple local timer. Limits amount if I2C traffic to Ublox module.
33+
34+
void setup()
35+
{
36+
Serial.begin(500000); //Increase serial speed to maximize
37+
while (!Serial)
38+
; //Wait for user to open terminal
39+
Serial.println("SparkFun Ublox Example");
40+
41+
Wire.begin();
42+
Wire.setClock(400000);
43+
44+
if (myGPS.begin() == false) //Connect to the Ublox module using Wire port
45+
{
46+
Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing."));
47+
while (1)
48+
;
49+
}
50+
51+
myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise)
52+
myGPS.saveConfiguration(); //Save the current settings to flash and BBR
53+
54+
//myGPS.enableDebugging(); //Enable debug messages over Serial (default)
55+
56+
myGPS.setNavigationFrequency(10); //Set output to 10 times a second
57+
byte rate = myGPS.getNavigationFrequency(); //Get the update rate of this module
58+
Serial.print("Current update rate:");
59+
Serial.println(rate);
60+
61+
}
62+
63+
void loop()
64+
{
65+
//Query module only every second. Doing it more often will just cause I2C traffic.
66+
//The module only responds when a new position is available
67+
if (millis() - lastTime > 10)
68+
{
69+
lastTime = millis(); //Update the timer
70+
71+
long latitude = myGPS.getLatitude();
72+
Serial.print(F("Lat: "));
73+
Serial.print(latitude);
74+
75+
long longitude = myGPS.getLongitude();
76+
Serial.print(F(" Long: "));
77+
Serial.print(longitude);
78+
Serial.print(F(" (degrees * 10^-7)"));
79+
80+
long altitude = myGPS.getAltitude();
81+
Serial.print(F(" Alt: "));
82+
Serial.print(altitude);
83+
Serial.print(F(" (mm)"));
84+
85+
byte SIV = myGPS.getSIV();
86+
Serial.print(F(" SIV: "));
87+
Serial.print(SIV);
88+
89+
Serial.print(myGPS.getYear());
90+
Serial.print("-");
91+
Serial.print(myGPS.getMonth());
92+
Serial.print("-");
93+
Serial.print(myGPS.getDay());
94+
Serial.print(" ");
95+
Serial.print(myGPS.getHour());
96+
Serial.print(":");
97+
Serial.print(myGPS.getMinute());
98+
Serial.print(":");
99+
Serial.print(myGPS.getSecond());
100+
Serial.print(".");
101+
Serial.print(myGPS.getNanosecond());
102+
103+
Serial.println();
104+
}
105+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*
2+
Getting time and date using Ublox commands
3+
By: Nathan Seidle
4+
SparkFun Electronics
5+
Date: April 16th, 2019
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 use the Millisecond and Nanosecond output as well as increase the
10+
I2C speed (100 to 400kHz), and serial output (115200 to 500kbps).
11+
12+
Leave NMEA parsing behind. Now you can simply ask the module for the datums you want!
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 BlackBoard
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+
long lastTime = 0; //Simple local timer. Limits amount if I2C traffic to Ublox module.
32+
33+
void setup()
34+
{
35+
Serial.begin(500000); //Increase serial speed to maximize
36+
while (!Serial)
37+
; //Wait for user to open terminal
38+
Serial.println("SparkFun Ublox Example");
39+
40+
Wire.begin();
41+
Wire.setClock(400000);
42+
43+
if (myGPS.begin() == false) //Connect to the Ublox module using Wire port
44+
{
45+
Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing."));
46+
while (1)
47+
;
48+
}
49+
50+
myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise)
51+
52+
//myGPS.enableDebugging(); //Enable debug messages over Serial (default)
53+
54+
myGPS.setNavigationFrequency(10); //Set output to 10 times a second
55+
byte rate = myGPS.getNavigationFrequency(); //Get the update rate of this module
56+
Serial.print("Current update rate:");
57+
Serial.println(rate);
58+
59+
myGPS.saveConfiguration(); //Save the current settings to flash and BBR
60+
61+
pinMode(2, OUTPUT); //For debug capture
62+
digitalWrite(2, HIGH);
63+
}
64+
65+
void loop()
66+
{
67+
//Query module very often to get max update rate
68+
if (millis() - lastTime > 10)
69+
{
70+
lastTime = millis(); //Update the timer
71+
72+
long latitude = myGPS.getLatitude();
73+
Serial.print(F("Lat: "));
74+
Serial.print(latitude);
75+
76+
long longitude = myGPS.getLongitude();
77+
Serial.print(F(" Long: "));
78+
Serial.print(longitude);
79+
Serial.print(F(" (degrees * 10^-7)"));
80+
81+
long altitude = myGPS.getAltitude();
82+
Serial.print(F(" Alt: "));
83+
Serial.print(altitude);
84+
Serial.print(F(" (mm)"));
85+
86+
byte SIV = myGPS.getSIV();
87+
Serial.print(F(" SIV: "));
88+
Serial.print(SIV);
89+
90+
Serial.print(" ");
91+
Serial.print(myGPS.getYear());
92+
Serial.print("-");
93+
Serial.print(myGPS.getMonth());
94+
Serial.print("-");
95+
Serial.print(myGPS.getDay());
96+
Serial.print(" ");
97+
Serial.print(myGPS.getHour());
98+
Serial.print(":");
99+
Serial.print(myGPS.getMinute());
100+
Serial.print(":");
101+
Serial.print(myGPS.getSecond());
102+
Serial.print(".");
103+
//Pretty print leading zeros
104+
int mseconds = myGPS.getMillisecond();
105+
if(mseconds < 100) Serial.print("0");
106+
if(mseconds < 10) Serial.print("0");
107+
Serial.print(mseconds);
108+
109+
Serial.print(" nanoSeconds: ");
110+
Serial.print(myGPS.getNanosecond());
111+
112+
Serial.println();
113+
}
114+
}

Diff for: keywords.txt

+2
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ getDay KEYWORD2
9595
getHour KEYWORD2
9696
getMinute KEYWORD2
9797
getSecond KEYWORD2
98+
getMillisecond KEYWORD2
99+
getNanosecond KEYWORD2
98100

99101
getHPPOSLLH KEYWORD2
100102
getTimeOfWeek KEYWORD2

Diff for: src/SparkFun_Ublox_Arduino_Library.cpp

+70-8
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ boolean SFE_UBLOX_GPS::checkUbloxI2C()
244244
while (bytesAvailable)
245245
{
246246
_i2cPort->beginTransmission(_gpsI2Caddress);
247-
_i2cPort->write(0xFF); //0xFF is the register to read general NMEA data from
247+
_i2cPort->write(0xFF); //0xFF is the register to read data from
248248
if (_i2cPort->endTransmission(false) != 0) //Send a restart command. Do not release bus.
249249
return (false); //Sensor did not ACK
250250

@@ -253,12 +253,28 @@ boolean SFE_UBLOX_GPS::checkUbloxI2C()
253253
if (bytesToRead > I2C_BUFFER_LENGTH)
254254
bytesToRead = I2C_BUFFER_LENGTH;
255255

256+
TRY_AGAIN:
257+
256258
_i2cPort->requestFrom((uint8_t)_gpsI2Caddress, (uint8_t)bytesToRead);
257259
if (_i2cPort->available())
258260
{
259261
for (uint16_t x = 0; x < bytesToRead; x++)
260262
{
261-
process(_i2cPort->read()); //Grab the actual character and process it
263+
uint8_t incoming = _i2cPort->read(); //Grab the actual character
264+
265+
//Check to see if the first read is 0x7F. If it is, the module is not ready
266+
//to respond. Stop, wait, and try again
267+
if (x == 0)
268+
{
269+
if (incoming == 0x7F)
270+
{
271+
debugPrintln("Module not ready with data");
272+
delay(5); //In logic analyzation, the module starting responding after 1.48ms
273+
goto TRY_AGAIN;
274+
}
275+
}
276+
277+
process(incoming); //Process this valid character
262278
}
263279
}
264280
else
@@ -479,15 +495,40 @@ void SFE_UBLOX_GPS::processUBX(uint8_t incoming, ubxPacket *incomingUBX)
479495
{
480496
if (_printDebug == true)
481497
{
482-
_debugSerial->print("Received: ");
498+
_debugSerial->print("Size: ");
499+
_debugSerial->print(incomingUBX->len);
500+
_debugSerial->print(" Received: ");
483501
printPacket(incomingUBX);
484502
}
485503
incomingUBX->valid = true;
486504
processUBXpacket(incomingUBX); //We've got a valid packet, now do something with it
487505
}
488506
else
489507
{
490-
debugPrintln("Checksum failed. Response too big?");
508+
if (_printDebug == true)
509+
{
510+
debugPrintln("Checksum failed. Response too big?");
511+
512+
digitalWrite(2, LOW);
513+
delay(10);
514+
digitalWrite(2, HIGH);
515+
516+
_debugSerial->print("Received: ");
517+
printPacket(incomingUBX);
518+
519+
_debugSerial->print("Size: ");
520+
_debugSerial->print(incomingUBX->len);
521+
_debugSerial->print(" checksumA: ");
522+
_debugSerial->print(incomingUBX->checksumA);
523+
_debugSerial->print(" checksumB: ");
524+
_debugSerial->print(incomingUBX->checksumB);
525+
526+
_debugSerial->print(" rollingChecksumA: ");
527+
_debugSerial->print(rollingChecksumA);
528+
_debugSerial->print(" rollingChecksumB: ");
529+
_debugSerial->print(rollingChecksumB);
530+
_debugSerial->println();
531+
}
491532
}
492533
}
493534
else //Load this byte into the payload array
@@ -529,12 +570,14 @@ void SFE_UBLOX_GPS::processUBXpacket(ubxPacket *msg)
529570
//Parse various byte fields into global vars
530571
constexpr int startingSpot = 0; //fixed value used in processUBX
531572

573+
gpsMillisecond = extractLong(0) % 1000; //Get last three digits of iTOW
532574
gpsYear = extractInt(4);
533575
gpsMonth = extractByte(6);
534576
gpsDay = extractByte(7);
535577
gpsHour = extractByte(8);
536578
gpsMinute = extractByte(9);
537579
gpsSecond = extractByte(10);
580+
gpsNanosecond = extractLong(16); //Includes milliseconds
538581

539582
fixType = extractByte(20 - startingSpot);
540583
carrierSolution = extractByte(21 - startingSpot) >> 6; //Get 6th&7th bits of this byte
@@ -554,6 +597,7 @@ void SFE_UBLOX_GPS::processUBXpacket(ubxPacket *msg)
554597
moduleQueried.gpsHour = true;
555598
moduleQueried.gpsMinute = true;
556599
moduleQueried.gpsSecond = true;
600+
moduleQueried.gpsNanosecond = true;
557601

558602
moduleQueried.all = true;
559603
moduleQueried.longitude = true;
@@ -1307,7 +1351,7 @@ uint8_t SFE_UBLOX_GPS::getMonth(uint16_t maxWait)
13071351
return (gpsMonth);
13081352
}
13091353

1310-
//Get the current year
1354+
//Get the current day
13111355
uint8_t SFE_UBLOX_GPS::getDay(uint16_t maxWait)
13121356
{
13131357
if (moduleQueried.gpsDay == false)
@@ -1316,7 +1360,7 @@ uint8_t SFE_UBLOX_GPS::getDay(uint16_t maxWait)
13161360
return (gpsDay);
13171361
}
13181362

1319-
//Get the current year
1363+
//Get the current hour
13201364
uint8_t SFE_UBLOX_GPS::getHour(uint16_t maxWait)
13211365
{
13221366
if (moduleQueried.gpsHour == false)
@@ -1325,7 +1369,7 @@ uint8_t SFE_UBLOX_GPS::getHour(uint16_t maxWait)
13251369
return (gpsHour);
13261370
}
13271371

1328-
//Get the current year
1372+
//Get the current minute
13291373
uint8_t SFE_UBLOX_GPS::getMinute(uint16_t maxWait)
13301374
{
13311375
if (moduleQueried.gpsMinute == false)
@@ -1334,7 +1378,7 @@ uint8_t SFE_UBLOX_GPS::getMinute(uint16_t maxWait)
13341378
return (gpsMinute);
13351379
}
13361380

1337-
//Get the current year
1381+
//Get the current second
13381382
uint8_t SFE_UBLOX_GPS::getSecond(uint16_t maxWait)
13391383
{
13401384
if (moduleQueried.gpsSecond == false)
@@ -1343,6 +1387,24 @@ uint8_t SFE_UBLOX_GPS::getSecond(uint16_t maxWait)
13431387
return (gpsSecond);
13441388
}
13451389

1390+
//Get the current millisecond
1391+
uint16_t SFE_UBLOX_GPS::getMillisecond(uint16_t maxWait)
1392+
{
1393+
if (moduleQueried.gpsiTOW == false)
1394+
getPVT();
1395+
moduleQueried.gpsiTOW = false; //Since we are about to give this to user, mark this data as stale
1396+
return (gpsMillisecond);
1397+
}
1398+
1399+
//Get the current nanoseconds - includes milliseconds
1400+
int32_t SFE_UBLOX_GPS::getNanosecond(uint16_t maxWait)
1401+
{
1402+
if (moduleQueried.gpsNanosecond == false)
1403+
getPVT();
1404+
moduleQueried.gpsNanosecond = false; //Since we are about to give this to user, mark this data as stale
1405+
return (gpsNanosecond);
1406+
}
1407+
13461408
//Get the latest Position/Velocity/Time solution and fill all global variables
13471409
boolean SFE_UBLOX_GPS::getPVT(uint16_t maxWait)
13481410
{

0 commit comments

Comments
 (0)