Help me write a code for reading the whole string from GPS

Status
Not open for further replies.

DrWhoF

Advanced Member level 1
Joined
May 6, 2005
Messages
402
Helped
24
Reputation
48
Reaction score
11
Trophy points
1,298
Activity points
4,388
Reading GPS

Can someone help me in writing a code (asm for 8051) which will read the whole string from GPS through one serial port and output only Lat-Long information without other characters through another serial port.
Thanks
DrWhoF
 

Re: Reading GPS

What you need to implement and what will be very handy later is serial port interrupt subroutine. If you don't know how to do this check out this code:
https://www.pjrc.com/tech/8051/uartintr.asm
Make sure that it is working correctly. To do this connect your µP ( I assume that you have RS-232 driver such as MAX202, 232 ..) to a PC and start any terminal software. Write a short program that will read a ASCII character, for example "A" (code 41h) and if your microcontroller reads it then it should send back another ASCII character, say, "B" (code 42h).
Once you have this done, come back, and we can go into reading GPS strings..
Regards,
IanP
 

    DrWhoF

    Points: 2
    Helpful Answer Positive Rating
Re: Reading GPS

Thanks veryt much for your help.
I am trying to figure out what actually should be in the Main Routine. This link has several subroutines, but I couldn't find any code which calls routines such as num_recv , num_xmit and others.
Thanks.
 

Re: Reading GPS

I hope yoy have done all initial steps such as declarations, memory organization for the main code and serial port interrupt, set SP etc. etc.
Next, you will have to call "init_uart_intr" (from the link provided previously).
After all this you can start your Main Loop; here is an example:

The microcontroller will be spendig here most of its time, interrupted by the serial port when a character arrives.
If RxBuffTail is not equal to RxBuffHead the program will branch to Ser_Rout.

We are not calling "cin" subroutine but "cin2" instead.
In the "cin2" after:
MOV A, @R0
add line:
MOV SerData, A
and also declere SerData as BYTE.

So now the Ser_Rout may look like this:
Ser_Rout:
MOV A, SerData
LCALL Count .. Count puts this byte in the Tx buffer and sets serial interrupt for transmission ..
RET .. ends this short routine ...

Try this and let us know how it goes ..
Regards,
IanP
 

    DrWhoF

    Points: 2
    Helpful Answer Positive Rating
Re: Reading GPS

The code you suggested seems to be working fine. My circuit echoes characters which are pressed on the keyboard.
Can you help me with GPS reading?
Thanks
DrWhoF
 

Re: Reading GPS

Which NMEA sentence will you be decoding:
$GPGLL, $GPGGA, $GPBWC ... ?
I would suggest the first one, GLL that is:

So, before you decide which sentence you prefer, define bits for all digits in Latitude and Longitude strings including N/S and E/W.
So you will have something like this:
Also, define bytes for each Lat/Long digit:

Other thing is that if you are going to use 8051 you may run out of available RAM as we need some bytes for TxBuffer and RxBuffer too.
My suggestion is that you use 8052 (or its version with EPROM, Flash ...)
Then you can shift Tx and Rx buffers to the second section of RAM, which is addressable by R0 and R1, and what is already implemented in the serial port interrupt routine.
I suggest thet we put these buffers here:
RxBuff DATA 0B0h
TxBuff DATA 0E0h

So make declarations, definitions etc. etc. and select the NMEA sentence ..

Regards,
IanP
 
Re: Reading GPS

Thanks for your help.
$GPGLL will be perfect.
In your example Latitude and logitude use 4 digits after the decimal point. What if my GPS receiver can produce only 3?
Thanks
DrWhoF
 

Re: Reading GPS

This program senses number of digits between commas and it really doesn't matter whether your GPS receiver sends 2, 3 or 4 digits after decimal pont ..
Post or PM your e-mail address so I can send it (the code) to you, as I don't think it is practical to discuss here another ≈400 lines of code ..
Regards,
IanP
 

    DrWhoF

    Points: 2
    Helpful Answer Positive Rating
    V

    Points: 2
    Helpful Answer Positive Rating
Re: Reading GPS

Thanks for your help.
I will PM my e-mail address to both of you.
Please send C-code and ASM.
Thanks.
DrWhoF
 

Re: Reading GPS

2 files: gps.c and gps1.c, there are source to 8051 read from serial a gps protocoll nmea, used SDCC compiler
 
Re: Reading GPS

could u please send me the gps.c and gps1.c files
 

Re: Reading GPS

hi all,
i wanna update a bus clock with gps time signal. but i dont know which module can be usefull for me. any suggestion?
there are a lot of gps module at globalsources web site but no datasheet published well, can all modules get the time signal via satellite or this modules can be used only navigation?
please advise...
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…