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

serial interrupt with GPS

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



Joined: 23 Jul 2006
Posts: 20

View user's profile Send private message

serial interrupt with GPS
PostPosted: Mon Nov 27, 2006 12:54 pm     Reply with quote

Hi
I have connected GPS with PIC but all I receive are junk characters. Here is the code. Any ideas ?
Code:

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define SIZE 80
#define CR 0x0d
#define COMMA 0x2C

#use rs232(baud=4800, xmit=PIN_C6,rcv=PIN_C7, stream=GPS,ERRORS)

void parse();
void rmc();
void gga();
unsigned int j,k;
unsigned char *pChar,LastComaPos;
unsigned char inStr[SIZE] ;
unsigned char c;
int8 index=0;
 
#INT_RDA
void gps_isr(void)
{

 c =fgetc(GPS);
 fprintf(GPS);
 c = (char)c;

 if(c=='$')
      printf(lcd_putc,"\%c",c);
      index=0;
      inStr[index]=c;
      index++;
      if((c==10)||(c==13))
      {
       inStr[index]='\0';
       index=0;

      }

}

void main()
{

    lcd_init();
    enable_interrupts(INT_RDA);
    enable_interrupts(GLOBAL);

   
    WHILE(TRUE)
    {
      parse();
    }
}


Last edited by ryan.reeve on Tue Nov 28, 2006 12:44 am; edited 1 time in total
drolleman
Guest







PostPosted: Mon Nov 27, 2006 1:02 pm     Reply with quote

where is your #use statement and clock?
drolleman
Guest







PostPosted: Mon Nov 27, 2006 1:07 pm     Reply with quote

you need #fuses statement

#include <18f252.h>
#device ADC=10
#device *=16
#fuses H4,wdt128,NOPROTECT,NOBROWNOUT,noPUT,NOLVP,debug
#use delay(clock=40000000)
#use rs232(baud=9600, xmit=PIN_c6, rcv=PIN_c7,errors,enable=pin_b1) // Jumpers: 8 to 11, 7 to 12
ryan.reeve



Joined: 23 Jul 2006
Posts: 20

View user's profile Send private message

that is included
PostPosted: Mon Nov 27, 2006 1:16 pm     Reply with quote

drolleman wrote:
you need #fuses statement

#include <18f252.h>
#device ADC=10
#device *=16
#fuses H4,wdt128,NOPROTECT,NOBROWNOUT,noPUT,NOLVP,debug
#use delay(clock=40000000)
#use rs232(baud=9600, xmit=PIN_c6, rcv=PIN_c7,errors,enable=pin_b1) // Jumpers: 8 to 11, 7 to 12


These are contained in another file included in the code, but not shown here.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Nov 27, 2006 1:37 pm     Reply with quote

1. Tell us about your GPS. Post the manufacturer and part number.

2. Tell us about your hardware connections between the PIC and GPS.
Describe the circuit.

3. What PIC are you using ?

4. What is your compiler version ?

5. Explain how you know that you're getting garbage. There is nothing
in your program that displays the data.
ryan.reeve



Joined: 23 Jul 2006
Posts: 20

View user's profile Send private message

detail..
PostPosted: Tue Nov 28, 2006 12:40 am     Reply with quote

PCM programmer wrote:
1. Tell us about your GPS. Post the manufacturer and part number.

2. Tell us about your hardware connections between the PIC and GPS.
Describe the circuit.

3. What PIC are you using ?

4. What is your compiler version ?

5. Explain how you know that you're getting garbage. There is nothing
in your program that displays the data.


I am using Garmin 12 XL and tried it with 16F877 and 18F452
Compiler is 3.249
I have omitted the print statement as my original purpose is not to print the GPS output butto grab the bearing and send to the servo controller.
I am using Proteus to simulate the circuit.
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Tue Nov 28, 2006 9:52 am     Reply with quote

Well there is a printf to an LCD statement in the RDA isr it is just echoing a received char but it will take as much time at least as it takes to accept a char and therefore puts the reception of the next char at some risk. There is no circular buffer on the sentence to be received just a linear buffer.
Suggestions:
Remove the linear buffer and replace it with a circular buffer...see the ccs examples and search this board.
Remove the printf to lcd and locate it in main only this time to print whatever is in the new circular buffer.

Unless you screen out other sentences by deslecting them in your GPS receiver them you run the risk of the receive buffer being filled with a sentence you don't want. It will need to be either thrown away promptly in your main routine or the RDA isr will need enhancing to a "count me in" type logic. If you see a $ then the next char must be say "G" then "M" then "P" etc
until your specific sentence is identified only then is it allowed into your circular buffer.
Now a Nmea sentence also has a check digit. If you are using this for any
real navigation you really should check this. It follows the "*"
ryan.reeve



Joined: 23 Jul 2006
Posts: 20

View user's profile Send private message

PostPosted: Tue Nov 28, 2006 11:38 am     Reply with quote

Douglas Kennedy wrote:
Nmea sentence also has a check digit


Are u talkin about the checksum ?
what is its importance from navigational point of view.
thanks.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Nov 28, 2006 1:32 pm     Reply with quote

The Garmin GPS 12XL is a stand alone consumer unit. How did you create the connection to your PIC processor? Did you use the Garmin supplied cable or created one yourself? Have you added a MAX232 or similar circuit?
ryan.reeve



Joined: 23 Jul 2006
Posts: 20

View user's profile Send private message

PostPosted: Wed Nov 29, 2006 12:13 am     Reply with quote

ckielstra wrote:
The Garmin GPS 12XL is a stand alone consumer unit. How did you create the connection to your PIC processor? Did you use the Garmin supplied cable or created one yourself? Have you added a MAX232 or similar circuit?


I used the standard Garmin cable without MAX232 as it is builtin within 12XL.
MarcosAmbrose



Joined: 25 Sep 2006
Posts: 38
Location: Adelaide, Australia

View user's profile Send private message

PostPosted: Wed Nov 29, 2006 3:51 am     Reply with quote

write the characters to a buffer as they're received by the RDA interrupt. Once you've received a complete NMEA sentence, then print the buffer to your LCD.
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Wed Nov 29, 2006 8:45 am     Reply with quote

What the checksum does is enable you to know with a high degree of assurabliity that you have received the sentence from your GPS correctly.
An incorrect value possibly could cause an accident. Another thing to be aware of is that the sentence also has a status flag...if the status flag is not indicating a good fix then even if the checksum validates the reading is no good for navigation.
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