View previous topic :: View next topic |
Author |
Message |
picfreak
Joined: 26 Oct 2009 Posts: 16
|
usart problem with gps |
Posted: Mon Oct 26, 2009 12:59 am |
|
|
hi friends,
I'm using pic=16f877a
gps=sr-87
My problem is when my pic is interfaced with gps, usart is not working.
But both pic and gps working fine when they work seperately with hyper terminal. When interface both pic and gps not working. I worked with rda int also.
Code: |
#include "D:\avudai\code\gps.h"
int gps_data[70]={};
int i=0,set_flag=0,j;
int temph,templ;//temporary variables
int16 hours;
void main()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
// TODO: USER CODE!!
while(1)
{
if(kbhit())
{
gps_data[i]=getch();
putc(gps_data[i]);
i++;
}
}
}
#include <16F877A.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOPUT //No Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#use delay(clock=20000000)
#use rs232(baud=4800,xmit=PIN_C6,rcv=PIN_C7)
|
Help me out.
Thanks in advance. |
|
|
Ttelmah Guest
|
|
Posted: Mon Oct 26, 2009 5:10 am |
|
|
Obvious comment abut the code, add:
if (i>69) i=0;
after you increment i....
Realistically, how are you interfacing the hardware?. If both the PIC, and the GPS work when attached to the PC, then both are using 'RS232' signalling (have a buffered inverter/level translator present). Are you keeping this when you connect the devices?.
If you have cables already made to connect to the PC, you need:
Pin2 GPS plug -> Pin3 PIC plug
Pin2 PIC plug -> Pin2 on PC
Pin 5 on all the connections joined.
For your test code to work (relaying the data 'on' to the PC).
Best Wishes |
|
|
Guest
|
|
Posted: Mon Oct 26, 2009 5:27 am |
|
|
1)ya i added that line in ma code
if (i>69) i=0;
2)Pin2 GPS plug -> Pin3 PIC plug
Pin2 PIC plug -> Pin2 on PC
Pin 5 on all the connections joined.
what u sujected like that only i gave connections .....
but i cannot view any data in hyper terminal yarr
when i interface the gps with rda_int its not working.......but if i connect usart to pc rda_int its working fine....
pls help me out
thanks
in advance |
|
|
picfreak
Joined: 26 Oct 2009 Posts: 16
|
|
Posted: Mon Oct 26, 2009 5:28 am |
|
|
Anonymous wrote: | 1)ya i added that line in ma code
if (i>69) i=0;
2)Pin2 GPS plug -> Pin3 PIC plug
Pin2 PIC plug -> Pin2 on PC
Pin 5 on all the connections joined.
what u sujected like that only i gave connections .....
but i cannot view any data in hyper terminal yarr
when i interface the gps with rda_int its not working.......but if i connect usart to pc rda_int its working fine....
pls help me out
thanks
in advance |
|
|
|
Ttelmah Guest
|
|
Posted: Mon Oct 26, 2009 8:14 am |
|
|
So, debug.
Start with the connections as they are, and try a simple 'hello world' application. Does the PC display this?. If not, then find out why. Pin 2 on the PC, is the receive data input pin. If the PIC works when directly connected, then it must be outputting it's data into this pin, so ought to work.
Get this part working, and then you have something to display the output on. Once this is working, then 'ERRORS' to your RS232 declaration to prevent a UART lockup if receive data is not handled, and start on testing this part.
Best Wshes |
|
|
Guest
|
|
Posted: Mon Oct 26, 2009 7:52 pm |
|
|
ok Ttelmah
ya pic with pc no probs it displaying it.......gps with pc also no probs it displaying but the problem is gps interfaced with pic.........my usart works fine.........
i'll debug every thing what u say ..........
hope i'll get it soon.......
thanks for ur suggesitions |
|
|
picfreak
Joined: 26 Oct 2009 Posts: 16
|
|
Posted: Mon Oct 26, 2009 7:53 pm |
|
|
ok Ttelmah
ya pic with pc no probs it displaying it.......gps with pc also no probs it displaying but the problem is gps interfaced with pic.........my usart works fine.........
i'll debug every thing what u say ..........
hope i'll get it soon.......
thanks for ur suggesitions |
|
|
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
|
|
Posted: Tue Oct 27, 2009 10:35 am |
|
|
Code: | gps_data[i]=getch();
putc(gps_data[i]); |
Most GPS's speak NMEA at a specific baud rate. The code above reads a character and then immediately outputs the character. The PIC while outputting the character must be able to receive a character at any time especially during the time it is outputting a character. As the pic reads say$ from the GPS it must be able to accept the next character in bound. The GPS doesn't know or care if the PIC has finished outputting a character when it transmits. There is a hardware buffer ( assuming you used a hardwre UART Rx PIN in your USE#rs232 ) of a char or two but that is all unless an isr tied to int# RDA that feeds a circular buffer is used. Now if the printf outbound is at a much higher baud rate than the GPS inbound the code above might work reasonably well. Nevertheless the only absolutely reliable way is via a circular buffer. If you only need certain sentences then in the isr test the first few characters and gate the ones you need into the buffer. Maintain pointers as to the next char to read and the last character written to this buffer. In main do the reading of the buffer and in the isr do the writing. Keep all isr's as short as you can possibly make them ( don't put printf or floating point calculations into an isr). |
|
|
picfreak
Joined: 26 Oct 2009 Posts: 16
|
|
Posted: Thu Oct 29, 2009 6:55 pm |
|
|
Sorry for the late reply.
ok Douglas Kennedy I'll do what you say.
Ya I connected hardware usart.
I'm trying my level best.
Thanks for your suggestions.
I'll work it out and get back to you soon. |
|
|
picfreak
Joined: 26 Oct 2009 Posts: 16
|
|
Posted: Thu Nov 05, 2009 8:51 pm |
|
|
Thanks guys for your suggestions.
I got the output from gps and my controller is displaying the specific line that I need to display.
1) I added this line:
if (i>69) i=0;
what Ttelmah said.
2) gps_data[i]=getch();
putc(gps_data[i]);
Then Douglas Kennedy said to not print while receiving data.
3) I connected a pullup in tx and rx.
It works fine.
Thanks for everyone who responded. Thanks very much. |
|
|
Jo
Joined: 12 Oct 2009 Posts: 6
|
|
Posted: Thu Nov 19, 2009 3:18 pm |
|
|
Hi picfreak
I read your topic about the link with RS232 towards the GPS.
I have a similar problem.
I want to connect PIC16F877a with a radio using "CAT" that works on RS232.
The PIC work well with Hyperterminal, also my radio work well with hyperterminal.
But the PIC won't work with the radio.
Please, can you explain me what you mean, when you say:
Quote: |
3) I connected a pullup in tx and rx.
It works fine.
|
The pull up is on the pin RC6 and RC7 or in
the RS232 of the GPS ?
Thanks
Jo |
|
|
picfreak
Joined: 26 Oct 2009 Posts: 16
|
|
Posted: Wed Nov 25, 2009 3:15 am |
|
|
hi jo
Sorry for the late reply.
I connected the
The pull up is on the pin RC6 and RC7
If you are going to connect gps to pic then connect the rx and tx of the gps without rs232.
Connect rx of pic to tx of the gps.
Connect tx of pic to rx of the gps.
It works fine for me.
att the best jo |
|
|
Jo
Joined: 12 Oct 2009 Posts: 6
|
usart problem with gps |
Posted: Wed Nov 25, 2009 9:35 am |
|
|
Thanks picfreak
I will try as you say
Jo |
|
|
|