Hello,
I am trying to use multiple interrupts in PIC32 microcontroller. When I use 2 interrupts lets say UART and 1 timer the microcontroller is working fine but when I use UART and 2 timer interrupts the microcontroller freezes. I have the following code in the interrupts.
#include "Tao4ch_defs.h"
// UART 2 interrupt handler
// it is set at priority level 2
void __ISR(_UART_2A_VECTOR, ipl3) _U2ARXInterrupt(void)
{ char ch;
IFS1bits.U2ARXIF = 0; // Reset the RX interrupt flag.
ch = U2ARXREG;
Char_in = ch;
Char_cap = 1; // Flag to indicate a character has been received.
// 0x0A is a line feed. Some terms attach linefeeds so must discard them.
if (ch != 0x0D && ch != 0x0A) { // If the rx'd char is not 'enter' or lf
Rx_buff [Rx_index] = ch; // load the rx buffer with the char and
Rx_index++; // increment the index.
if (Rx_index >= RX_BUF_LEN)
Rx_index = 0;
}
if (ch == 13) { // When the 'enter' char is received
Rx_buff[Rx_index] = 0; // put a null char in the string.
Rx_index = 0; // and reset the index.
Com_flag = 1; // Com flag should be reset after the
} // buffer has been read.
// string is processed.
}
// interrput code for the timer 1
void __ISR( _TIMER_1_VECTOR, ipl2) _T1Interrupt( void)
{
int i;
asm("ei"); //To enable interrupts
// clear interrupt flag and exit
IFS0bits.T1IF = 0;
sampleBuffer[sampleIndex].re = read_ext_adc1(5) - 25485; // read the ADC into the real part of the samplebuffer
// increment the sampleIndex
if (sampleIndex == (N-1))
{
sampleIndex = 0;
}
else
{
sampleIndex++;
}
} // T3 Interrupt
void __ISR( _TIMER_3_VECTOR, ipl1) _T3Interrupt( void)
{ asm("ei");
IFS0bits.T3IF = 0;
//do something
}
Thanks
I am trying to use multiple interrupts in PIC32 microcontroller. When I use 2 interrupts lets say UART and 1 timer the microcontroller is working fine but when I use UART and 2 timer interrupts the microcontroller freezes. I have the following code in the interrupts.
#include "Tao4ch_defs.h"
// UART 2 interrupt handler
// it is set at priority level 2
void __ISR(_UART_2A_VECTOR, ipl3) _U2ARXInterrupt(void)
{ char ch;
IFS1bits.U2ARXIF = 0; // Reset the RX interrupt flag.
ch = U2ARXREG;
Char_in = ch;
Char_cap = 1; // Flag to indicate a character has been received.
// 0x0A is a line feed. Some terms attach linefeeds so must discard them.
if (ch != 0x0D && ch != 0x0A) { // If the rx'd char is not 'enter' or lf
Rx_buff [Rx_index] = ch; // load the rx buffer with the char and
Rx_index++; // increment the index.
if (Rx_index >= RX_BUF_LEN)
Rx_index = 0;
}
if (ch == 13) { // When the 'enter' char is received
Rx_buff[Rx_index] = 0; // put a null char in the string.
Rx_index = 0; // and reset the index.
Com_flag = 1; // Com flag should be reset after the
} // buffer has been read.
// string is processed.
}
// interrput code for the timer 1
void __ISR( _TIMER_1_VECTOR, ipl2) _T1Interrupt( void)
{
int i;
asm("ei"); //To enable interrupts
// clear interrupt flag and exit
IFS0bits.T1IF = 0;
sampleBuffer[sampleIndex].re = read_ext_adc1(5) - 25485; // read the ADC into the real part of the samplebuffer
// increment the sampleIndex
if (sampleIndex == (N-1))
{
sampleIndex = 0;
}
else
{
sampleIndex++;
}
} // T3 Interrupt
void __ISR( _TIMER_3_VECTOR, ipl1) _T3Interrupt( void)
{ asm("ei");
IFS0bits.T3IF = 0;
//do something
}
Thanks