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:
Thu Feb 16 23:55:28 2017 +0000
Parent:
1:4b5ffae743c0
Child:
3:e64b8be9ce92
Commit message:
Wrapper for NMEA

Changed in this revision

GPSISR.cpp Show annotated file Show diff for this revision Revisions of this file
GPSISR.h Show annotated file Show diff for this revision Revisions of this file
--- a/GPSISR.cpp	Fri Feb 10 17:57:45 2017 +0000
+++ b/GPSISR.cpp	Thu Feb 16 23:55:28 2017 +0000
@@ -19,12 +19,15 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
- 
+#include "nmea.h"
 #include "GPSISR.h"
 
+NMEA nmea; //parse GPS Sentence.
+
 GPS::GPS(PinName tx, PinName rx, int Baud) : _gps(tx, rx) {
     _gps.baud(Baud);
     _gps.attach(this,&GPS::Rx_interrupt, Serial::RxIrq);
+    
     printf("Interrupt Attached");
 }
 
@@ -45,6 +48,14 @@
 void GPS::Rx_interrupt(void) {
     interrupt = 1;
     rx_in = _gps.getc();
+    nmea.fusedata(rx_in);
     interrupt = 0;
     return;
 }
+ bool GPS::isdatardy(void){
+ return  nmea.isdataready();
+     
+}     
+int GPS::getSats(void){
+    return nmea.getSatellites();
+}    
\ No newline at end of file
--- a/GPSISR.h	Fri Feb 10 17:57:45 2017 +0000
+++ b/GPSISR.h	Thu Feb 16 23:55:28 2017 +0000
@@ -34,9 +34,12 @@
     GPS(PinName tx, PinName rx, int Baud);
     //Peripheral
     Serial _gps;
+    
     // Setup a serial interrupt function to transmit data
     void getline();
     void Rx_interrupt(void);
+    bool isdatardy(void);
+    int getSats(void);
     char msg[256];
     volatile char rx_in;
     bool interrupt;