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
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"); } } }
GPSISR.h@6:f0c13bb7d266, 2017-03-01 (annotated)
- Committer:
- trevieze
- Date:
- Wed Mar 01 15:36:05 2017 +0000
- Revision:
- 6:f0c13bb7d266
- Parent:
- 5:c5f700c1e1af
Math error in GPS speed calculation from Knots to Kilometer. Should be ; 1Kn = 1.85Km
Who changed what in which revision?
User | Revision | Line number | New 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 | 5:c5f700c1e1af | 50 | char latc; |
trevieze | 5:c5f700c1e1af | 51 | char lonc; |
trevieze | 3:e64b8be9ce92 | 52 | uint8_t day; |
trevieze | 3:e64b8be9ce92 | 53 | uint8_t month; |
trevieze | 3:e64b8be9ce92 | 54 | uint8_t year; |
trevieze | 4:7240a18102a6 | 55 | uint8_t hours; |
trevieze | 3:e64b8be9ce92 | 56 | uint8_t minutes; |
trevieze | 4:7240a18102a6 | 57 | uint8_t seconds; |
trevieze | 3:e64b8be9ce92 | 58 | float speed; |
trevieze | 3:e64b8be9ce92 | 59 | float altitude; |
trevieze | 3:e64b8be9ce92 | 60 | float bearing; |
trevieze | 3:e64b8be9ce92 | 61 | int satellites; |
trevieze | 3:e64b8be9ce92 | 62 | }; |
trevieze | 3:e64b8be9ce92 | 63 | struct reading buffer; |
trevieze | 3:e64b8be9ce92 | 64 | |
trevieze | 3:e64b8be9ce92 | 65 | void read(void); |
trevieze | 1:4b5ffae743c0 | 66 | char msg[256]; |
trevieze | 1:4b5ffae743c0 | 67 | volatile char rx_in; |
trevieze | 1:4b5ffae743c0 | 68 | bool interrupt; |
trevieze | 1:4b5ffae743c0 | 69 | private: |
trevieze | 1:4b5ffae743c0 | 70 | |
trevieze | 1:4b5ffae743c0 | 71 | }; |
trevieze | 1:4b5ffae743c0 | 72 | |
trevieze | 1:4b5ffae743c0 | 73 | #endif |