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");
	}   
   }  
} 
Committer:
trevieze
Date:
Fri Feb 10 17:57:45 2017 +0000
Revision:
1:4b5ffae743c0
Child:
2:dbc6c0789611
New interrupt service handler for NMEA library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
trevieze 1:4b5ffae743c0 1 /* mbed EM-406 GPS Module Library
trevieze 1:4b5ffae743c0 2 * Copyright (c) 2008-2010, sford
trevieze 1:4b5ffae743c0 3 *
trevieze 1:4b5ffae743c0 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
trevieze 1:4b5ffae743c0 5 * of this software and associated documentation files (the "Software"), to deal
trevieze 1:4b5ffae743c0 6 * in the Software without restriction, including without limitation the rights
trevieze 1:4b5ffae743c0 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
trevieze 1:4b5ffae743c0 8 * copies of the Software, and to permit persons to whom the Software is
trevieze 1:4b5ffae743c0 9 * furnished to do so, subject to the following conditions:
trevieze 1:4b5ffae743c0 10 *
trevieze 1:4b5ffae743c0 11 * The above copyright notice and this permission notice shall be included in
trevieze 1:4b5ffae743c0 12 * all copies or substantial portions of the Software.
trevieze 1:4b5ffae743c0 13 *
trevieze 1:4b5ffae743c0 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
trevieze 1:4b5ffae743c0 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
trevieze 1:4b5ffae743c0 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
trevieze 1:4b5ffae743c0 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
trevieze 1:4b5ffae743c0 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
trevieze 1:4b5ffae743c0 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
trevieze 1:4b5ffae743c0 20 * THE SOFTWARE.
trevieze 1:4b5ffae743c0 21 */
trevieze 1:4b5ffae743c0 22
trevieze 1:4b5ffae743c0 23 #include "GPSISR.h"
trevieze 1:4b5ffae743c0 24
trevieze 1:4b5ffae743c0 25 GPS::GPS(PinName tx, PinName rx, int Baud) : _gps(tx, rx) {
trevieze 1:4b5ffae743c0 26 _gps.baud(Baud);
trevieze 1:4b5ffae743c0 27 _gps.attach(this,&GPS::Rx_interrupt, Serial::RxIrq);
trevieze 1:4b5ffae743c0 28 printf("Interrupt Attached");
trevieze 1:4b5ffae743c0 29 }
trevieze 1:4b5ffae743c0 30
trevieze 1:4b5ffae743c0 31 void GPS::getline() {
trevieze 1:4b5ffae743c0 32 while(_gps.getc() != '$'); // wait for the start of a line
trevieze 1:4b5ffae743c0 33 for(int i=0; i<256; i++) {
trevieze 1:4b5ffae743c0 34 msg[i] = _gps.getc();
trevieze 1:4b5ffae743c0 35 if(msg[i] == '\r') {
trevieze 1:4b5ffae743c0 36 msg[i] = 0;
trevieze 1:4b5ffae743c0 37 return;
trevieze 1:4b5ffae743c0 38 }
trevieze 1:4b5ffae743c0 39 }
trevieze 1:4b5ffae743c0 40 error("Overflowed message limit");
trevieze 1:4b5ffae743c0 41 return;
trevieze 1:4b5ffae743c0 42 }
trevieze 1:4b5ffae743c0 43
trevieze 1:4b5ffae743c0 44 // Interupt Routine to read in data from serial port
trevieze 1:4b5ffae743c0 45 void GPS::Rx_interrupt(void) {
trevieze 1:4b5ffae743c0 46 interrupt = 1;
trevieze 1:4b5ffae743c0 47 rx_in = _gps.getc();
trevieze 1:4b5ffae743c0 48 interrupt = 0;
trevieze 1:4b5ffae743c0 49 return;
trevieze 1:4b5ffae743c0 50 }