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

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 "mbed.h"
trevieze 1:4b5ffae743c0 24
trevieze 1:4b5ffae743c0 25 #ifndef MBED_GPS_H
trevieze 1:4b5ffae743c0 26 #define MBED_GPS_H
trevieze 1:4b5ffae743c0 27
trevieze 1:4b5ffae743c0 28 /** A GPS interface for reading from a Globalsat EM-406 GPS Module */
trevieze 1:4b5ffae743c0 29 class GPS {
trevieze 1:4b5ffae743c0 30 public:
trevieze 1:4b5ffae743c0 31
trevieze 1:4b5ffae743c0 32 /** Create the GPS interface, connected to the specified serial port
trevieze 1:4b5ffae743c0 33 */
trevieze 1:4b5ffae743c0 34 GPS(PinName tx, PinName rx, int Baud);
trevieze 1:4b5ffae743c0 35 //Peripheral
trevieze 1:4b5ffae743c0 36 Serial _gps;
trevieze 2:dbc6c0789611 37
trevieze 1:4b5ffae743c0 38 // Setup a serial interrupt function to transmit data
trevieze 1:4b5ffae743c0 39 void getline();
trevieze 1:4b5ffae743c0 40 void Rx_interrupt(void);
trevieze 2:dbc6c0789611 41 bool isdatardy(void);
trevieze 2:dbc6c0789611 42 int getSats(void);
trevieze 1:4b5ffae743c0 43 char msg[256];
trevieze 1:4b5ffae743c0 44 volatile char rx_in;
trevieze 1:4b5ffae743c0 45 bool interrupt;
trevieze 1:4b5ffae743c0 46 private:
trevieze 1:4b5ffae743c0 47
trevieze 1:4b5ffae743c0 48 };
trevieze 1:4b5ffae743c0 49
trevieze 1:4b5ffae743c0 50 #endif