Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
0

GPS Breakout Parsing
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

GPS Breakout Parsing

by Chatty on Sat Sep 01, 2012 1:46 am

Hi all,

Ultimate GPS up and running beautifully and all going well - one small question though. I've been running the Parsing sketch and all has been fine. However, i'm struggling to understand what the middle section of code is actually doing;

Code: Select all | TOGGLE FULL SIZE
// 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;
  }
}


Can anyone break this down for me? I'm pretty sure some of it Hex (?) but i'm really not able to understand what this section of the sketch is doing.

Regards,

Chatty
Chatty
 
Posts: 10
Joined: Sat Sep 01, 2012 1:41 am

Re: GPS Breakout Parsing

by adafruit_support_bill on Sat Sep 01, 2012 6:04 am

It is using the timer0 interrupt to poll the GPS software serial port every millisecond. If it finds a character, it copies it to the hardware serial port. It writes directly to Tx via UDR0 for speed.

adafruit_support_bill
 
Posts: 77925
Joined: Sat Feb 07, 2009 10:11 am

Re: GPS Breakout Parsing

by Chatty on Tue Sep 04, 2012 4:53 am

Thanks for the response. i'm wondering if you can provide any more background though on the commands - i've gone through the Arduino reference library (at arduino.cc) but the commands seem to be slightly different.

eg;
SIGNAL doesn't appear in the library
The function of the useInterrupt section, specifically the terms OCR0A and TIMSK0.

I'm keen to utilise some of this code in making a speedo for a kayak, but i'd rather understand what the code is doing rather than just copying it. Hopefully makes it a bit easier to work out when it goes wrong!

Chatty
Chatty
 
Posts: 10
Joined: Sat Sep 01, 2012 1:41 am

Re: GPS Breakout Parsing

by Chatty on Tue Sep 04, 2012 5:31 am

Actually, as a thought, is the library for the Ultimate GPS documented somewhere?

It may resolve this issue. Currently trying to learn the coding via the sample codes.

Chatty
Chatty
 
Posts: 10
Joined: Sat Sep 01, 2012 1:41 am

Re: GPS Breakout Parsing

by adafruit_support_bill on Tue Sep 04, 2012 6:52 am

i've gone through the Arduino reference library (at arduino.cc) but the commands seem to be slightly different.

The Arduino language is a thinly wrapped subset of C++ and the library provides a rather simplified view of the underlying AVR architecture. The Arduino environment as a whole was designed with simplicity rather than performance in mind. However, it does not prevent you from accessing the more powerful and higher performance features under the hood.

The GPS sample code makes direct use of some AVR functions and constructs to set up and handle the timer interrupt. You can find documentation for the AVR processors and a programmers reference guide here:http://www.atmel.no/univ_prog/index.php?option=com_weblinks&catid=23&Itemid=44

adafruit_support_bill
 
Posts: 77925
Joined: Sat Feb 07, 2009 10:11 am

Re: GPS Breakout Parsing

by Chatty on Tue Sep 04, 2012 7:48 am

So, is there a simplified Arduino library for the GPS shield that covers off on all of the coding required to parse data fully, or do we use the mashup of AVR/Arduino code like in the example files (parsing.pde etc)?

Chatty
Chatty
 
Posts: 10
Joined: Sat Sep 01, 2012 1:41 am

Re: GPS Breakout Parsing

by adafruit_support_bill on Tue Sep 04, 2012 8:34 am

It is a mix of AVR and Arduino code.

adafruit_support_bill
 
Posts: 77925
Joined: Sat Feb 07, 2009 10:11 am

Re: GPS Breakout Parsing

by Chatty on Tue Sep 04, 2012 10:05 am

Cheers, cut and paste it is!

Chatty
Chatty
 
Posts: 10
Joined: Sat Sep 01, 2012 1:41 am

Please be positive and constructive with your questions and comments.