View previous topic :: View next topic |
Author |
Message |
redkit_redkit
Joined: 18 Aug 2010 Posts: 5
|
Problem with calling a char from GPS |
Posted: Wed Aug 18, 2010 6:03 am |
|
|
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
}
}
|
|
|
![](templates/subSilver/images/spacer.gif) |
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
|
|
Posted: Wed Aug 18, 2010 6:25 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
redkit_redkit
Joined: 18 Aug 2010 Posts: 5
|
|
Posted: Wed Aug 18, 2010 6:53 am |
|
|
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
}
} |
|
|
![](templates/subSilver/images/spacer.gif) |
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
|
|
Posted: Wed Aug 18, 2010 7:18 am |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
redkit_redkit
Joined: 18 Aug 2010 Posts: 5
|
|
Posted: Wed Aug 18, 2010 7:23 am |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
|