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

gps data logger

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



Joined: 27 Nov 2008
Posts: 11

View user's profile Send private message AIM Address ICQ Number

gps data logger
PostPosted: Thu Nov 27, 2008 3:38 am     Reply with quote

Hi. I'm just trying to log gps nmea data. I don't know what's wrong in my code.
My controller hangs at a particular point** and restarts itself. Can any body tell what's wrong in it ?
Code:

 while (Rec_Data != '$')
         {
            Rec_Data = bgetc();
            #ASM
                CLRWDT
            #ENDASM
         }
         Rec_Data = bgetc();
         Rmc_Data[0] = Rec_Data;
         if(Rec_Data == 'G')
         {
             Rec_Data = bgetc();
             Rmc_Data[1] = Rec_Data;
             if(Rec_Data == 'P')
             {
                 Rec_Data = bgetc();
                 Rmc_Data[2] = Rec_Data;
                 if(Rec_Data == 'R')
                 {
                    Rec_Data = bgetc();
                    Rmc_Data[3] = Rec_Data;
                    if(Rec_Data == 'M')
                    {
                       Rec_Data = bgetc();
                       Rmc_Data[4] = Rec_Data;
                       if(Rec_Data == 'C')
                       {
                           Rec_Data = bgetc();   /////1
                           Rmc_Data[5] = Rec_Data;
                           if(Rec_Data == ',')
                           {
                              Rec_Data = bgetc();
                              Rmc_Data[6] = Rec_Data;
                              i=7;

                              while(Rec_Data != ',')
                              {
                                 Rec_Data = bgetc();   /////2
                                 Rmc_Data[i] = Rec_Data;
                                 i++;
                              }
                              Rec_Data = bgetc();
                              Rmc_Data[i] = Rec_Data;
                              if(Rec_Data == 'A')
                              {
                                 OUTPUT_HIGH(Led2);
                                 Ok_Data = 1;
                              }
                              i++;
                              while(Rec_Data != '13')   //it always restart at this point
                              {                          //because controller hang here
                                  Rec_Data = bgetc();   //usually happen in while/for loop
                                  Rmc_Data[i] = Rec_Data;
                                  i++;
                              }
                           }
                       }
                    }
                 }
             }
         }
         first = 0;
         if(Ok_Data == 1)
         {
            OUTPUT_HIGH(Led1);
            delay_ms(50);
            OUTPUT_LOW(Led1);
            delay_ms(50);
            Ok_Data = 0;
         }
     
         delay_ms(50);
         OUTPUT_LOW(Led2);
         delay_ms(50);


I'm using 16F913 with inbuilt usart module and GPS module transmitting only GPRMC data.
_________________
manibabu
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Thu Nov 27, 2008 8:41 am     Reply with quote

A typical gps squarks ( sends a sentence when it wants) it is rare that they are polled ( asked to send first). This means the PIC has to be ready at any and all times to catch the incoming chars. This can be done without a hardware USART isr service routine but by not using an isr the task becomes very very timing critical and worse is when it doesn't work it is hard to guess at what exactly in the timing caused it to fail. I'd recommend strongly using an isr that feeds a circular buffer that will hold the sentence. The isr could score the input....$ received sets the score to zero a "G" moves it to 1 providing it was at zero a "P" moves only a one to two and so on till your sentence name is received then you can have the isr gate the rest of the sentence char by char into the circular buffer. When the sentence is fully received set a flag in the isr to let your main code know it can begin to parse the sentence. The isr approach has the great advantage that it can allow your main routine to use the time in between the GPS squarks to process the last sentence received.
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