|
|
View previous topic :: View next topic |
Author |
Message |
rhaguiuda
Joined: 05 Sep 2007 Posts: 46 Location: Londrina - Brazil
|
RS232 interrupt problem |
Posted: Thu Nov 20, 2008 5:00 am |
|
|
Hi.
I'm using a PIC18LF1220, internal oscillator in 8MHz and PCH version 4.057.
My very simple program only blinks a LED at a pin, and it is configured to interrupt on RS232 reception. The problem is the PIC when running only keeps interrupting, even with nothing connected to PIN_B4 (RX).
Below is the code I'm using.
Code: |
#include <18F1220.h>
#fuses HS, NOWDT, PUT, NOMCLR
#use delay(internal=8M)
#use rs232(baud=9600, xmit=PIN_B1, rcv=PIN_B4, errors)
#define Led PIN_B0
#INT_RDA
void rda_isr()
{
printf ("Interrupt");
}
void main()
{
enable_interrupts (int_rda);
enable_interrupts (global);
do
{
output_high (Led);
delay_ms (1000);
output_low (Led);
delay_ms (1000);
}
while (1);
}
}
|
When this program is running, it only prints "Interrupt", and never blinks the led. So it always interrupted by RS232 rx.
Why my PIC only gets interrupted even with nothing connected to usart pins?
Thanks for any help. |
|
|
Ttelmah Guest
|
|
Posted: Thu Nov 20, 2008 5:19 am |
|
|
The 'idle' state for TTL RS232, is with the signal _high_ (5v). A disconnected pin, is probably floating _low_. This is seen as continuous RS232 data.
Then, the second reason, is your interrupt code. Once even one character is seen, it'll trigger for ever. When the RS232 interrupt occurs, it is saying 'I have a character that _needs_ reception'. Your routine does not retrieve the character, so it'll trigger again (and again, and again......).
So, do two things:
1) Add something to pull the RX pin hgh (a 100K resistor to +5v, or connect th line to the output of a MAX232 which will idle high - however you will still probably see one garbage character, as the chip wakes up).
2) Add a 'getc' to your interrupt.
Best Wishes |
|
|
|
|
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
|