Skip to content
This repository was archived by the owner on Jan 28, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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.
  • Loading branch information
nseidle committed Jul 15, 2019
commit e3e170ea08b64f7bb9a0366f6189be6c488038ce
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
Getting time and date using Ublox commands
By: davidallenmann
SparkFun Electronics
Date: April 16th, 2019
License: MIT. See license file for more information but you can
basically do whatever you want with this code.

This example shows how to use the Nanosecond output as well as increase the
I2C speed (100 to 400kHz), and serial output (115200 to 500kbps).

Leave NMEA parsing behind. Now you can simply ask the module for the datums you want!

Feel like supporting open source hardware?
Buy a board from SparkFun!
ZED-F9P RTK2: https://www.sparkfun.com/products/15136
NEO-M8P RTK: https://www.sparkfun.com/products/15005
SAM-M8Q: https://www.sparkfun.com/products/15106

Hardware Connections:
Plug a Qwiic cable into the GPS and a BlackBoard
If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425)
Open the serial monitor at 115200 baud to see the output
*/

#include <Wire.h> //Needed for I2C to GPS

#include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_Ublox_GPS
SFE_UBLOX_GPS myGPS;

long lastTime = 0; //Simple local timer. Limits amount if I2C traffic to Ublox module.

void setup()
{
Serial.begin(500000); //Increase serial speed to maximize
while (!Serial)
; //Wait for user to open terminal
Serial.println("SparkFun Ublox Example");

Wire.begin();
Wire.setClock(400000);

if (myGPS.begin() == false) //Connect to the Ublox module using Wire port
{
Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing."));
while (1)
;
}

myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise)

//myGPS.enableDebugging(); //Enable debug messages over Serial (default)

myGPS.setNavigationFrequency(10); //Set output to 10 times a second
byte rate = myGPS.getNavigationFrequency(); //Get the update rate of this module
Serial.print("Current update rate:");
Serial.println(rate);

myGPS.saveConfiguration(); //Save the current settings to flash and BBR

pinMode(2, OUTPUT); //For debug capture
digitalWrite(2, HIGH);
}

void loop()
{
//Query module very often to get max update rate
if (millis() - lastTime > 10)
{
lastTime = millis(); //Update the timer

long latitude = myGPS.getLatitude();
Serial.print(F("Lat: "));
Serial.print(latitude);

long longitude = myGPS.getLongitude();
Serial.print(F(" Long: "));
Serial.print(longitude);
Serial.print(F(" (degrees * 10^-7)"));

long altitude = myGPS.getAltitude();
Serial.print(F(" Alt: "));
Serial.print(altitude);
Serial.print(F(" (mm)"));

byte SIV = myGPS.getSIV();
Serial.print(F(" SIV: "));
Serial.print(SIV);

Serial.print(" ");
Serial.print(myGPS.getYear());
Serial.print("-");
Serial.print(myGPS.getMonth());
Serial.print("-");
Serial.print(myGPS.getDay());
Serial.print(" ");
Serial.print(myGPS.getHour());
Serial.print(":");
Serial.print(myGPS.getMinute());
Serial.print(":");
Serial.print(myGPS.getSecond());
Serial.print(".");
//Pretty print leading zeros
int mseconds = myGPS.getMillisecond();
if(mseconds < 100) Serial.print("0");
if(mseconds < 10) Serial.print("0");
Serial.print(mseconds);

Serial.print(" nanoSeconds: ");
Serial.print(myGPS.getNanosecond());

Serial.println();
}
}
53 changes: 47 additions & 6 deletions src/SparkFun_Ublox_Arduino_Library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ boolean SFE_UBLOX_GPS::checkUbloxI2C()
while (bytesAvailable)
{
_i2cPort->beginTransmission(_gpsI2Caddress);
_i2cPort->write(0xFF); //0xFF is the register to read general NMEA data from
_i2cPort->write(0xFF); //0xFF is the register to read data from
if (_i2cPort->endTransmission(false) != 0) //Send a restart command. Do not release bus.
return (false); //Sensor did not ACK

Expand All @@ -253,12 +253,28 @@ boolean SFE_UBLOX_GPS::checkUbloxI2C()
if (bytesToRead > I2C_BUFFER_LENGTH)
bytesToRead = I2C_BUFFER_LENGTH;

TRY_AGAIN:

_i2cPort->requestFrom((uint8_t)_gpsI2Caddress, (uint8_t)bytesToRead);
if (_i2cPort->available())
{
for (uint16_t x = 0; x < bytesToRead; x++)
{
process(_i2cPort->read()); //Grab the actual character and process it
uint8_t incoming = _i2cPort->read(); //Grab the actual character

//Check to see if the first read is 0x7F. If it is, the module is not ready
//to respond. Stop, wait, and try again
if (x == 0)
{
if (incoming == 0x7F)
{
debugPrintln("Module not ready with data");
delay(5); //In logic analyzation, the module starting responding after 1.48ms
goto TRY_AGAIN;
}
}

process(incoming); //Process this valid character
}
}
else
Expand Down Expand Up @@ -479,15 +495,40 @@ void SFE_UBLOX_GPS::processUBX(uint8_t incoming, ubxPacket *incomingUBX)
{
if (_printDebug == true)
{
_debugSerial->print("Received: ");
_debugSerial->print("Size: ");
_debugSerial->print(incomingUBX->len);
_debugSerial->print(" Received: ");
printPacket(incomingUBX);
}
incomingUBX->valid = true;
processUBXpacket(incomingUBX); //We've got a valid packet, now do something with it
}
else
{
debugPrintln("Checksum failed. Response too big?");
if (_printDebug == true)
{
debugPrintln("Checksum failed. Response too big?");

digitalWrite(2, LOW);
delay(10);
digitalWrite(2, HIGH);

_debugSerial->print("Received: ");
printPacket(incomingUBX);

_debugSerial->print("Size: ");
_debugSerial->print(incomingUBX->len);
_debugSerial->print(" checksumA: ");
_debugSerial->print(incomingUBX->checksumA);
_debugSerial->print(" checksumB: ");
_debugSerial->print(incomingUBX->checksumB);

_debugSerial->print(" rollingChecksumA: ");
_debugSerial->print(rollingChecksumA);
_debugSerial->print(" rollingChecksumB: ");
_debugSerial->print(rollingChecksumB);
_debugSerial->println();
}
}
}
else //Load this byte into the payload array
Expand Down Expand Up @@ -529,14 +570,14 @@ void SFE_UBLOX_GPS::processUBXpacket(ubxPacket *msg)
//Parse various byte fields into global vars
constexpr int startingSpot = 0; //fixed value used in processUBX

gpsMillisecond = extractLong(0) % 1000; //Get last three digits of iTOW
gpsYear = extractInt(4);
gpsMonth = extractByte(6);
gpsDay = extractByte(7);
gpsHour = extractByte(8);
gpsMinute = extractByte(9);
gpsSecond = extractByte(10);
gpsMillisecond = extractLong(0) % 1000; //Get last three digits of iTOW
gpsNanosecond = extractLong(16); //Includes milliseconds
gpsNanosecond = extractLong(16); //Includes milliseconds

fixType = extractByte(20 - startingSpot);
carrierSolution = extractByte(21 - startingSpot) >> 6; //Get 6th&7th bits of this byte
Expand Down
4 changes: 3 additions & 1 deletion src/SparkFun_Ublox_Arduino_Library.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@

//The catch-all default is 32
#define I2C_BUFFER_LENGTH 32
//#define I2C_BUFFER_LENGTH 16 //For testing on Artemis

#endif
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Expand Down Expand Up @@ -169,7 +170,8 @@ const uint8_t VAL_ID_I2C_ADDRESS = 0x01;

#ifndef MAX_PAYLOAD_SIZE

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

#endif

Expand Down