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

Commit e3e170e

Browse files
committed
Fix for issue #26. Add example 16. Increase payload size to 128.
We now throw out incoming transfers that start with 0x7F. This commit also increases the RAM footprint by 64 bytes so that we can correctly deal with the 92 byte response of the PVT inquiry.
1 parent e2a8883 commit e3e170e

File tree

3 files changed

+164
-7
lines changed

3 files changed

+164
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
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 use the 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: src/SparkFun_Ublox_Arduino_Library.cpp

+47-6
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,14 +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);
538-
gpsMillisecond = extractLong(0) % 1000; //Get last three digits of iTOW
539-
gpsNanosecond = extractLong(16); //Includes milliseconds
580+
gpsNanosecond = extractLong(16); //Includes milliseconds
540581

541582
fixType = extractByte(20 - startingSpot);
542583
carrierSolution = extractByte(21 - startingSpot) >> 6; //Get 6th&7th bits of this byte

Diff for: src/SparkFun_Ublox_Arduino_Library.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171

7272
//The catch-all default is 32
7373
#define I2C_BUFFER_LENGTH 32
74+
//#define I2C_BUFFER_LENGTH 16 //For testing on Artemis
7475

7576
#endif
7677
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
@@ -169,7 +170,8 @@ const uint8_t VAL_ID_I2C_ADDRESS = 0x01;
169170

170171
#ifndef MAX_PAYLOAD_SIZE
171172

172-
#define MAX_PAYLOAD_SIZE 64 //Some commands are larger than 64 bytes but this covers most
173+
//Payload size must be big enough to cover the commands we want to get responses from
174+
#define MAX_PAYLOAD_SIZE 128 //Increased to 128 to cover the PVT packet
173175

174176
#endif
175177

0 commit comments

Comments
 (0)