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

Commit 447f241

Browse files
committed
Fixed error in sendCommand. getPosAccuracy works again.
1 parent 495e6c7 commit 447f241

File tree

2 files changed

+67
-64
lines changed

2 files changed

+67
-64
lines changed

Diff for: examples/Example3_GetPosition/Example3_GetPosition.ino

+15-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
99
This example shows how to query a Ublox module for its lat/long/altitude. Leave NMEA
1010
parsing behind. Now you can simply ask the module for the datums you want!
11-
11+
1212
Feel like supporting open source hardware?
1313
Buy a board from SparkFun!
1414
ZED-F9P RTK2: https://www.sparkfun.com/products/15136
@@ -43,7 +43,15 @@ void setup()
4343
while (1);
4444
}
4545

46-
Wire.setClock(400000); //Increase I2C clock speed to 400kHz
46+
//Wire.setClock(400000); //Increase I2C clock speed to 400kHz
47+
48+
//long pos = myGPS.getPositionAccuracy(2000);
49+
//Serial.print("pos: ");
50+
//Serial.println(pos);
51+
52+
byte version = myGPS.getProtocolVersionHigh(2000);
53+
54+
while (1);
4755
}
4856

4957
void loop()
@@ -53,21 +61,23 @@ void loop()
5361
delay(250); //Don't pound too hard on the I2C bus
5462

5563
//Every other second print the current 3D position accuracy
56-
if(millis() - lastTime > 1000)
64+
if (millis() - lastTime > 1000)
5765
{
5866
long latitude = myGPS.getLatitude();
5967
Serial.print("Lat: ");
6068
Serial.print(latitude);
6169

70+
while (1);
71+
6272
long longitude = myGPS.getLongitude();
6373
Serial.print(" Long: ");
6474
Serial.print(longitude);
65-
Serial.println(" (degrees * 10^-7)");
75+
Serial.print(" (degrees * 10^-7)");
6676

6777
long altitude = myGPS.getAltitude();
6878
Serial.print(" Alt (above mean sea level): ");
6979
Serial.print(altitude);
70-
Serial.println(" (mm)");
80+
Serial.print(" (mm)");
7181

7282
long altitudeEllipsoid = myGPS.getAltitudeEllipsoid();
7383
Serial.print(" AltMSL (above Ellipsoid model surface of earth): ");

Diff for: src/SparkFun_Ublox_Arduino_Library.cpp

+52-59
Original file line numberDiff line numberDiff line change
@@ -194,17 +194,6 @@ void SFE_UBLOX_GPS::process(uint8_t incoming)
194194
processUBX(incoming, &packetAck);
195195
else if (ubxFrameClass == CLASS_NOT_AN_ACK)
196196
processUBX(incoming, &packetCfg);
197-
else
198-
{
199-
#ifdef DEBUG
200-
//Print this character
201-
debug.print(F("No frame class set: "));
202-
debug.write(incoming);
203-
debug.print(" 0x");
204-
debug.print(incoming, HEX);
205-
debug.println();
206-
#endif
207-
}
208197
}
209198
else if (currentSentence == NMEA)
210199
{
@@ -329,18 +318,22 @@ void SFE_UBLOX_GPS::processUBX(uint8_t incoming, ubxPacket *incomingUBX)
329318
if (incomingUBX->checksumA == tempA && incomingUBX->checksumB == tempB)
330319
{
331320
#ifdef DEBUG
332-
debug.print("Frame cleared: ");
321+
debug.print("Checksum/Frame Good: ");
333322
//printFrame(incomingUBX);
334323
#endif
335-
336324
incomingUBX->valid = true;
337325
processUBXpacket(incomingUBX); //We've got a valid packet, now do something with it
338326
}
327+
#ifdef DEBUG
328+
else
329+
debug.println("Checksum failed. Response too big?");
330+
#endif
331+
339332
}
340333
else //Load this byte into the payload array
341334
{
342335
//Begin recording if counter goes past startingSpot
343-
if(incomingUBX->counter > incomingUBX->startingSpot)
336+
if( (incomingUBX->counter - 4) > incomingUBX->startingSpot)
344337
{
345338
//Check to see if we have room for this byte
346339
if( (incomingUBX->counter - 4) < MAX_PAYLOAD_SIZE)
@@ -394,53 +387,46 @@ boolean SFE_UBLOX_GPS::sendCommand(ubxPacket outgoingUBX, uint16_t maxWait)
394387

395388
//Write header bytes
396389
_i2cPort->beginTransmission((uint8_t)_gpsI2Caddress); //There is no register to write to, we just begin writing data bytes
397-
_i2cPort->write(UBX_SYNCH_1);
398-
_i2cPort->write(UBX_SYNCH_2);
390+
_i2cPort->write(UBX_SYNCH_1); //μ - oh ublox, you're funny. I will call you micro-blox from now on.
391+
_i2cPort->write(UBX_SYNCH_2); //b
399392
_i2cPort->write(outgoingUBX.cls);
400393
_i2cPort->write(outgoingUBX.id);
401394
_i2cPort->write(outgoingUBX.len & 0xFF); //LSB
402395
_i2cPort->write(outgoingUBX.len >> 8); //MSB
403-
404-
//Normally we would endTransmission() here but instead, we check if there are more bytes to transmit.
396+
if (_i2cPort->endTransmission(false) != 0) //Do not release bus
397+
return (false); //Sensor did not ACK
405398

406-
//If we are sending just a command, there are no bytes to send so skip sending anything.
407-
if(outgoingUBX.len > 0)
399+
//Write payload. Limit the sends into 32 byte chunks
400+
//This code based on ublox: https://forum.u-blox.com/index.php/20528/how-to-use-i2c-to-get-the-nmea-frames
401+
uint16_t bytesToSend = outgoingUBX.len;
402+
403+
//"The number of data bytes must be at least 2 to properly distinguish
404+
//from the write access to set the address counter in random read accesses."
405+
uint16_t startSpot = 0;
406+
while (bytesToSend > 1)
408407
{
409-
if (_i2cPort->endTransmission(false) != 0) //Do not release bus
410-
return (false); //Sensor did not ACK
411-
412-
//Write payload. Limit the sends into 32 byte chunks
413-
//This code based on ublox: https://forum.u-blox.com/index.php/20528/how-to-use-i2c-to-get-the-nmea-frames
414-
uint16_t bytesToSend = outgoingUBX.len;
415-
416-
//"The number of data bytes must be at least 2 to properly distinguish
417-
//from the write access to set the address counter in random read accesses."
418-
uint16_t startSpot = 0;
419-
while (bytesToSend > 1)
420-
{
421-
uint8_t len = bytesToSend;
422-
if (len > I2C_BUFFER_LENGTH) len = I2C_BUFFER_LENGTH;
423-
424-
_i2cPort->beginTransmission((uint8_t)_gpsI2Caddress);
425-
//_i2cPort->write(outgoingUBX.payload, len); //Write a portion of the payload to the bus
426-
427-
for (uint16_t x = 0 ; x < len ; x++)
428-
_i2cPort->write(outgoingUBX.payload[startSpot + x]); //Write a portion of the payload to the bus
429-
430-
if (_i2cPort->endTransmission(false) != 0) //Don't release bus
431-
return (false); //Sensor did not ACK
432-
433-
//*outgoingUBX.payload += len; //Move the pointer forward
434-
startSpot += len; //Move the pointer forward
435-
bytesToSend -= len;
436-
}
437-
438-
//Write checksum
439-
_i2cPort->beginTransmission((uint8_t)_gpsI2Caddress);
440-
if (bytesToSend == 1) _i2cPort->write(outgoingUBX.payload, 1);
441-
_i2cPort->write(outgoingUBX.checksumA);
442-
_i2cPort->write(outgoingUBX.checksumB);
408+
uint8_t len = bytesToSend;
409+
if (len > I2C_BUFFER_LENGTH) len = I2C_BUFFER_LENGTH;
410+
411+
_i2cPort->beginTransmission((uint8_t)_gpsI2Caddress);
412+
//_i2cPort->write(outgoingUBX.payload, len); //Write a portion of the payload to the bus
413+
414+
for (uint16_t x = 0 ; x < len ; x++)
415+
_i2cPort->write(outgoingUBX.payload[startSpot + x]); //Write a portion of the payload to the bus
416+
417+
if (_i2cPort->endTransmission(false) != 0) //Don't release bus
418+
return (false); //Sensor did not ACK
419+
420+
//*outgoingUBX.payload += len; //Move the pointer forward
421+
startSpot += len; //Move the pointer forward
422+
bytesToSend -= len;
443423
}
424+
425+
//Write checksum
426+
_i2cPort->beginTransmission((uint8_t)_gpsI2Caddress);
427+
if (bytesToSend == 1) _i2cPort->write(outgoingUBX.payload, 1);
428+
_i2cPort->write(outgoingUBX.checksumA);
429+
_i2cPort->write(outgoingUBX.checksumB);
444430

445431
//All done transmitting bytes. Release bus.
446432
if (_i2cPort->endTransmission() != 0)
@@ -694,9 +680,15 @@ uint32_t SFE_UBLOX_GPS::getPositionAccuracy(uint16_t maxWait)
694680
tempAccuracy |= payloadCfg[26] << 8*2;
695681
tempAccuracy |= payloadCfg[27] << 8*3;
696682

683+
Serial.print("temp: ");
684+
Serial.println(tempAccuracy, HEX);
685+
697686
if( (tempAccuracy % 10) >= 5) tempAccuracy += 5; //Round fraction of mm up to next mm if .5 or above
698687
tempAccuracy /= 10; //Convert 0.1mm units to mm
699688

689+
Serial.print("temp: ");
690+
Serial.println(tempAccuracy, HEX);
691+
700692
return(tempAccuracy);
701693
}
702694
//Get the current latitude in degrees
@@ -709,8 +701,7 @@ int32_t SFE_UBLOX_GPS::getLatitude(uint16_t maxWait)
709701
packetCfg.len = 0;
710702
packetCfg.startingSpot = 0;
711703

712-
// if(sendCommand(packetCfg, maxWait) == false)
713-
if(sendCommand(packetCfg, 1500) == false)
704+
if(sendCommand(packetCfg, maxWait) == false)
714705
return(0); //If command send fails then bail
715706

716707
//We got a response, now parse the byte fields
@@ -807,13 +798,12 @@ uint8_t SFE_UBLOX_GPS::getProtocolVersionHigh(uint16_t maxWait)
807798
//Then we look at each extension field of 30 bytes
808799
for(uint8_t extensionNumber = 0 ; extensionNumber < 1 ; extensionNumber++)
809800
{
810-
packetCfg.startingSpot = 40 + (30*extensionNumber);
801+
//packetCfg.startingSpot = 40 + (30*extensionNumber);
802+
packetCfg.startingSpot = 0;
811803

812804
if(sendCommand(packetCfg, maxWait) == false)
813805
return(0); //If command send fails then bail
814806

815-
while(1);
816-
817807
//Now we need to start looking for "PROTVER" in the incoming byte stream
818808
Serial.print("Extension: ");
819809
for(int location ; location < 64 ; location++)
@@ -822,6 +812,9 @@ uint8_t SFE_UBLOX_GPS::getProtocolVersionHigh(uint16_t maxWait)
822812
if(packetCfg.payload[location] == '\0') break;
823813
}
824814
Serial.println();
815+
816+
while(1);
817+
825818
}
826819

827820
return(0);

0 commit comments

Comments
 (0)