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

communicating with GPS receiver

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








communicating with GPS receiver
PostPosted: Wed May 17, 2006 10:01 am     Reply with quote

Hello,

I am trying to communicate with a GPS receiver using PIC16F873. But I am not able to receive the data out of it. On the contrary, it prints out data which I am not able to recogonize.
I am not that good in programming and I apologize for any basic mistakes.

My code is as follows:


#include <16F873.h>
#use delay(clock=4000000)
#fuses XT, NOPROTECT, NOLVP, NOCPD, NOWRT, NOBROWNOUT, NOPUT,NODEBUG,NOWDT
#use rs232(baud=4800,parity=N,xmit=pin_c0,rcv=pin_c1,bits=8,stream=GPS,errors)
#use rs232(baud=4800,parity=N,xmit=pin_c6,rcv=pin_c7,bits=8,stream=output,errors)
char c;
char gpsdata[30];
int i;
#int_rda
void rda_isr()
{
i = 0;
for (i = 0; i <= 30; i++)
{
c = fgetc(GPS);
gpsdata[i] = c;
}
}
void main()
{
while(true)
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_spi(FALSE);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
enable_interrupts(global);
enable_interrupts(int_rda);
for (i = 0; i <= 30; i++)
{
fprintf(output, gpsdata[i]);
}
}
}

and the output in the hyperterminal is as follows:

(ìP»‘Ú÷ 5ÁÙ5Á5Á‘×(ûP(ìP»‘Ú÷ 5ÁÙ5Á5Á‘×(ûP
(ìP»‘Ú÷ 5ÁÙ5Á5Á‘×(ûP(ìP»‘Ú÷ 5ÁÙ5Á5Á‘×(ûP
(ìP»‘Ú÷ 5ÁÙ5Á5Á‘×(ûP(ìP»‘Ú÷ 5ÁÙ5Á5Á‘×(ûP
(ìP»‘Ú÷ 5ÁÙ5Á5Á‘×(ûP(ìP»‘Ú÷ 5ÁÙ5Á5Á‘×(ûP
(ìP»‘Ú÷ 5ÁÙ5Á5Á‘×(ûP(ìP»‘Ú÷ 5ÁÙ5Á5Á‘×(ûP
(ìP»‘Ú÷ 5ÁÙ5Á5Á‘×(ûP(ìP»‘Ú÷ 5ÁÙ5Á5Á‘×(ûP
(ìP»‘Ú÷ 5ÁÙ5Á5Á‘×(ûP(ìP»‘Ú÷ 5ÁÙ5Á5Á‘×(ûP
(ìP»‘Ú÷ 5ÁÙ5Á5Á‘×(ûP(ìP»‘Ú÷ 5ÁÙ5Á5Á‘×(ûP
(ìP»‘Ú÷ 5ÁÙ5Á5Á‘×(ûP(ìP»‘Ú÷ 5ÁÙ5Á5Á‘×(ûP

When I use a fputc command instead of fprintf, the printed data is diffirent , but again they are also garbage values.

Please help me out.

Thanks,
noviceprogrammer.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed May 17, 2006 10:27 am     Reply with quote

The immediate problem is that #int_rda only works with the hardware
UART. You have assigned a soft UART (pins C0 and C1) to the GPS
stream. So it can't work.

You need to switch the streams. The hardware UART is always on
pins C6 and C7 in the 16F873. Change it to be the GPS stream.
Put the "output" stream on pins C0 and C1.


Also, your #int_rda function is not done in the best way. Normally,
you only get one character per pass through the #int_rda function.
That's because it will give you one interrupt per character. Do a
search on the forum for "GPS". There are probably several posts
that hopefully show how to do it better.
Guest








PostPosted: Thu May 18, 2006 4:51 pm     Reply with quote

Thanks very much. It was useful. If I wish to retain the C0 and C1 pins for my GPS stream can I use 'int_ext' interrupt instead of int_rda??
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu May 18, 2006 5:35 pm     Reply with quote

Yes, you can use the External interrupt pin to detect the start bit of an
incoming character on a soft UART. Then you can call fgetc() inside
the INT_EXT isr to get the character.

However, if for some reason you can't service the INT_EXT interrupt
quickly enough, you will lose the incoming character. This could happen
if you have interrupts disabled, or if another interrupt (such as INT_RDA)
is being serviced.
Guest








PostPosted: Thu May 18, 2006 5:59 pm     Reply with quote

Thankyou very much. I did use the #int_ext interrrupt to start with. I post the code after revising it. I apologize for not posting it earlier.


#include <16F873.h>
#use delay(clock=4000000)
#fuses HS, NOPROTECT, NOLVP,NOWDT,NOBROWNOUT
#use rs232(baud=4800,xmit=pin_c0,rcv=pin_c1,stream=GPS,bits=8,parity=N,errors)
#use rs232(baud=4800,xmit=pin_c6,rcv=pin_c7,stream=out,bits=8,parity=N)
byte c[75];
byte b=0;
byte x=75;
int i=0;
int j=0;

#int_ext noclear
void ext_isr()
{
byte intial;
intial=fgetc(GPS);
if(intial=='$')
{
c[i]=fgetc(GPS);
i=i+1;
if(i==x)
{
i=0;
}
}
}
byte getdata()
{
byte data;
data=c[j];
j=j+1;
if(j==x)
{
j=0;
}
return data;
}

void main()
{
enable_interrupts(global);
enable_interrupts(int_ext);
while(true)
{
fputc(getdata(),out);
}
}


The output still remains a garbage. I understand, as you said that there is a timing issue involved in the interrupt routine. But I am not able to get rid of it.
Thanks once again.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu May 18, 2006 6:04 pm     Reply with quote

I should have said that the INT_EXT interrupt is only available on
pin B0 in the 16F873. It's not available on pin C0.
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Fri May 19, 2006 8:44 am     Reply with quote

First, make sure your setup() commands are Not inside your while(1) loop. You are forcing the processor to set everything up each loop. Have your while(1) loop Below all of these.

I've made commercial devices, using GPS receivers, and I STRONGLY suggest you use the hardware RX pin for this. You do Not want to lose any data from your receiver. If there is ANY possible way to change to the hardware, do it! If you need a second serial port to send data out then use that one as a software port.

Ronald
Guest








PostPosted: Mon May 22, 2006 9:37 am     Reply with quote

Thankyou PCM programmer and Ronald.
Is there any way I could communicate keeping C0 and C1 as my Tx and Rx pins?
I tried to communicate with the receiver without using any interrrupt functions, but to no avail.
I understand what Ronlad said, but I don't think I can change the pins right now.
Please let me know how to tackle the issue.

Thanks.
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