View previous topic :: View next topic |
Author |
Message |
sgarc
Joined: 03 Nov 2008 Posts: 6
|
UART Crashes |
Posted: Mon Nov 03, 2008 12:49 pm |
|
|
I'm using an 18F2680. I am using the hardware uart with the following RS232 use statement:
Code: | #define RS232BAUD 19200
#use rs232(baud=RS232BAUD,parity=N,bits=8, errors, uart1) |
Essentially I am monitoring some peripherals on the ATD ports. I am using a 1 ms interrupt to average the ATD ports. Every three seconds I output 28 bytes of data to the RS232 port.
At first everything works fine but after the program has been running for a while (about an hour on average), the UART crashes. Nothing is being output and the PIC locks up. I know the PIC locks up because I have a blinking status light that will light up every second, and when the UART crashes the status light stays on or off depending on what it was when the UART crashed.
If I run the program using the debugger it will run for a while and then lock up. I see that the program will lock up on the first putc it encounters. So it goes from working fine to not working at all in three seconds.
1. Does anyone have any ideas as to why this happens?
2. Can you suggest any work arounds?
Thanks in advance |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Nov 03, 2008 1:04 pm |
|
|
Quote: | but after the program has been running for a while the UART crashes |
Do you have NOXINST and NOLVP fuses enabled ? You need them.
You will get random-appearing crashes if you don't have them. |
|
|
sgarc
Joined: 03 Nov 2008 Posts: 6
|
|
Posted: Mon Nov 03, 2008 1:09 pm |
|
|
Yes i do have the NOXINST and NOLVP fuses set |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
sgarc
Joined: 03 Nov 2008 Posts: 6
|
|
Posted: Mon Nov 03, 2008 1:28 pm |
|
|
Ok i read the first two posts. I dont have the Watch Dog Timer enabled, also i use NOPUT. One thing to note about my problem is that if i remove the code that outputs to the RS232 every three seconds then the program runs fine and does not crash, this has been tested for months so i know the problem has to do with the UART.
I also use NOBROWNOUT at the moment so i will try using BROWNOUT and see if that helps. After i read the third post i will update on my status.
Thank you for your help |
|
|
sgarc
Joined: 03 Nov 2008 Posts: 6
|
|
Posted: Mon Nov 03, 2008 1:35 pm |
|
|
oh i also forgot to mention that when the UART crashes the device does not reset it just stays in locked state and also the voltage on the RX line drops to -10V. During normal operation both the TX and RX lines idle high at 5V, but after the crash TX stays high at 5V but RX begins to idle at -10V.
hopefully this will help pinpoint the problem |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Nov 03, 2008 1:55 pm |
|
|
Quote: | also the voltage on the RX line drops to -10V |
Is the "Rx line" on the RS-232 side of the MAX232 chip ?
Are you using a MAX232 chip ? Do you have the +/- 10v RS232
line connected directly to your PIC pin ? (I hope not). |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1635 Location: Perth, Australia
|
|
Posted: Mon Nov 03, 2008 2:02 pm |
|
|
sgarc wrote: | oh i also forgot to mention that when the UART crashes the device does not reset it just stays in locked state and also the voltage on the RX line drops to -10V. During normal operation both the TX and RX lines idle high at 5V, but after the crash TX stays high at 5V but RX begins to idle at -10V. |
I am not sure if you are mixing references to the PIC RX and TX pins with the line drivers TX/RX pins.
The idles RS232 voltage on the line side (to the remote device) is nominally -12 volts (min - 3 volts). In the last sentence above you mention TX stays high at +5V which is what you would expect for an idle condition at the PIC pin which should translate to -12volts on the line driver output to the remote device. However in the same sentence you mention that the RX idles at -10 volts implying you are looking at the line side of the RS232 driver not the PIC pin.
Could you please clarify where you are making these measurements.
Quote: | hopefully this will help pinpoint the problem |
Can you post the smallest segment of code that demonstrates the problem. As a minimum (and assuming you are using receive interrupts) can you please post your serial receive interrupt handler. _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
sgarc
Joined: 03 Nov 2008 Posts: 6
|
|
Posted: Mon Nov 03, 2008 2:12 pm |
|
|
Yes i am using a MAX232 chip and i measure the 5V(tx) and -10V(rx) after the MAX232 chip. These measurements were not made on the PIC pins. |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1635 Location: Perth, Australia
|
Re: UART Crashes |
Posted: Tue Nov 04, 2008 9:22 am |
|
|
sgarc wrote: |
oh i also forgot to mention that when the UART crashes the device does not reset it just stays in locked state and also the voltage on the RX line drops to -10V. During normal operation both the TX and RX lines idle high at 5V, but after the crash TX stays high at 5V but RX begins to idle at -10V. |
The idle condition for the line side of an RS232 interface is nominally -12 volts. You mention that in idle condition the lines are high at +5 volts. This cannot be idle - it means. Are you measuring this with a multimeter (meanless values if data is being transmitted) or with an Oscilloscope?
Quote: | I know the PIC locks up because I have a blinking status light that will light up every second, and when the UART crashes the status light stays on or off depending on what it was when the UART crashed.
|
Is the status light driven by the interrupt handler or the main code body? If in the main body then move it to the timer interrupt handler and see what happens.
Do you have 0,1uF decoupling capacitors on the power pins of all ICs?
Do you have a power supply filtering capacitor across the power rails? _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
sgarc
Joined: 03 Nov 2008 Posts: 6
|
|
Posted: Mon Nov 17, 2008 6:56 pm |
|
|
Ok so after some trial and error I managed to find a work around for the problem. I just reset the UART before every output and it works consistently.
Code: | // disable the uart
setup_uart(0);
DELAY_MS(10);
// enable the uart
setup_uart(1);
DELAY_MS(500); |
I still don't know what the underlying cause of the problem was but its working now.
Thank you to everyone who offered their advice, I really appreciate it |
|
|
fugazi
Joined: 23 Apr 2010 Posts: 2
|
|
Posted: Fri Apr 23, 2010 2:41 pm |
|
|
I have exactly the same issue.
When i use the force-SW mode it works without crashing.
In HW mode the PIC hangs ( HARD!!).
I will try your trick ( periodical reset when rs-232 is iddling).
btw. my hardware is completely decoupled etc.
Looks like a compiler bug. |
|
|
fugazi
Joined: 23 Apr 2010 Posts: 2
|
|
Posted: Sat Apr 24, 2010 7:07 am |
|
|
PROBLEM SOLVED!
Follow sgarc direction and that works. It's dirty but it works. |
|
|
|