- Code: Select all
#include <Adafruit_GPS.h>
#include <SoftwareSerial.h>
Adafruit_GPS GPS(&Serial);
// Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
// Set to 'true' if you want to debug and listen to the raw GPS sentences
#define GPSECHO true
// this keeps track of whether we're using the interrupt
// off by default!
boolean usingInterrupt = false;
void useInterrupt(boolean); // Func prototype keeps Arduino 0023 happy
void setup() {
Serial.begin(115200);
Serial.println("Adafruit GPS library basic test!");
useInterrupt(false);
delay(1000);
}
// Interrupt is called once a millisecond, looks for any new GPS data, and stores it
SIGNAL(TIMER0_COMPA_vect) {
char c = GPS.read();
// if you want to debug, this is a good time to do it!
if (GPSECHO)
if (c) UDR0 = c;
// writing direct to UDR0 is much much faster than Serial.print
// but only one character can be written at a time.
}
void useInterrupt(boolean v) {
if (v) {
// Timer0 is already used for millis() - we'll just interrupt somewhere
// in the middle and call the "Compare A" function above
OCR0A = 0xAF;
TIMSK0 |= _BV(OCIE0A);
usingInterrupt = true;
}
else {
// do not call the interrupt function COMPA anymore
TIMSK0 &= ~_BV(OCIE0A);
usingInterrupt = false;
}
}
void loop() {
if (! usingInterrupt) {
// read data from the GPS in the 'main loop'
char c = GPS.read();
// if you want to debug, this is a good time to do it!
if (GPSECHO) if (c) UDR0 = c;
}
// if a sentence is received, we can check the checksum, parse it...
if (GPS.newNMEAreceived()) {
//Serial.println(GPS.lastNMEA()); // this also sets the newNMEAreceived() flag to false
if (!GPS.parse(GPS.lastNMEA())) // this also sets the newNMEAreceived() flag to false
return; // we can fail to parse a sentence in which case we should just wait for another
}
}
If I call with useInterrupt(false) then it prints every NMEA sentence as expected,
- Code: Select all
$GPRMC,160427.600,A,3416.1119,N,11818.8537,W,0.00,206.03,191212,,,D*76
$GPRMC,160427.800,A,3416.1119,N,11818.8537,W,0.00,206.03,191212,,,D*78
$GPRMC,160428.000,A,3416.1119,N,11818.8537,W,0.00,206.03,191212,,,D*7F
$GPRMC,160428.200,A,3416.1119,N,11818.8537,W,0.00,206.03,191212,,,D*7D
$GPRMC,160428.400,A,3416.1119,N,11818.8537,W,0.00,206.03,191212,,,D*7B
$GPRMC,160428.600,A,3416.1119,N,11818.8537,W,0.00,206.03,191212,,,D*79
$GPRMC,160428.800,A,3416.1119,N,11818.8537,W,0.00,206.03,191212,,,D*77
BUT, if I call with useInterrupt(true) then most of the sentences are missing the newline.
- Code: Select all
$GPRMC,160615.800,A,3416.1185,N,11818.8520,W,0.01,219.89,191212,,,A*7$GPRMC,160616.000,A,3416.1187,N,11818.8516,W,0.02,219.89,191212,,,A*E$GPRMC,160616.200,A,3416.1187,N,11818.8514,W,0.01,219.89,191212,,,A*7$GPRMC,160616.400,A,3416.1185,N,11818.8514,W,0.02,219.89,191212,,,A*7$GPRMC,160616.600,A,3416.1185,N,11818.8513,W,0.03,219.89,191212,,,A*7
$GPRMC,160616.800,A,3416.1184,N,11818.8512,W,0.02,219.89,191212,,,A*7$GPRMC,160617.000,A,3416.1184,N,11818.8512,W,0.00,219.89,191212,,,A*7$GPRMC,160617.200,A,3416.1184,N,11818.8511,W,0.03,219.89,191212,,,A*7
$GPRMC,160617.400,A,3416.1184,N,11818.8510,W,0.00,219.89,191212,,,A*7$GPRMC,160617.600,A,3416.1184,N,11818.8508,W,0.01,219.89,191212,,,A*7$GPRMC,160617.800,A,3416.1184,N,11818.8507,W,0.05,219.89,191212,,,A*7$GPRMC,160618.000,A,3416.1184,N,11818.8505,W,0.01,219.89,191212,,,A*7$GPRMC,160618.200,A,3416.1184,N,11818.8505,W,0.03,219.89,191212,,,A*7$GPRMC,160618.400,A,3416.1182,N,11818.8506,W,0.04,219.89,191212,,,A*7$GPRMC,160618.600,A,3416.1180,N,11818.8507,W,0.04,219.89,191212,,,A*6$GPRMC,160618.800,A,3416.1179,N,11818.8508,W,0.04,219.89,191212,,,A*7$GPRMC,160619.000,A,3416.1179,N,11818.8509,W,0.02,219.89,191212,,,A*7$GPRMC,160619.200,A,3416.1177,N,11818.8511,W,0.05,219.89,191212,,,A*7$GPRMC,160619.400,A,3416.1177,N,11818.8511,W,0.01,219.89,191212,,,A*7$GPRMC,160619.600,A,3416.1175,N,11818.8511,W,0.04,219.89,191212,,,A*7$GPRMC,160619.800,A,3416.1175,N,11818.8511,W,0.01,219.89,191212,,,A*7$GPRMC,160620.000,A,3416.1174,N,11818.8512,W,0.03,219.89,191212,,,A*3$GPRMC,160620.200,A,3416.1173,N,11818.8513,W,0.02,219.89,191212,,,A*7$GPRMC,160620.400,A,3416.1172,N,11818.8513,W,0.04,219.89,191212,,,A*7$GPRMC,160620.600,A,3416.1171,N,11818.8513,W,0.04,219.89,191212,,,A*6$GPRMC,160620.800,A,3416.1170,N,11818.8513,W,0.03,219.89,191212,,,A*7$GPRMC,160621.000,A,3416.1170,N,11818.8513,W,0.01,219.89,191212,,,A*7$GPRMC,160621.200,A,3416.1169,N,11818.8514,W,0.01,219.89,191212,,,A*7$GPRMC,160621.400,A,3416.1168,N,11818.8515,W,0.02,219.89,191212,,,A*7$GPRMC,160621.600,A,3416.1167,N,11818.8514,W,0.04,219.89,191212,,,A*7$GPRMC,160621.800,A,3416.1166,N,11818.8515,W,0.05,219.89,191212,,,A*7
$GPRMC,160622.000,A,3416.1165,N,11818.8516,W,0.04,219.89,191212,,,A*7
$GPRMC,160622.200,A,3416.1163,N,11818.8517,W,0.04,219.89,191212,,,A*7$GPRMC,160622.400,A,3416.1162,N,11818.8518,W,0.01,219.89,191212,,,A*7$GPRMC,160622.600,A,3416.1162,N,11818.8519,W,0.04,219.89,191212,,,A*7
and that is the ONLY change I make.
Of course, if it's missing the newline then recvdflag never gets set true, so it doesn't think it's receiving valid sentences.
Also (and forgive my ignorance as I'm just picking up Arduinos this week) but this doesn't really seem interrupt driven. Not that it matters, really, but it seems like you're generating an interrupt with a timer, and then using that to poll. So it still seems like polling but polling at specific intervals, no? (as opposed to an interrupt being generated when data arrives, for example)
Anyway, I don't see how the \n is being lost.
Thanks!

