I have a problem with my interrupt and I don't know why. I want to use an interruption each time I receive a data from my RX port. So, I used the interrupt on the port RX of my microcontroller. My problem is, I can detect an interruption but I am locked into the interruption. I'm locked into like a while(1)
. Any idea?
This is my test code:
//Functions//
void interrupt SerialRxPinInterrupt(void);
int main(int argc, char** argv)
{
//Variables//
unsigned char UARTConfig = 0, baud = 0;
//Toggle led//
TRISAbits.RA1=0; //output
//Configuration internal clock to 8Mhz//
OSCCONbits.IRCF0 = 1;
OSCCONbits.IRCF1 = 1;
OSCCONbits.IRCF2 = 1;
/*UART PINS*/
TRISCbits.RC6 = 0; //TX pin set as output
TRISCbits.RC7 = 1; //RX pin set as input
//UART Configuration//
UARTConfig = USART_TX_INT_OFF & USART_RX_INT_ON & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_BRGH_HIGH ;
baud=51; //Formula 16(X+1) = Fosc/Baud Rate
OpenUSART(UARTConfig,baud);
//Interrupt configuration//
RCIF = 0; //reset RX pin flag
RCIP = 0; //Not high priority
RCIE = 1; //Enable RX interrupt
PEIE = 1; //Enable pheripheral interrupt (serial port is a pheripheral)
ei(); //(INTCONbits.GIE = 1)
while(1)
{
LED=1;
}
return (EXIT_SUCCESS);
}
void interrupt SerialRxPinInterrupt(void)
{
LED=0;
//check if the interrupt is caused by RX pin
if(PIR1bits.RCIF == 1)
{
RCIF = 0; // clear rx flag
}
}