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 support@ccsinfo.com

RS232 interrupt problem

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



Joined: 05 Sep 2007
Posts: 46
Location: Londrina - Brazil

View user's profile Send private message

RS232 interrupt problem
PostPosted: Thu Nov 20, 2008 5:00 am     Reply with quote

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







PostPosted: Thu Nov 20, 2008 5:19 am     Reply with quote

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