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 (Lowrance) NEMA data to PIC16F690 c program

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



Joined: 08 Mar 2008
Posts: 17

View user's profile Send private message

GPS (Lowrance) NEMA data to PIC16F690 c program
PostPosted: Sun Jul 26, 2009 6:40 pm     Reply with quote

I have created the following code to read NEMA sentences. My problem is that I only get the first sentence and then the program is sitting waiting for more sentences....why is it not seeing the next sentence?

connecting the gps to to hyerterminal....all sentences are coming thru...

connected the PIC to hyperterminal and if I type in a sentence (anything) when I press enter it I see it returned to the terminal...exactly what I want. except of course I cant type as fast as the pic at 4800 baud.

Now I connect the GPS to the receive pin of the PIC and the transmit to hyperterminal using this code....

I get the first Nema sentence....so all wiring is correct but the C program is disregarding the next sentence(s).

What am I missing?

The PIC is connected to the GPS and the computer(hyperterminal) via the max232 RS232 driver/receiver chip.

Thanks all.

Brian

Code:

#include <16F690.h>
#fuses INTRC_IO, NOWDT, NOBROWNOUT, PUT, NOMCLR
#use delay(clock=4000000)
#use rs232(baud=4800, xmit=PIN_B7, rcv=PIN_B5)


#include <string.h>
//=============================
void main()
{
char input[80];
char word[6];
int x;
char c;
//strcpy(word, "124");

printf("Ready:\n\r ");

while(true)

  {

printf("loop:\n\r ");

gets(input);

//strcpy(input, "$GPRMC,000856,A,5053.4290,N,10519.0989,W,3.5,138.0,010200,12.3,E*58");

puts(input);

}
}


 
 
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jul 26, 2009 6:57 pm     Reply with quote

Quote:
puts(input);

You're sending a long string with the line above. While you're sending it,
the PIC can't do anything else. It takes about 2 ms per character (at
4800 baud) to send the string. So effectively, the PIC is locked up for
over 100 ms.

During that time, new characters may be coming into the UART's receiver.
But, it has only a 2-deep receive fifo. If more than 2 characters come in
without you reading them, the UART will generate an overrun error.
It will then stop receiving any future characters until that error condition
is cleared. You can tell the compiler to insert code to automatically
clear overrun errors by adding the ERRORS parameter to the #use rs232
statement. You'll still lose characters if you don't read them in time, but
at least the UART's receiver won't be locked up.
brianm



Joined: 08 Mar 2008
Posts: 17

View user's profile Send private message

ERRORS added to use rs232 line - losing data as stated....
PostPosted: Sun Jul 26, 2009 7:36 pm     Reply with quote

As stated in your suggestion I am losing data...makes perfect sense.

Now what can you suggest to make it so I don't lose data...I will be sending the data to a LCD once I get the proper data coming in...using the terminal program to test for now.

Thanks so much for the fast response and great explanation.

Brian
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jul 26, 2009 8:05 pm     Reply with quote

Use an interrupt-driven software receive fifo. Look at the Ex_Sisr.c
example file:
Quote:
c:\program files\picc\examples\ex_sisr.c
brianm



Joined: 08 Mar 2008
Posts: 17

View user's profile Send private message

was trying this example.
PostPosted: Sun Jul 26, 2009 8:41 pm     Reply with quote

http://www.ccsinfo.com/forum/viewtopic.php?t=39659&highlight=rs232

I see this is similar to the example code you suggested. This examples is nice because $gprmc is the exact data I want to work with.

BUT with the original code I do get some mixed up data.

I replaced the lines as suggested and adjusted it for my PIC but get a compile error as shown.
Code:

xbuff =0;
                  do {
                    theChar = bgetc();
                    NMEA_RMC[xbuff++] = theChar;
                  } while (theChar != '*');

The compile goes like this

Clean: Deleting intermediary and output files.
Clean Warning: File "D:\microchip\projects in c\rs232 inout using getc and buffer\rs232inoutgetc.o" doesn't exist.
Clean: Deleted file "rs232inoutgetc.ERR".
Clean: Done.
Executing: "C:\software\PICC\CCSC.EXE" +FM "rs232inoutgetc.c" +DF +LN +T +A +M +Z +Y=9 +EA
>>> Warning 207 "rs232inoutgetc.c" Line 69(1,1): Code has no effect
>>> Warning 207 "rs232inoutgetc.c" Line 99(1,1): Code has no effect
*** Error 75 "rs232inoutgetc.c" Line 108(1,2): Expect WHILE
*** Error 43 "rs232inoutgetc.c" Line 108(5,10): Expecting a declaration
*** Error 43 "rs232inoutgetc.c" Line 108(11,12): Expecting a declaration
*** Error 48 "rs232inoutgetc.c" Line 108(19,25): Expecting a (
*** Error 43 "rs232inoutgetc.c" Line 108(22,23): Expecting a declaration
*** Error 43 "rs232inoutgetc.c" Line 108(23,24): Expecting a declaration
*** Error 43 "rs232inoutgetc.c" Line 108(24,25): Expecting a declaration
*** Error 43 "rs232inoutgetc.c" Line 110(1,2): Expecting a declaration
8 Errors, 2 Warnings.
Halting build on first failure as requested.
BUILD FAILED: Sun Jul 26 20:30:17 2009


Code:

#include <16F690.h>
#fuses INTRC_IO, NOWDT, NOBROWNOUT, PUT, NOMCLR
#use delay(clock=4000000)
#use rs232(baud=4800, xmit=PIN_B7, rcv=PIN_B5, ERRORS)

#include <string.h>

char NMEA_RMC[58] ;
#include <STDLIB.H>
#include <MATH.H>

#define BUFFER_SIZE 58
int8 buffer[BUFFER_SIZE];
int8 next_in = 0;
int8 next_out = 0;
int xbuff=0x00;
char GPS_OK = 0;

#INT_RDA
void serial_isr() {                       // Serial Interrupt
   int t;

   buffer[next_in]=getc();
   t=next_in;
   next_in=(next_in+1) % BUFFER_SIZE;
   if(next_in==next_out)
     next_in=t;                       // Buffer full !!
}

#define bkbhit (next_in!=next_out)

int8 bgetc() {
   BYTE c;

   WHILE(!bkbhit) ;
   c=buffer[next_out];
   next_out=(next_out+1) % BUFFER_SIZE;
   return(c);
}

void Ini_NMEA_RMC(void){       // Inicia a \0 cbuff -------------------
  int i;
  int count=58;
  for(i=0;i<count;i++){     // Bucle que pone a 0 todos los
    buffer[i]=0x00;          // caracteres en el buffer
   }
  xbuff=0x00;               // Inicializo el índice de siguiente
}

void main() {
   
   int8 n = 0;
   int32 i =0;
   int8 theChar = 0;
   
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_spi(FALSE);
   setup_wdt(WDT_OFF);

   enable_interrupts(global);
   enable_interrupts(int_rda);

   delay_ms(50);

    printf ("Ready \n\r");
do{
      GPS_OK == 0;
         WHILE (theChar != '$') theChar = bgetc();                              // Look for a '$' - the start of a NMEA sentence
         theChar = bgetc();
         IF (theChar == 'G') {
            theChar = bgetc();
            IF (theChar == 'P') {
               theChar = bgetc();
               IF (theChar == 'R') {
                  theChar = bgetc();
                  IF (theChar == 'M') {
                     theChar = bgetc();
                     IF (theChar == 'C') {
                        theChar = bgetc();                                       // Discard ','

                        theChar = bgetc();                                       // Discard Time
                        WHILE (theChar != ',') theChar = bgetc();

                  xbuff =0;
                  //Ini_NMEA_RMC();
                  //while (theChar != '*'){
                  //NMEA_RMC[xbuff++] = bgetc();
               do {
                    theChar = bgetc();
                    NMEA_RMC[xbuff++] = theChar;
               }
                while (theChar != '*');


printf ("%s \n\r", NMEA_RMC);
                     }
                  GPS_OK == 1;
               
                   }
               }
            }
         }
      }

 
}   while (GPS_OK == 0);

}
dyeatman



Joined: 06 Sep 2003
Posts: 1923
Location: Norman, OK

View user's profile Send private message

PostPosted: Sun Jul 26, 2009 9:01 pm     Reply with quote

It appears you have too many closing braces just before the while statement at the end. Comment one out and it compiles.
_________________
Google and Forum Search are some of your best tools!!!!
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