I have an interrupt for the uart rx that swtiches a led and increments a value sent our over serial. The interrupt only happens 4 times though and then after awhile the whole thing resets back to 0 and the interrupt starts working again. I have no idea why and any help would be great. below is my initialization code and the output over uart.
(data.c)
void initsci1(void){
U1MODE = 0x8000;
U1STA = 0x0400;
U1BRG = 48;
delay(100);
IPC2bits.U1TXIP = 4;
IPC2bits.U1RXIP = 3;
IFS0bits.U1TXIF =0; //clear timer1 interrupt flag
IFS0bits.U1RXIF =0; //clear timer1 interrupt
IEC0bits.U1TXIE=0; //disable timer1 Interrupt
IEC0bits.U1RXIE=1; //enable timer1 Interrupt
}
/////////////////////////////////////////////////////////////////////////////
(interrupts.c)
unsigned char val = 0;
void _ISR _U1RXInterrupt(){
val++;
sendchar1(val);
LATB = ~PORTB;
IFS0bits.U1RXIF=0;
}
It may be important to note that these are in different c files considering that val gets sent back to 0 but is outside of the interrupt. They are both being called from main.c as follows
#include "data.c"
#include "interrupts.c"
TX: DF
RX: 01
TX: DF
RX: 02
TX: DF
RX: 03
TX: DF
RX: 04
TX: DF
TX: DF
Thanks for any help.
(data.c)
void initsci1(void){
U1MODE = 0x8000;
U1STA = 0x0400;
U1BRG = 48;
delay(100);
IPC2bits.U1TXIP = 4;
IPC2bits.U1RXIP = 3;
IFS0bits.U1TXIF =0; //clear timer1 interrupt flag
IFS0bits.U1RXIF =0; //clear timer1 interrupt
IEC0bits.U1TXIE=0; //disable timer1 Interrupt
IEC0bits.U1RXIE=1; //enable timer1 Interrupt
}
/////////////////////////////////////////////////////////////////////////////
(interrupts.c)
unsigned char val = 0;
void _ISR _U1RXInterrupt(){
val++;
sendchar1(val);
LATB = ~PORTB;
IFS0bits.U1RXIF=0;
}
It may be important to note that these are in different c files considering that val gets sent back to 0 but is outside of the interrupt. They are both being called from main.c as follows
#include "data.c"
#include "interrupts.c"
TX: DF
RX: 01
TX: DF
RX: 02
TX: DF
RX: 03
TX: DF
RX: 04
TX: DF
TX: DF
Thanks for any help.
Last edited: