Added interrupt support
Added interrupt support to shield_sdlog sketch
This commit is contained in:
parent
5f0415ee68
commit
defdba557d
|
|
@ -26,6 +26,11 @@ Adafruit_GPS GPS(&mySerial);
|
|||
/* set to true to only log to SD when GPS has a fix, for debugging, keep it false */
|
||||
#define LOG_FIXONLY false
|
||||
|
||||
// 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
|
||||
|
||||
// Set the pins used
|
||||
#define chipSelect 10
|
||||
#define ledPin 13
|
||||
|
|
@ -46,7 +51,7 @@ uint8_t parseHex(char c) {
|
|||
|
||||
// blink out an error code
|
||||
void error(uint8_t errno) {
|
||||
/*
|
||||
/*
|
||||
if (SD.errorCode()) {
|
||||
putstring("SD error: ");
|
||||
Serial.print(card.errorCode(), HEX);
|
||||
|
|
@ -102,10 +107,12 @@ void setup() {
|
|||
|
||||
logfile = SD.open(filename, FILE_WRITE);
|
||||
if( ! logfile ) {
|
||||
Serial.print("Couldnt create "); Serial.println(filename);
|
||||
Serial.print("Couldnt create ");
|
||||
Serial.println(filename);
|
||||
error(3);
|
||||
}
|
||||
Serial.print("Writing to "); Serial.println(filename);
|
||||
Serial.print("Writing to ");
|
||||
Serial.println(filename);
|
||||
|
||||
// connect to the GPS at the desired rate
|
||||
GPS.begin(9600);
|
||||
|
|
@ -122,13 +129,54 @@ void setup() {
|
|||
// Turn off updates on antenna status, if the firmware permits it
|
||||
GPS.sendCommand(PGCMD_NOANTENNA);
|
||||
|
||||
// the nice thing about this code is you can have a timer0 interrupt go off
|
||||
// every 1 millisecond, and read data from the GPS for you. that makes the
|
||||
// loop code a heck of a lot easier!
|
||||
useInterrupt(true);
|
||||
|
||||
Serial.println("Ready!");
|
||||
}
|
||||
|
||||
|
||||
// Interrupt is called once a millisecond, looks for any new GPS data, and stores it
|
||||
SIGNAL(TIMER0_COMPA_vect) {
|
||||
char c;
|
||||
while (mySerial.available())
|
||||
{
|
||||
c = GPS.read();
|
||||
// if you want to debug, this is a good time to do it!
|
||||
#ifdef UDR0
|
||||
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.
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
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() {
|
||||
char c = GPS.read();
|
||||
char c;
|
||||
while (mySerial.available())
|
||||
{
|
||||
c = GPS.read();
|
||||
if (GPSECHO)
|
||||
if (c) Serial.print(c);
|
||||
}
|
||||
|
||||
// if a sentence is received, we can check the checksum, parse it...
|
||||
if (GPS.newNMEAreceived()) {
|
||||
|
|
@ -161,3 +209,4 @@ void loop() {
|
|||
|
||||
|
||||
/* End code */
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue