Program halt after interrupt enable

mikroC, mikroBasic and mikroPascal PRO for Microchip’s 32-bit PIC MCUs
Post Reply
Author
Message
siradr
Posts: 34
Joined: 31 Oct 2008 18:22
Location: Malaysia

Program halt after interrupt enable

#1 Post by siradr » 24 May 2020 16:08

Hello,

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
}

siradr
Posts: 34
Joined: 31 Oct 2008 18:22
Location: Malaysia

Re: Program halt after interrupt enable

#2 Post by siradr » 25 May 2020 02:15

I found another strange behavior programming this chip. If i enable the interrupt and masking the Timer1 and UART receive interrupt, it will automatically still enable all interrupts for Timer1 and UART receive. There is something wrong with this. Could anybody do have a look ?

Code: Select all

       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
       
       

User avatar
jovana.medakovic
mikroElektronika team
Posts: 986
Joined: 18 Dec 2018 10:36

Re: Program halt after interrupt enable

#3 Post by jovana.medakovic » 25 May 2020 15:46

Hello,

Can you zip and send me your project for review, because I don't see that you initialized the UART module and call the InitTimer1 function?

Kind regards,
Jovana

siradr
Posts: 34
Joined: 31 Oct 2008 18:22
Location: Malaysia

Re: Program halt after interrupt enable

#4 Post by siradr » 28 May 2020 15:19

Hello Jovana,

Please see the program attached. It is a very simple program with just a few lines of codes.

Regards
Attachments
TestDebugFail.zip
(191.89 KiB) Downloaded 82 times

User avatar
jovana.medakovic
mikroElektronika team
Posts: 986
Joined: 18 Dec 2018 10:36

Re: Program halt after interrupt enable

#5 Post by jovana.medakovic » 01 Jun 2020 13:13

Hello,

In the attachment, you can find your project. I tested it and it works fine.
In the timer interrupt routine, you should set some flag and in the main function, you should check if the interrupt occurred.
Also, if you are using the PPS_Mapping function, you don't have to use Unlock_IOLOCK and Lock_IOLOCK function (read Help file).

Kind regards,
Jovana
Attachments
TestDebugFail.zip
(191.99 KiB) Downloaded 86 times

Post Reply

Return to “PIC32 PRO Compilers”