View previous topic :: View next topic |
Author |
Message |
turbo2ltr
Joined: 27 Jan 2005 Posts: 12
|
RDA int problem |
Posted: Tue Feb 06, 2007 4:27 pm |
|
|
I'm sure it's something stupid but I can't seem to figure it out.
I enable the int_rda interrupt. My program works fine until a byte is received in the UART. Then the RDA interrupt runs continuously. I just send one byte, so after it services the interrupt once, it should clear the interrupt and it should not happen again. The disassembly shows that it clears the RXIF bit just before it exits. So why would it get triggered again if the flag is cleared?
I tried this with even an empty ISR routine and it still does it.
16F690
Code: |
void main()
{
enable_interrupts(global);
enable_interrupts(int_rda);
// main loop
while(1)
{
putc('-');
} // end while
}
#int_rda
void SerRxIsr()
{
// SerDataRdy = true;
// putc('+');
}
|
Code: | 285: #int_rda
286: void SerRxIsr()
287: {
288: // SerDataRdy = true;
289: // putc('+');
290: }
291:
292:
099 128C BCF 0xc, 0x5
09A 118A BCF 0xa, 0x3
09B 2834 GOTO 0x34 |
The output is a "-" stream until I tap a key, at which point I get nothing. If I uncomment the putc in the ISR, I get the "-" stream until I press a key, then I get a "+" stream. I never see the "-" again.
Any help is greatly appreciated.
Thanks,
Mike |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Feb 06, 2007 4:45 pm |
|
|
Read the 16F690 data sheet, in the Asynchronous USART section.
It says:
Quote: |
The RCIF interrupt flag bit will be set when there is an
unread character in the FIFO, regardless of the state of
interrupt enable bits.
|
This means you have to read the character in order to clear the interrupt.
Typically, getc() or fgetc() is used in the #int_rda isr to read the byte. |
|
|
turbo2ltr
Joined: 27 Jan 2005 Posts: 12
|
|
Posted: Tue Feb 06, 2007 5:42 pm |
|
|
I thought about that after I posted. I have some other timing critical interrupts and was hoping that I didn't have to read the byte right away, but could just set a flag to read later. Guess I'll at least pull it out of the register in the interrupt.
Thanks. |
|
|
|