A GPS serial interrupt service routine that has an on the fly nmea parser. Works with a STM32F411RE and a Adafruit GPS logger.

Dependents:   Bicycl_Computer_NUCLEO-F411RE Bicycl_Computer_NUCLEO-L476RG

Fork of GPS by Simon Ford

main.cpp

#include "mbed.h"
#include "GPSISR.h"

#define PIN_RX_GPS      PA_12 //GPS Shield RX pin
#define PIN_TX_GPS      PA_11 //GPS Shield TX pin
Serial pc(USBTX, USBRX);

// Set up serial interrupe service handler for gps characters.
GPS MyGPS(PIN_TX_GPS,PIN_RX_GPS, 9600);
int main()
{
    while (1) {
	if (MyGPS.dataready()) {
					MyGPS.read();
					pc.printf("NMEA has valid data");
					pc.printf("Sats : %d \n", MyGPS.buffer.satellites);
					pc.printf("%d-%d-%d\n", MyGPS.buffer.month, MyGPS.buffer.day, MyGPS.buffer.year);
					pc.printf("%d:%d:%d\n", MyGPS.buffer.hours, MyGPS.buffer.minutes, MyGPS.buffer.seconds);
	}
	else {
                pc.printf("NMEA has no valid data");
	}   
   }  
} 

Files at this revision

API Documentation at this revision

Comitter:
trevieze
Date:
Wed Mar 01 15:36:05 2017 +0000
Parent:
5:c5f700c1e1af
Commit message:
Math error in GPS speed calculation from Knots to Kilometer. Should be ; 1Kn = 1.85Km

Changed in this revision

nmea.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r c5f700c1e1af -r f0c13bb7d266 nmea.cpp
--- a/nmea.cpp	Wed Mar 01 03:38:03 2017 +0000
+++ b/nmea.cpp	Wed Mar 01 15:36:05 2017 +0000
@@ -219,7 +219,7 @@
 		//parse speed
 		// The knot (pronounced not) is a unit of speed equal to one nautical mile (1.852 km) per hour
 		res_fSpeed = string2float(tmp_words[7]);
-		res_fSpeed /= 1.852; // convert to km/h
+		res_fSpeed *= double(1.852); // convert to km/h  1knot = 1.852Km, Was res_fSpeed /= 1.852;
 		// parse bearing
 		res_fBearing = string2float(tmp_words[8]);
 		// parse UTC date