Hi Sérgio,
It's difficult to receive NMEA sentences by parsing them directly with SERIN2.
Especially if you want to do anything with the data, such as print it out on an LCD.
There is no time between sentences. The next sentence starts coming in immediately after the last one. So, when you take the time to display the results, you miss the beginning of the next one.
The GPS receiver will start sending sentences as soon as it's powered up, so it's easy to miss the first one. From there you will only catch every other sentence.
For example, with the following sequence, The first RMC will be missed do to start up time. So, the first sentence to be received will be the GGA. The next one (GSA) gets missed while displaying the GGA, so it sees GSV next. After that it catches the last GSV and skips the next one which will be another RMC. So, it never sees an RMC sentence, which is the one you want the most.
$GPRMC,130717,V,5128.7968,N,00143.4973,E,084.3,112 .1,200106,,,N*61
$GPGGA,130718,5118.7968,N,00043.4973,E,0,00,,00638 .1,M,050.8,M,,*53
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPGSV,3,1,09,02,32,307,00,04,66,250,48,07,04,220, 00,10,01,282,00*71
$GPGSV,3,2,09,13,81,200,00,16,04,066,00,20,29,100, 45,23,60,065,52*71
$GPGSV,3,3,09,24,45,169,37,,,,,,,,,,,,*4D
You say that you only get GGA's. It's possible that your receiver only sends RMC and GGA since the others just give useless info about the satellites. So the example might not fit perfectly with your symptoms. Once you get it hooked up to the PC, you should be able to tell.
With that said, if you want to recieve just the RMC, you can change the wait modifier to look for the whole sentence name.
SERIN2 GPSIN,188,2000,Nogps,[WAIT("$GPRMC"),str sats\1 ....
This will insure that it never gets skipped. If you also want to read the GGA you should have a second SERIN2 that looks for that one immediately after the RMC. Now you've got some time to calculate and display before the next RMC comes in.
Also, keep in mind that some of the fields are variable length. You can't always rely on everything being in the same place all the time.
The best way to parse NMEA data is to receive the entire sentence into a buffer using the USART and interrupts. Then, calculate the checksum by xoring all the bytes together, and compare it with the checksum in the sentence. If they aren't the same, dump the data. Then run through the buffer and "count commas" to seperate the fields. Using this method, you won't miss a thing, and there's plenty of time to do it, and run the rest of your program too.
As for hooking it up to the PC, Yes, GPS TX to the PC RX, and vice versa. You'll also need a MAX 232 or equiv. If the receiver uses 5v levels.
Bookmarks