View previous topic :: View next topic |
Author |
Message |
mwalter
Joined: 18 Mar 2011 Posts: 2
|
24F16KA102 / UART Interrupts |
Posted: Sun Mar 20, 2011 11:04 am |
|
|
I am having a problem with UART interrupts on the 24F16KA102. My UART ISR is never called when I type in HyperTerminal. When I poll for chars in main() with getc(), I receive the chars.
This is obviously a basic need that is done all the time, so I must be doing something stupid. Could someone review my code below?
Thanks.
I found the example code, EX_SISR.C and stripped it down to show the problem.
Setup :
24F16KA102
XLP 16-Bit Development board.
Code: |
#include <24F16KA102.h>
#fuses HS, NOWDT, NOPROTECT
#use delay(clock=8000000)
#USE rs232(BAUD=57600, XMIT=PIN_B0, RCV=PIN_B1)
#define BUFFER_SIZE 32
BYTE buffer[BUFFER_SIZE];
BYTE next_in = 0;
BYTE next_out = 0;
#int_rda
void serial_isr() {
int t;
buffer[next_in]=getc();
t=next_in;
next_in=(next_in+1) % BUFFER_SIZE;
if(next_in==next_out)
next_in=t; // Buffer full !!
}
#define bkbhit (next_in!=next_out)
BYTE bgetc() {
BYTE c;
while(!bkbhit) ;
c=buffer[next_out];
next_out=(next_out+1) % BUFFER_SIZE;
return(c);
}
void main()
{
setup_oscillator( OSC_INTERNAL, 8000000);
enable_interrupts(int_rda);
enable_interrupts(intr_global);
printf("\r\n\Running...\r\n");
// The program will delay for 10 seconds and then display
// any data that came in during the 10 second delay
do {
delay_ms(4000);
printf("\r\nBuffered data => ");
while(bkbhit)
putc( bgetc() );
} while (TRUE);
}
|
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9246 Location: Greensville,Ontario
|
|
Posted: Sun Mar 20, 2011 1:23 pm |
|
|
I think the ISR only works with the hardware UART that being said are your pin assignments in the RS232 () directive correct for hardware UART ? |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sun Mar 20, 2011 11:46 pm |
|
|
RB0 and RB1 are hardware UART pins, but of UART2 that is automatically selected by your #use RS232 statement. So INT_RDA2 has to be used. |
|
|
mwalter
Joined: 18 Mar 2011 Posts: 2
|
|
Posted: Mon Mar 21, 2011 7:22 am |
|
|
That did it.
Thanks for the help. |
|
|
|