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 17 23:31:39 2017 +0000
Revision:
3:e64b8be9ce92
Parent:
2:dbc6c0789611
Child:
4:7240a18102a6
Tested library with Adafruit GPS data logger and appears to work.

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 3:e64b8be9ce92 41 bool dataready(void);
trevieze 3:e64b8be9ce92 42
trevieze 3:e64b8be9ce92 43
trevieze 3:e64b8be9ce92 44 //void f1(a_struct& struct);
trevieze 3:e64b8be9ce92 45 //f1(a_struct s);
trevieze 3:e64b8be9ce92 46 // Reading struct that includes the data for each reading we take
trevieze 3:e64b8be9ce92 47 struct reading {
trevieze 3:e64b8be9ce92 48 float latitude; //Signed positive if N, negative if S
trevieze 3:e64b8be9ce92 49 float longitude; //Signed positive if E, negative if W
trevieze 3:e64b8be9ce92 50 uint8_t day;
trevieze 3:e64b8be9ce92 51 uint8_t month;
trevieze 3:e64b8be9ce92 52 uint8_t year;
trevieze 3:e64b8be9ce92 53 uint8_t hour;
trevieze 3:e64b8be9ce92 54 uint8_t minutes;
trevieze 3:e64b8be9ce92 55 float speed;
trevieze 3:e64b8be9ce92 56 float altitude;
trevieze 3:e64b8be9ce92 57 float bearing;
trevieze 3:e64b8be9ce92 58 int satellites;
trevieze 3:e64b8be9ce92 59 };
trevieze 3:e64b8be9ce92 60 struct reading buffer;
trevieze 3:e64b8be9ce92 61
trevieze 3:e64b8be9ce92 62 void read(void);
trevieze 1:4b5ffae743c0 63 char msg[256];
trevieze 1:4b5ffae743c0 64 volatile char rx_in;
trevieze 1:4b5ffae743c0 65 bool interrupt;
trevieze 1:4b5ffae743c0 66 private:
trevieze 1:4b5ffae743c0 67
trevieze 1:4b5ffae743c0 68 };
trevieze 1:4b5ffae743c0 69
trevieze 1:4b5ffae743c0 70 #endif