|
DAN141
Interface to a GPS Receiver
By Michael
Simpson

Ever wanted to connect a GPS receiver up to
your bot? How bout building a data logger for your RC helicopter?
What about a black box that keeps track of location telemetry for later
recovery? What ever the reason I think this paper may help you do
just that.
One of the main reasons I wanted to do this
project was so I could put the string handling features of the Dios to
use. It went well beyond my wildest dreams.
What I have found
I'm not going to give you step by step
instructions as there are just too many GPS units out there. Even
the output spec varies a bit from unit to unit.
Most will out put NMEA protocol in one form
or another. 4800 baud seems to be the most common serial speed.
However the connectors from unit to unit will vary. The output
levels from the units will also vary. Most are setup as DCE RS232.
I chose the Magellan meridian platinum for
a couple of reasons.
-
It has a selectable NMEA 1.5 APA, 1.5
XTE, and 2.1 GSA
-
Selectable baud rates from 1200-115200
-
A simulation mode for testing
Build your connector
Probably the biggest problem you will have
is getting connected to your GPS. My Meridian Platinum came
with serial cable. The cable is designed to plug into the PC.
This makes the GPS a DCE unit. As a DCE unit the data is
transmitted out on pin2.
To connect a DCE device to the Dios you
have two choices
Choice 1 is to purchase null modem cable.
Jameco has one for $6 (181403). and connect to an existing RS232
Driver. Note that if you have a null cable and a Dios Ultra
Board or Dios Ultra Board mini you can configure the onboard driver to
connect to the built in UART.
Choice 2 is to slightly modify the EZRS232
driver to interface to a DCE.

You will need a male 9 pin connector.
You can get this from Jameco (15747) and a 4 pin right angle header.
Connect the header to pins 2-5 with the
pins facing out as shown. Solder in place

Cut the 2 center pins away.

Insert the two pins as shown into the
bottom of the board. Solder in place.
Assemble the remainder of the EZRS232
according to instructions
Schematics

Program Download it here
Let me talk about the program a bit.
It was written so that you can tweak it for your Receiver. Since the
different units could output the information needed using various NMEA
commands I decided to make it so minor changes could be made.
I'm using the NMEA 2.1 GSA interface and
the $GPRMC command gather the data I wanted.
getGPS()
This routine is the main entry to into the
routines that will pull the data from the GPS unit. I don't actually
pull the data in the background because I don't want to mess with the
print display routine. So when I enter the getGPS routine I start
the UART and when I exit I turn it back on.
When the UART is started it automatically
handles all the receive data. This is all done behind the scenes.
The main loop just checks the buffer and pulls it out and places it in the
main data string. Once we receive a complete line of data we check
the string to see if the $GPRMC was at the beginning of the line.
Once the correct line is received we call
the procGPRMC() function.
procGPRMC()
Here we parse the various fields by calling
the 3 support routines. This is where you can tweak the interface.
GPSfield(fld)
This routine pulls the field from the
captured string and places that field in the strtest string. We will
access this string with other functions.
GPSfieldval(pos,len)
This returns a 16bit word from the strtest
string. You can specify the starting position and length of what to
pull off.
GPSfloatval(pos,mode)
This does the same as above but returns a
floating point number.
func main()
global hour,min,sec,day,month,year
global longdeg
global latdeg
global latmin as float
global longmin as float
global strdat(80) as string
global strtest(80) as string
global strtemp(80) as string
global speed as float
global dir as float
global latdir
global longdir
clear
hsersetup baud,HBAUD57600
loop:
getGPS()
print "-----------------------------"
print latdeg," ",{-6.4} latmin, " ",nodec latdir
print longdeg," ",{-6.4} longmin, " ",nodec longdir
print
print "dir ",{4.1} dir
print "speed ", {3.1} speed
print
DECMASK = %10000011
print day,"/",month,"/",year," ",hour,":",min,":",sec
DECMASK = %11111111
print "-----------------------------"
goto loop
endfunc
'--------------------------------------------------------
func getGPS()
dim dat,stat
clear strdat,strtest
hsersetup start,clear
loop:
hserin loop,dat
if dat = 13 then goto loop
if dat = 10 then
STRgetword(strdat,1,',',strtest)
stat = STRinstr(strtest,"$GPRMC")
if stat <> 1000 then
hsersetup stop
procGPRMC()
exit 0
goto loop
endif
clear strdat,strtest
goto loop
endif
strdat = * + dat
goto loop
endfunc
'------------------------------------------
func procGPRMC()
'Get Time
GPSfield(2)
hour=GPSfieldval(0,2)
min=GPSfieldval(2,2)
sec=GPSfieldval(4,2)
'Get Date
GPSfield(10)
day=GPSfieldval(0,2)
month=GPSfieldval(2,2)
year=GPSfieldval(4,2)
'Get Speed
GPSfield(8)
speed = GPSfloatval(0) * 1.15207
'Get Dir
GPSfield(9)
dir = GPSfloatval(0)
'get lat
GPSfield(4)
latdeg = GPSfieldval(0,2)
latmin = GPSfloatval(2)
GPSfield(5)
latdir = #strtest
'Get Long
GPSfield(6)
longdeg = GPSfieldval(0,3)
longmin = GPSfloatval(3)
GPSfield(7)
longdir = #strtest
endfunc
'------------------------------------------------------
'GPS Support Routines
'------------------------------------------------------
func GPSfield(fld)
STRgetword(strdat,fld,',',strtest)
endfunc
'-------------------------------------------------------
function GPSfieldval(pos,len)
dim tval
strtemp = strtest(pos,len) : tval = STRval(strtemp)
exit tval
endfunc
'-------------------------------------------------------
function GPSfloatval(pos,mode) as float
dim decpos
dim tlen,x,mult
dim lval as float
dim rval as float
'clear rval,lval
if OPP8 <> 2 then
strtemp = strtest(pos,255)
else
strtemp = strtest(pos,mode)
endif
'Locate decimal point
decpos = STRinstr(strtemp,".")
lval = STRval(strtemp,".")
if decpos <> 1000 then
rval = STRval(decpos+1)
tlen = STRlen(decpos+1)
for x = 0 to tlen - 1
rval = rval / 10.0
next
lval = lval + rval
exit lval
else
exit lval
endif
endfunc
include \lib\DiosString.lib
Parts
list
DiosPro 40 Pin Chip
Dios Workboard
Deluxe
Easy RS232 Driver
DiosPro 28 Pin Chip
Dios 32 Pin Carrier
(Carrier #1)
9 Pin Cable
Breadboard Regulator
|