GPS code not working
guru1
Posts: 8
I'm having problems with a code I'm using to test my Parallax GPS receiver module to get NMEA0183 data format to my pc. The code compiled succesfully but was unable to retrieve any GPS coordinates. I would like to know whether·I have to be in raw mode in order to access the GPSRMC strings. The code is attached below. I'm using a BS2P24 microcontroller.
' {$STAMP BS2p}
' {$PBASIC 2.5}
' {$PORT COM1}
'By Randy Price - March 2002
'Program to read in GPS coordinates from the NMEA 0183 GPRMC statement
gpstime VAR Word
N VAR Word
W VAR Word
NN VAR Word
WW VAR Word
speed1 VAR Word
speed2 VAR Nib
course1 VAR Word
course2 VAR Nib
'Baud rate:
n9600 CON 500
main:
'Get next GPS RMC statement at 9600 baud pin 15
SERIN 15,n9600,2100,noGPS1,[noparse][[/noparse]WAIT("RMC,"),DEC gpstime, SKIP 3, DEC N, DEC NN, SKIP 3, DEC W, DEC WW, SKIP 3, DEC speed1, DEC speed2, DEC course1,DEC course2]
GOSUB output1
GOTO main
'******************************************* OUTPUT ROUTINE *******************************************
output1:
'output to terminal at 9600 baud
SEROUT 16,n9600,[noparse][[/noparse]DEC gpstime,",",DEC W]
IF WW < 10 THEN gps1
IF WW < 100 THEN gps2
IF WW < 1000 THEN gps3
SEROUT 16,n9600,[noparse][[/noparse]".",DEC WW]
GOTO gpsNN
gps1:
SEROUT 16,n9600,[noparse][[/noparse]".000",DEC WW]
GOTO gpsNN
gps2:
SEROUT 16,n9600,[noparse][[/noparse]".00",DEC WW]
GOTO gpsNN
gps3:
SEROUT 16,n9600,[noparse][[/noparse]".0",DEC WW]
GOTO gpsNN
gpsNN:
SEROUT 16,n9600,[noparse][[/noparse]",W,",DEC N]
IF NN < 10 THEN gps4
IF NN < 100 THEN gps5
IF NN < 1000 THEN gps6
SEROUT 16,n9600,[noparse][[/noparse]".",DEC NN]
GOTO gpsend
gps4:
SEROUT 16,n9600,[noparse][[/noparse]".000",DEC NN]
GOTO gpsend
gps5:
SEROUT 16,n9600,[noparse][[/noparse]".00",DEC NN]
GOTO gpsend
gps6:
SEROUT 16,n9600,[noparse][[/noparse]".0",DEC NN]
GOTO gpsend
gpsend:
SEROUT 16,n9600,[noparse][[/noparse]",N,"]
'End Data output from GPS
SEROUT 16,n9600,[noparse][[/noparse]DEC speed1,".",DEC speed2,",",DEC course1,".",DEC course2,10,13]
RETURN
'************************************** GPS Not Detected Routine ***************************************
nogps1:
DEBUG "no gps",CR
GOTO MAIN
' {$STAMP BS2p}
' {$PBASIC 2.5}
' {$PORT COM1}
'By Randy Price - March 2002
'Program to read in GPS coordinates from the NMEA 0183 GPRMC statement
gpstime VAR Word
N VAR Word
W VAR Word
NN VAR Word
WW VAR Word
speed1 VAR Word
speed2 VAR Nib
course1 VAR Word
course2 VAR Nib
'Baud rate:
n9600 CON 500
main:
'Get next GPS RMC statement at 9600 baud pin 15
SERIN 15,n9600,2100,noGPS1,[noparse][[/noparse]WAIT("RMC,"),DEC gpstime, SKIP 3, DEC N, DEC NN, SKIP 3, DEC W, DEC WW, SKIP 3, DEC speed1, DEC speed2, DEC course1,DEC course2]
GOSUB output1
GOTO main
'******************************************* OUTPUT ROUTINE *******************************************
output1:
'output to terminal at 9600 baud
SEROUT 16,n9600,[noparse][[/noparse]DEC gpstime,",",DEC W]
IF WW < 10 THEN gps1
IF WW < 100 THEN gps2
IF WW < 1000 THEN gps3
SEROUT 16,n9600,[noparse][[/noparse]".",DEC WW]
GOTO gpsNN
gps1:
SEROUT 16,n9600,[noparse][[/noparse]".000",DEC WW]
GOTO gpsNN
gps2:
SEROUT 16,n9600,[noparse][[/noparse]".00",DEC WW]
GOTO gpsNN
gps3:
SEROUT 16,n9600,[noparse][[/noparse]".0",DEC WW]
GOTO gpsNN
gpsNN:
SEROUT 16,n9600,[noparse][[/noparse]",W,",DEC N]
IF NN < 10 THEN gps4
IF NN < 100 THEN gps5
IF NN < 1000 THEN gps6
SEROUT 16,n9600,[noparse][[/noparse]".",DEC NN]
GOTO gpsend
gps4:
SEROUT 16,n9600,[noparse][[/noparse]".000",DEC NN]
GOTO gpsend
gps5:
SEROUT 16,n9600,[noparse][[/noparse]".00",DEC NN]
GOTO gpsend
gps6:
SEROUT 16,n9600,[noparse][[/noparse]".0",DEC NN]
GOTO gpsend
gpsend:
SEROUT 16,n9600,[noparse][[/noparse]",N,"]
'End Data output from GPS
SEROUT 16,n9600,[noparse][[/noparse]DEC speed1,".",DEC speed2,",",DEC course1,".",DEC course2,10,13]
RETURN
'************************************** GPS Not Detected Routine ***************************************
nogps1:
DEBUG "no gps",CR
GOTO MAIN
Comments
If you’re trying to access the RAW strings then you need to tie the /RAW pin LOW. Without that the GPS only responds to commands send with the “!GPS” header. Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support