circuitcellar.com
Magazine Support   Digital Library   Products & Services   Suppliers Directory 
 
 





 

August 1999, Issue 109

Where in the World (Part 1):
GPS Introduction

NMEA-0183 PROTOCOL BASICS

NMEA protocols NMEA-0180/182 differ in the types of messages that are sent and are much more limited than NMEA-0183. NMEA-0183 is the most general and supports many different kinds of navigation equipment including GPS, which is why I’m going to talk about this protocol.

Its basic structure consists of sentences that are generated by a "talker." There is one talker and one or more listeners on a "bus." The standard doesn’t dictate what the physical and electrical specs of the bus are, but typically, it’s RS-232 or RS-422. It could also be optical or whatever fits your application.

A sentence is a CR/LF-terminated line that is encoded in standard ASCII. I like protocols that are human readable. It makes it easy to use a terminal or terminal emulator to monitor the protocol during debugging.

Each sentence starts with a $ and ends with a * and an optional 8-bit checksum expressed as two hexadecimal characters. The characters themselves are transmitted without parity. The checksum is computed by performing an 8-bit XOR over the text of the sentence, not including the start ($) and end (*) markers.

The sentence inside the markers consists of a list of comma-separated fields. The number of fields is predefined for a particular message type. If there isn’t any data for a particular field, a two-comma "null" field can be sent. In other words, you leave out the data, but keep the field separator.

The first field of the sentence identifies what kind of sentence you have and encodes what kind of talker sent the message. NMEA assigns several talker IDs, which are the first two characters of this field.

For GPS, the talker ID is GP. Other examples of talker IDs are:

• LC—Loran C Receiver

• OM—Omega Receiver

• HC—Magnetic Compass

• P—Proprietary (typically PG if it’s GPS)

Following the talker ID, there is a sentence-type ID, which is a three-character ID that tells what kind of information is encoded in the remaining fields. The types are defined by the NMEA standard.

proc nmea_checksum {sent} {
  set len [string length $sent]
  set sum 0
  set val 0
  for {set i 0} {$i < $len} {incr i} {
    set char [string index $sent $i]
    if {$char == "\$"} continue
    if {$char == "\*"} break
    binary scan "$char" c val
    set sum [ expr $sum ^ ($val % 128)]
  }
  return [format "%02X" [expr $sum % 256]]
}
Listing 1—This Tcl code for computing the NMEA checksum is simply the
 XOR of all the ASCII characters between the start ($) and end (*) tokens 
(exclusive).

At this point, it’s probably best to show you an example. Here’s a typical message sent by one of my GPS receivers:

$GPRMC,132515,A,3908.8652,N,08625. 1367,W,0.387,4.6,290499,2.9,W*7V

You can see the start and end markers as well as a checksum. Listing 1 shows the routine I used to compute the checksum.

The first field, "GPRMC", means that the sentence originated from a GPS receiver (GP) and is a recommended minimum specific-to-GPS/transmit data (RMC) sentence. The generic RMC format is:

RMC,<time of fix>,<status>,<latitude>, <latitude sense>,<longitude>, <longitude sense>,<speed over gound>, <course>, <date of fix>,<magnetic deviation>

So, the sample message was a fix on April 29, 1999, at 13:25:15 UTC, and the location is 39°08.8652¢ north and 86°25.1367¢ west. The current course is 4.6° true, and we are traveling at a speed of 0.387 knots. The magnetic deviation is 2.9° west. The "A" for status means the data is good. The "V" means that the receiver is not locked in.

 

CEP

DRMS 2 DRMS
hpos 40 m 50 m 100 m
vpos 47 m 70 m 70 m
spherical 76 m 86 m 172 m
velocity - 0.1 mps 0.2 mps
time gps 95 ns 140 ns 280 ns
time utc 115 ns 170 ns 340 ns
Table 1—Take a look at the positioning errors for the civilian standard position service (SPS).

Note that although the message has a speed and heading indication, the receiver was actually stationary. I’ll get to that in a bit.

Other common messages sent by GPS receivers are the GGA (global positioning fix data), GSA (GPS DOP and number of satellites), and GSV (satellites in view).

The formats for these are:

• GPGGA,<fix time>,<latitude>,<latitude sense>,<longitude>,<longitude sense>, <GPS quality[012]>, <num satellites>, <HDOP>,<sea level>, <units[M]>, <geoidal separation>, <units[M]>,<null>,<null>

•GPGSA,A,<fix mode[0123]>,<sat. PRN>, <PDOP>,<HDOP>,<VDOP>

• GPGSV,<num of msgs>,<msg num>, <sats in view>,<sat PRN>,<elev.>, <asim.>,<signal strength>,<sat PRN>, <elev.>,<asim.>,<signal strength>, <sat PRN>,<elev.>,<asim.>,<signal strength>

With respect to the GPS quality and fix mode information in the GGA and GSA formats, the messages are 0 for invalid, 1 for GPS, 2 for DGPS and 0 for none, 2 for 2D, and 3 for 3D, respectively. In the GSA format, PRN stands for pseudo random number for satellite, PDOP stands for 3D dilution of precision, HDOP is horizontal dilution of precision, and VDOP means vertical dilution of precision.

An NMEA talker will send a group of messages at a time. Different receivers send different kinds of messages and the rate of the messages varies, typically from 0.5 to 8 s. In some GPS receivers, rate and message types can be adjusted either with a proprietary message or through the user interface, if it has one.