View previous topic :: View next topic |
Author |
Message |
mutthunaveen
Joined: 08 Apr 2009 Posts: 100 Location: Chennai, India
|
RS232 receive interrupt issue |
Posted: Sun Aug 24, 2014 8:58 am |
|
|
hello board
im getting a wired error on INT_RDA, without any action on rx tx from my serial port in my computer im receiving a interrupt all the time
in my computer im reading "received some data" all the time (even i did not send any data to PIC)
here is my code
Code: | #include <16F877a.h>
#device adc=10
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#include <flex_lcd.c>
#int_RDA
void RDA_isr(void)
{
printf("\n\r some data received \n\r");
}
void main()
{
printf("\n\r program initiated \n\r");
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
while(1){
delay_ms(1000);
}
} |
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Sun Aug 24, 2014 9:01 am |
|
|
ASSUMING this is REAL hardware and NOT a 'simulation'.....
Do you have a MAX232 or equal between the PIC and PC ?
Also, you should NOT be printing 'inside' the ISR. Instead, set a flag within the ISR and in main check to see if set.
hth
jay |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Sun Aug 24, 2014 9:42 am |
|
|
Hi,
This has been covered hundreds of times before. You MUST actually read the received character inside the ISR to clear the int rda interrupt. Add the following to your ISR:
Code: |
Char Temp;
Temp=getc();
|
John |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19549
|
|
Posted: Mon Aug 25, 2014 2:49 am |
|
|
As Ezflyr says, has been covered multiple times.
However I'll just expand a fraction further.
Key is to understand 'what' the interrupt says.
INT_RDA, is triggered when 'there is a character waiting to be read'.
Now you can clear INT_RDA fine, (the compiler does this for you, when you exit the handler), but since there is still a 'character waiting to be read', it will set again immediately (actually at the start of the instruction after the clear).
You need to distinguish between interrupts that happen at a 'moment', like 'INT_EXT', which occurs when the input signal 'moves through a particular level' (high to low, or low to high), and interrupts that are triggered by a condition or mis-match (INT_RDA, INT_RB, INT_TBE etc..). The latter, require the condition/mis-match to be 'handled' before they are cleared, or they will trigger again, until this is dealt with....
So for INT_RDA, you have to read the byte waiting. For INT_RB, you need to read/write the port, to reset the latches here, for INT_TBE, you need to load a byte into the transmit buffer, etc. etc..
It is in the data sheet, for the peripherals concerned. |
|
|
mutthunaveen
Joined: 08 Apr 2009 Posts: 100 Location: Chennai, India
|
thanks for your help board |
Posted: Mon Aug 25, 2014 10:14 pm |
|
|
thanks guys...
yes i have MAX IC and now it work
the mistake i made is -> the answer given by ezflyr (thanks man )
thank you Ttelmah for your elaborated information......
now everything works great
it will be good if they add this information in HELP file of CCS |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19549
|
|
Posted: Tue Aug 26, 2014 12:12 am |
|
|
Not really. CCS, expect you to understand the hardware. It's not their job to explain things in this. |
|
|
mutthunaveen
Joined: 08 Apr 2009 Posts: 100 Location: Chennai, India
|
yes indeed |
Posted: Tue Aug 26, 2014 10:04 am |
|
|
yeah... you are totally correct... its not CCS job.....
CCS would sure help for low hardware knowledge people (like me) |
|
|
megaball
Joined: 04 Oct 2018 Posts: 1
|
|
Posted: Wed Sep 25, 2019 5:39 am |
|
|
HI,
Can you post all your program? |
|
|
|