View previous topic :: View next topic |
Author |
Message |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Oct 19, 2008 6:00 pm |
|
|
Quote: | setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
setup_timer_2(T2_DIV_BY_16,255,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
setup_oscillator(OSC_8MHZ|OSC_INTRC|OSC_31250|OSC_PLL_OFF); |
Get rid of all this stuff. You're not using interrupts. You have the
interrupt service routine for int_rda commented out. Any incoming
character that comes in on the hardware UART will (with your program) jump off into space and blow up the program.
Also, you are still using INTHS instead of INTRC_IO. I don't know if
INTHS works. But I do know that INTRC_IO definitely does work.
The compiler sees that fuse. Then it looks at the #use delay() statement
and sees the frequency. Then it sets up the start-up code to use the
internal oscillator at the specified frequency. It's all automatic, if only
you let the compiler do it. |
|
|
analog_world
Joined: 16 Sep 2008 Posts: 26
|
|
Posted: Sun Oct 19, 2008 7:08 pm |
|
|
Hi PCM,
Thanks for your valuable and timely suggestions. I did take out all that unnecessary stuff inserted by the PIC wizard. I have used the INTHS to write to the output port and I guess it does work. But the problem is I don't understand when you said Quote: | You have the interrupt service routine for int_rda commented out. Any incoming character that comes in on the hardware UART will (with your program) jump off into space and blow up the program. | .
Did you mean to say that I should completely take out the hardware receive interrupt or i should instead include the ISR into my program and include some code into the ISR. I tried taking it out completely, but still I am not able to read in the characters from the GPS. Seems like I'm stuck with a weird debugging issue. Thank you. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Oct 19, 2008 7:40 pm |
|
|
Don't enable interrupts if you have no isr. When the PIC gets an
interrupt, it will jump to the location where the isr is supposed to be,
except there is no code there. The program will crash. |
|
|
analog_world
Joined: 16 Sep 2008 Posts: 26
|
|
Posted: Sun Oct 19, 2008 7:58 pm |
|
|
Hi,
That's what I did though. It still does not show me the output for some reason. I am trying to use fgets this time around.
Code: |
#use rs232(stream=GPS, baud=4800,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8, ERRORS)
#use rs232(stream =PC,baud=9600, xmit=PIN_B1, INVERT, DISABLE_INTS, ERRORS)
#include "myflex_lcd.c"
void main()
{
char rcv_string [82];
lcd_init(); // Always call this first.
while(1)
{
fgets(rcv_string,GPS);
fputs(rcv_string,PC);
};
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Oct 19, 2008 8:05 pm |
|
|
What's your compiler version ? You can find it at the top of the .LST file.
It's a 4-digit number in this format: x.xxx
The .LST file will be in your project directory. |
|
|
analog_world
Joined: 16 Sep 2008 Posts: 26
|
|
Posted: Sun Oct 19, 2008 8:09 pm |
|
|
V 4.057 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Oct 19, 2008 8:33 pm |
|
|
Is that really your code ? Or do you have Wizard code still in there,
such as setup_spi() ? Did you remove all the Wizard code ?
I suggest that you simplify the test program as follows:
1. Remove the #include line for the lcd driver. Remove the call to lcd_init().
2. Change the main() code to this, so it echoes characters instead of
strings. See if you get anything at all in the terminal window.
Code: |
void main()
{
char c;
while(1)
{
c = fgetc(GPS);
fputc(c, PC);
}
} |
|
|
|
analog_world
Joined: 16 Sep 2008 Posts: 26
|
|
Posted: Sun Oct 19, 2008 8:43 pm |
|
|
I took out the wizard code as you had suggested earlier. I am still not able to observe anything on the SIOW window using the simple main program.Infact, what i tried doing was testing if fputc actually worked by assigning a character c = 'A' ; and then commenting out the fgetc. In that case, I can see the character A being written on the output window continuously. So, in this case the problem should lie in the c= fgetc(GPS) which does not load any value into C for some reason. I am puzzled now as to what could be the problem. |
|
|
analog_world
Joined: 16 Sep 2008 Posts: 26
|
|
Posted: Sun Oct 19, 2008 8:53 pm |
|
|
I noticed that on my board, there is max232 chip connected between the serial port and PIC. Do you think this could be a source of problem since GPS outputs at a level compatible with the PIC. or am I wrong?? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Oct 19, 2008 9:18 pm |
|
|
Post the manufacturer and model number of your GPS.
Post a link to the website for it. |
|
|
analog_world
Joined: 16 Sep 2008 Posts: 26
|
|
Posted: Sun Oct 19, 2008 9:41 pm |
|
|
I just changed my USART to be software configured. In that case, when I run the program all I see is some random characters on the SIOW continuously in a pattern like this.
Code: |
\0A
P\0A
@€\0A
€€@@ P$T\0@ (€@€€\0A
€€\0A
@@\0J€€!PR @$ @€ @ $\0A
€€J”( P€ P@P@ "
H€ P@\0”H$!H !@¨@€€ „€@(€€\0$@H D@@P\0 !ˆ ”\0€ €@T@(€ (€\0€€*@($( \0A
P@ @
€@ ¢\0A
@ \0\0A
\0€ \0A
€€T\0A
@„@@@H@H€ ¤\0\0A
$ˆD \0A
€(@H@@„@@€P @@\0A
€„H@„€@*$@$€P „D
@ \0A
@\0 P @@*€H(PP H€P ”P %P\0Jˆ ¨\0(€€ \08
|
The GPS i am using is the GARMIN ETREX VISTA.here is the link for it:
https://buy.garmin.com/shop/shop.do?pID=163
Now that I see some garbage characters being output by the putc function, it is even more confusing :D. Thank you. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Oct 19, 2008 10:59 pm |
|
|
You said this:
Quote: | since GPS outputs at a level compatible with the PIC |
The manual says there is an attachment called the "PC interface cable".
It interfaces to a COM port on a PC.
On page 64 (page 74 in the Acrobat reader) of the owner's manual, it
shows a 4-pin connector with 3 wires. That's the PC interface cable.
http://www.garmin.com/manuals/eTrexVista_OwnersManual.pdf
This FAQ shows a schematic of the PC interface cable, down near the
bottom of the page. It's labeled "Units with a 4 pin rectangular plug":
http://www8.garmin.com/support/faqs/faq.jsp?faq=68
It looks to me like the PC interface cable will work fine a MAX232 chip.
I think the problem is this same old one that we solved 2 1/2 years ago
in this thread. Please read this thread carefully and use the information
to fix your problem:
http://www.ccsinfo.com/forum/viewtopic.php?t=26844 |
|
|
analog_world
Joined: 16 Sep 2008 Posts: 26
|
|
Posted: Mon Oct 20, 2008 12:28 am |
|
|
Hi PCM,
That was the problem. It finally works, but now there are some more glitches. The fgetc and fputc functions work perfectly, but no other functions like the fgets and fputs work. It is strange, but the SIOW terminal does not display anything once I slightly modify the code for reading in the GPS string and storing it so that I can parse it.
Code: |
#use rs232(stream=GPS, baud=4800,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8, ERRORS)
#use rs232(stream =PC,baud=9600, xmit=PIN_B1, INVERT, DISABLE_INTS, ERRORS)
void main()
{
char a;
while (1)
{
a = fgetc(GPS);
if (a == '\n')
{
fputc('5', PC);
}
else
fputc(a, PC);
/*
int i =0;
while (i < 85)
{
c[i] = fgetc(GPS);
fputc(c[i], PC);
if (c[i] == '\n')
{
c[i] = '\0';
break;
}
++i;
}
if ( i == sizeof(c))
continue;
*/
// c [0] fgetc(GPS);
// fputs(c,PC);
};
} |
As you can see, I have commented out many statements where I have tried to write my own gets function or try to determine whether the GPS sends out a '\n' characters after each string. But unfortunately, the program does not work for any of those cases except the simple fgetc and fputc code. This is kind of confusing since the other examples that I have explored seem to be able to do it easily. Thanks a ton. |
|
|
analog_world
Joined: 16 Sep 2008 Posts: 26
|
|
Posted: Mon Oct 20, 2008 8:45 pm |
|
|
the gets() and puts() function still don't work for some reason. I think I am messing up with the receiver buffer. Any suggestions would be greatly appreciated. Thank you so much. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Oct 20, 2008 9:25 pm |
|
|
Troubleshoot the problem. Investigate the contents of the string that's
coming from the GPS.
Connect the GPS to your PC. Fix the wiring on the DB9 cable if required.
Display the output of the GPS in a terminal window. If you have Siow.exe
then use that as your terminal program. It will show you if a carriage
return character (0x13) is received from the GPS. The fgets() function
looks for that character to mark the end of a string.
This test will also tell you how long the incoming messages are.
Your buffer may be too short. |
|
|
|