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 calling a char from GPS

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



Joined: 18 Aug 2010
Posts: 5

View user's profile Send private message

Problem with calling a char from GPS
PostPosted: Wed Aug 18, 2010 6:03 am     Reply with quote

Hi guys;
I'm trying toget gps data from my gps modul. My code is below. When i connect my gps to my computer i can see gps data.
I can send and receive data between pic<->computer but i couldn't get any data from my gps. I tried to use gets() and getc functions didn't work both way. Please help me.


Code:
#include <16f877.h>
#fuses XT,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOPUT,NOWRT,NODEBUG,NOCPD
#use delay (clock=4000000)
#use rs232 (baud=4800, xmit=pin_C6, rcv=pin_C7, parity=N, stop=1)

char character;

#int_rda
void  seri_interrupt ()
{
   disable_interrupts(int_rda);
   character=getc();
   printf("\ngps received=%c",character);    //sending gps data to terminal
}

void main ( )
{

   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_CCP1(CCP_OFF);
   setup_CCP2(CCP_OFF);

delay_ms(1000);
printf("start");             //sending start to terminal
enable_interrupts(GLOBAL);
 while(1)
  {
enable_interrupts(int_rda);   //enabling int_rda
   }

}
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Wed Aug 18, 2010 6:25 am     Reply with quote

Well you printf("\ngps received=%c",character); from within an isr.
That means for every one char that is received you send out 15 chars. So if the gps is sending say 10 chars you will miss all but one or two of them while the isr is blocked from reactivating for the time it takes to send 15 chars (your printf) . Remember rs232 is asynchronous. Take the printf out of the isr and place it in main. Create a circular buffer in your isr to place all inbound chars one at a time into your buffer. See the CCS examples on how to write a circular buffer. Do all processing in main except for the short and crisp placing of chars from the gps into the buffer via your isr. Never print more than one char in an a rda isr better yet never print anything from within an RDA isr get rid of disable interrupts in your isr
redkit_redkit



Joined: 18 Aug 2010
Posts: 5

View user's profile Send private message

PostPosted: Wed Aug 18, 2010 6:53 am     Reply with quote

I can't even get only one character. Even when i wrote like this code below, i cant see anything on terminal. Shouldn't i see even one character on terminal?

Code:

void main ( )
{
while(1)
  {
        character=getc();
      printf("%c",character);    //sending gps data to terminal
   }
}
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Wed Aug 18, 2010 7:18 am     Reply with quote

put errors in your use rs232.
You should see chars but terminal programs can be quirky especially hyperterminal. Test the terminal code first without the gps by testing to see if printf("hello") works. Then add the gps buffer and see if you can collect a dozen or more chars into your buffer. Just fill an array with a dozen chars in your isr and then printf them in main. Then make your buffer circular. Then test again. It will be slow learning but in the end you will get results.
redkit_redkit



Joined: 18 Aug 2010
Posts: 5

View user's profile Send private message

PostPosted: Wed Aug 18, 2010 7:23 am     Reply with quote

I found out what is wrong. I changed my fuses settings like below
Code:
#fuses XT,NOWDT,NOPROTECT,NOLVP


I get first sentence. But i'm missing some characters now, as you said. Now i will try what you said.
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