CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Problem with GPS and UART

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
uni_student



Joined: 01 Aug 2007
Posts: 38
Location: AUckland, NEW ZEALAND

View user's profile Send private message Send e-mail MSN Messenger

Problem with GPS and UART
PostPosted: Mon Aug 10, 2009 4:29 am     Reply with quote

Hi, trying to send UTC clock from GPS RMC format to hyperterminal, but all sorts of gibberish is showing. Settings are all correct as have tried to send 'printf("ABC123"),' which works. Any help appreciated!

Note: running on 3.3V, pull down resistor on tx pin, 3.3V rs232 line driver used

Code:
#include <18f1220.h>
#fuses HS,NOWDT,NOPROTECT

#use delay(clock=10000000)
#use rs232(baud=9600, xmit=PIN_B1, rcv=PIN_B4, parity=N, bits=8, ERRORS)

char gps[200], temp[20];
int i, j;

#define LED PIN_B5

void main(){
   while(TRUE){
      gets(gps);
      if((gps[2]=='P')&&(gps[3]=='R')&&(gps[4]=='M')&&(gps[5]=='C')){
         output_high(LED);
         delay_ms(100);
         output_low(LED);
         for(i=7;i<=16;i++){
            j=i-7;
            temp[j]=gps[i];
         }
         printf(temp);
      }
   }
}
mskala



Joined: 06 Mar 2007
Posts: 100
Location: Massachusetts, USA

View user's profile Send private message

PostPosted: Mon Aug 10, 2009 9:38 am     Reply with quote

Knowing the length of GPS sentences, it is practically impossible that your copy includes the string terminator. The string terminator '\0' (or integer 0) is required by all string functions, including printf. You need to add it to the end of any string created the way you're doing it. Otherwise it will print all kinds of junk after where you wanted it to stop.
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

Re: Problem with GPS and UART
PostPosted: Mon Aug 10, 2009 11:18 am     Reply with quote

uni_student wrote:
Hi, trying to send UTC clock from GPS RMC format to hyperterminal, but all sorts of gibberish is showing. Settings are all correct as have tried to send 'printf("ABC123"),' which works. Any help appreciated!

Code:

#use rs232(baud=9600, xmit=PIN_B1, rcv=PIN_B4, parity=N, bits=8, ERRORS)


In addition to what mskala says...

NMEA defaults to 4800 baud, not 9600.

While so many GPS's support 9600 (and higher), the safest bet is 4800.


Also, as I have mentioned in another post. Think state machine.

You are gathering a stream of chars from a GPS.

Get chars and wait for '$'....
Start stuffing subsequent chars into a string. Is the char a CR or LF?
End the string with \0
then parse the string someplace else...

Don't forget to stop your ISR (if you have one) from continuing to stuff chars into the holding string while you copy it to a temp holder.
Then release the ISR while you process the string that was just received.

Cheers,

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group