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 support@ccsinfo.com

ZX4120 GPS module

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



Joined: 19 Jan 2006
Posts: 22

View user's profile Send private message

ZX4120 GPS module
PostPosted: Wed Feb 01, 2006 6:01 pm     Reply with quote

Hi,

I had a ZX4120 GOS module sending serial data at 9600 baud 8N1 directly to a PC via a level converter. This part worked fine.

However, when I instead tried to read the serial data using a PIC18F452 , I ran into problems. I connected the TX line of the GPS directly to the RX line of the PIC (TTL levels), and then sent serial data from the PIC to the PC (via a level converter). I can send data from the PIC to the PC fine - tested with "hello world" etc.

I have simplified my parser down to the stage where it extracts the sentance it wants, then sends it unmodified on to the PC. However, the PC receives garbage. I suspect the problem may be with the baud rate, or could it e something to do with inverted levels between the two devices...?

My code, if anyone can bear to look, is as follows...

Cheers,

Ben

Code:

#include <18F452.h>

#define GPS_RX PIN_C7
#define PC_TX PIN_D2

#define LED        PIN_B0
#define RESET      PIN_B7

#fuses HS,NOWDT,NOPROTECT,NOLVP
#use Delay(Clock=20000000)
#use rs232(baud=9600, rcv=GPS_RX,stream=GPS)  //GPS data from GPS unit
#use rs232(baud=9600, xmit=PC_TX,stream=PC)   //TX line to level converter and PC


   CHAR c;     //Read serial characters into here
   INT buffer_index; //Keep track of position in buffer
   boolean found;  //flag to determine if we have found the NMEA sentance we want
   CHAR GPRMC [60]; //buffer to hold the desired sentance for parsing

   void parse();  //function to do the parsing


void main() {
boolean i;

output_low(RESET);   //reset GPS unit
output_high(LED);
delay_ms(4000);
output_high(RESET);
output_low(LED);

while(TRUE){
int b;

fprintf(PC,"$GPRMC");       //buffer doesn't contain this, so print it directly
for(b=0;b<60;b++){          //loop through array elemts printing them to the PC via link
fprintf(PC,"%c",GPRMC[b]);
}
fprintf(PC,"\n");
delay_ms(2000);
}
}

void parse()
   {
   buffer_index = 0;
   found=FALSE; //initialy, we haven't found the sentance



c=fgetc(GPS);   //read a character from the serial line
WHILE (!found){ 
   WHILE (c != '$')  //keep on reading until we find a '$' - the start of a sentance
   {
      c = fgetc (GPS); 
   }
   c = fgetc (GPS);
   IF (c == 'G')
   {
      c = fgetc (GPS);

      IF (c == 'P')
      {
         c = fgetc (GPS);  //run through subsequent characters to check if it is the one we want

         IF (c == 'R')
         {
            c = fgetc (GPS);

            IF (c == 'M')
            {
               c = fgetc (GPS);

               IF (c == 'C')
               {
                  c = fgetc (GPS);
                  found=TRUE;
                  //If we get here, we have identified NMEA sentance we want. Read it into a buffer.
                  WHILE (c != '$')
                  {
                     c = fgetc (GPS);
                     GPRMC[buffer_index] = c;
                     buffer_index++;
               }
               }
            }
         }
      }
   }
}

   }

PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Feb 01, 2006 6:56 pm     Reply with quote

At a minimum, you should reconfigure your GPS stream so that it uses
the hardware UART. Add the items shown in bold below.
Quote:

define GPS_TX PIN_C6
define GPS_RX PIN_C7

#use rs232(baud=9600, xmit=GPS_TX, rcv=GPS_RX, ERRORS, stream=GPS)
Donlaser



Joined: 17 Sep 2005
Posts: 12
Location: Trenque Lauquen, Argentina

View user's profile Send private message MSN Messenger

PostPosted: Wed Feb 01, 2006 7:36 pm     Reply with quote

Add a call to the parse function in the main loop. The garbage that you get in the pc is the uninitialized content of GRTMC buffer.



while(TRUE){
int b;

parse(); // <<<<<< add this line <<<<<<<

fprintf(PC,"$GPRMC"); //buffer doesn't contain this, so print it directly
for(b=0;b<60;b++){ //loop through array elemts printing them to the PC via link
fprintf(PC,"%c",GPRMC[b]);
Guest








PostPosted: Thu Feb 02, 2006 3:59 am     Reply with quote

Oh dear - I must have been suffering from "it's-too-late-at-night-itus"!
How can I have left out the call to the parsing function!!! It works fine now -
thanks for your efforts.

Cheers,

Ben
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