I am trying to enable the interrupt on the PIC32MX570F512L on a very simple program but i am facing some issue. The program runs for about 2-3 seconds and then it hangs.
I have disable any WDT and also the only interrupt used is just Timer1 and also the UART1 interrupt. As you can see from my code below, it sends the string on the while loop for 2-3 times then the program hangs. Does anybody has encounter this problem before ? It is just a very simple program and i could not find the cause.
Code: Select all
sbit Alive at LATG9_bit;
unsigned long beat1ms=0;
//UART variables
char rxarray[50]; // array to store the received charaters
char b=0;
char uart_rd;
char stringComplete = 0;
void Timer1Interrupt() iv IVT_TIMER_1 ilevel 7 ics ICS_SRS {
T1IF_bit = 0;
//Enter your code here
beat1ms++;
if(beat1ms>500){
beat1ms=0;
Alive = ~Alive; // Toggle Alive LED
}
}
void InitTimer1(){
T1CON = 0x8000;
T1IP0_bit = 1;
T1IP1_bit = 1;
T1IP2_bit = 1;
T1IF_bit = 0;
T1IE_bit = 1;
PR1 = 48000;
TMR1 = 0;
}
void UART1interrupt() iv IVT_UART_1 ilevel 6 ics ICS_AUTO {
uart_rd = UART1_Read(); // read the received data
rxarray[b] = uart_rd;
b++; // increment counter to reset array
if (uart_rd == 0x0A) { // select this if looking for a terminating character
stringComplete = 1;
}// end if (rxchar == "Line feed \n")
U1RXIF_bit = 0;
}
void main() {
ANSELA = 0;
TRISA = 0;
LATA = 0; // turn OFF ports
EnableInterrupts(); // Enable all interrupts
T1IE_bit = 1; // Enable Timer1 Interrupt
ON_T1CON_bit = 1; // Enable Timer1
U1IP0_bit = 0; // Set UART1 interrupt
U1IP1_bit = 1; // Set interrupt priorities
U1IP2_bit = 1; // Set UART1 interrupt to level 6
U1RXIE_bit = 1; // Set UART Receive Interrupt
while(1){
UART1_Write_Text("Test123...");
Delay_ms(500);
}//While Loop
}