I'm learning PIC32 and making some tests to make sure my ISRs are working properly. My test code is just turning a LED on and off in a time interval controlled by the ISR. Problem is, the ISR executes only once, and I don't get why.

I've tried the actual code to turn the LED on and off in the main function, with a timer between the turning on and off, it's working fine. I've tried different ways of clearing the interrupt flag to make sure it's cleared. but i can't say if it's actually ok or not.

here is the code

#include <p32xxxx.h>    
#include <string.h>    
#include <stdio.h>    
#include <stdlib.h>    
#include <stdbool.h>        
#include <plib.h> 
#include <xc.h>

#define PIN_bypassled PORTEbits.RE4 
#define PIN_bypassledwrite LATEbits.LATE4 

//-------- ISRs   -----------------

//low speed timer 
void __ISR( _TIMER_2_VECTOR, ipl7) Swiching_loop( void)
{
//    INTDisableInterrupts();

    mT2ClearIntFlag();  //  first attempt to clear interrput flag
    IFS0bits.T2IF = 0;  //  second attempt to clear interrupt flag


    PIN_bypassledwrite = !PIN_bypassled;

//   INTEnableInterrupts();
 }

void main() {
    TRISE = 0x000000;
    SYSTEMConfigPerformance(80000000L);  //            INTEnableSystemSingleVectoredInt();


//    T1CON = 0X0010;                    //TMR1 Off, PRESCALE 1:256, 16b mode 
    PR1 = 100000; 
   mT1SetIntPriority(7);                //set priority interrupt level for timer 1 
    T1CON = 0x8030;                   //TMR1 ON, PRESCALE 1:256, 16b mode 
    mT1IntEnable(1);                      //

 //   T2CON = 0X0030;                    //TMR2 Off, PRESCALE 1:256, 16b mode 
    PR2 = 100000; 
    mT2SetIntPriority(7);                //set priority interrupt level for timer 2
    T2CON = 0x8070;                   //TMR2 ON, PRESCALE 1:256, 16b mode 
    mT2IntEnable(1);                      //

    INTEnableInterrupts();
    while (1){ 

  }
}

expected result would be my LED turning on and off, but instead it's just turning on. I interpret this as the ISR only executing once, but maybe i'm missing something since i'm under the impression that i'm clearing the interrupt flag correctly. What am i missing?

0 Answers

Related Questions