Shop OBEX P1 Docs P2 Docs Learn Events
Code to determine exact NMEA sentence data — Parallax Forums

Code to determine exact NMEA sentence data

PKilbournPKilbourn Posts: 4
edited 2009-04-14 16:20 in BASIC Stamp
I am using several marine instruments (GPS, wind, speed, compass, weather station) to send data to a BS2.· Most instruments come with manuals that describe the sentence structure of the NMEA data that is being sent.· But I have found that the manual description is not always accurate.· I wrote the following code that parses an incoming NMEA sentence so I can see its precise structure.· The precise structure must be known in order to write a SERIN command that correctly parses and stores the incoming data.· I have attached the code, and also printed it here.· Would appreciate it if anyone has any suggestions to make it work better.
' Read any NMEA sentence
' This program reads each element of a NMEA sentence and then
' displays the decimal number and the ASCII character
' It runs until receiving the carriage return at the end of the sentence.
' In the first SERIN line, replace the three characters with the NMEA
' characters of the sentence of interest coming from the NMEA talker.
' NMEA talker is wired into a Basic Stamp2 with serial pins 3 and 5
' Let the program run, then scroll up/down the debug screen to see all data.
' {$STAMP BS2}
' {$PBASIC 2.5}
B4800 CON 16572········ ' 4800 baud
element·· VAR·········· Byte(12)
counter·· VAR·········· Nib
comma···· VAR·········· Byte
RxD······ CON 4········ ' serial I/O pin 4 receives NMEA Talker Data

DEBUG "Running", CR
comma = 0
Main:
··· ' Read the NMEA Talker
· SERIN RxD, B4800, [noparse][[/noparse]WAIT ("MWV,"), SKIP (comma), element(1), element(2), element(3), element(4), element(5),element(6), element(7), element(8), element(9), element(10) ]
· FOR counter = 1 TO 10
· IF element(counter) = 44 THEN GOTO Reset '44 is a comma signaling end of a data element
· IF element(counter) = 13 THEN GOTO Done· '13 is a carriage return; end of sentence
· DEBUG DEC counter, " ", DEC element(counter), " ", ASC? element(counter), CR
· NEXT
Reset:
·· comma = counter + comma
·· DEBUG CR
·· GOTO Main
Done:
· DEBUG "End of data stream"

· END

Comments

  • Craig EidCraig Eid Posts: 106
    edited 2009-04-14 16:20
    PKilborn,

    Your post does not indicate if you are receiving data from the GPS module - is it functioning? What specific problems are you encountering? Click here·for an explanation of NMEA sentences.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ························ Craig Eid


    ··········· Triad Research and Development
    Electical Engineering Design and Consulting Services

    ··················· www.TriadRD.com
Sign In or Register to comment.