0
\$\begingroup\$

I have read every post I can find and still do not understand why external interrupts are not triggering, the following is my initialization, it is not clean, as I am in the process of trying everything I can think of to make this work.

To simplify the problem, consider only INT1.

Update: It appears the flag is getting triggered, but the ISR is never being executed. The flag is not being lowered

void __attribute__((__interrupt__, no_auto_psv)) _INT1Interrupt(void)
{
IFS1bits.INT1IF = 0;    //Clear the INT1 interrupt flag 
//U1TXREG='0';

m_Capture1 = 1;

}  




// Hall Sensor A                | Pin 31    RPI24       RA8

// Disable all other pin functionality.
TRISAbits.TRISA8 = 1 ;
//LATAbits.LATA8 = 0;
ODCAbits.ODCA8=0;
CNENAbits.CNIEA8=0;
CNPUAbits.CNPUA8=0;
CNPDAbits.CNPDA8=0;


//INTCON1bits.NSTDIS = 0; // interrupt nesting enabled.
//INTCON2bits.GIE = 1;    // Global Interrupt Enable.

INTCON2 = 0x0000;       // all interrupts on rising edge.       

// Reset Interrupt flags.
IFS0bits.INT0IF = 0;      //Reset INT0 interrupt flag 
IFS1bits.INT1IF = 0;    //Reset INT1 interrupt flag
IFS1bits.INT2IF = 0;    //Reset INT2 interrupt flag

INTCON2bits.INT0EP = 1 ;
INTCON2bits.INT1EP = 1 ;
INTCON2bits.INT2EP = 1 ;

// Enable Interrupts.
IEC0bits.INT0IE = 1;    // Enable INT0 Interrupt Service Routine.
IEC1bits.INT1IE = 1;    // Enable INT1 Interrupt Service Routine. 
IEC1bits.INT2IE = 1;    // Enable INT2 Interrupt Service Routine.

// Set Interrupt Priority.
//IPC5bits.INT1IP = 5;  // If all the IPC bits associated with
                        // an interrupt source are cleared, the interrupt 
                        // source is effectively disabled.
//IPC7bits.INT2IP = 2;  //set low priority
//IPC0bits.INT0IP = 2;  //set low priority
IPC5bits.INT1IP = 4;    /*set low priority*/


RPINR0bits.INT1R |= 24;//0x18; //001 1000;    // Set Hall A - RPI24/RA8 set                     INT1
RPINR1bits.INT2R |= 51;//0x33; //011 0011     // Set Hall B = RPI51/RC3 set INT2
// Hall C RP39/RB7 is INT0 (not mappable)

I have verified with 100% certainty that the voltage on the pin is changing from 0 to 3.3V. Any help is appreciated.

Thanks, Gary

\$\endgroup\$
  • 3
    \$\begingroup\$ Uncommenting: INTCON2bits.GIE = 1; // Global Interrupt Enable. \$\endgroup\$ – Dirceu Rodrigues Jr Dec 14 '16 at 0:58
  • \$\begingroup\$ What is the exact chip model you have? \$\endgroup\$ – vini_i Dec 14 '16 at 1:12
  • \$\begingroup\$ dsPIC33EP64MC206 \$\endgroup\$ – GodJohnson Dec 14 '16 at 14:07
  • \$\begingroup\$ Unfortunately I have already tried uncommenting GIE \$\endgroup\$ – GodJohnson Dec 14 '16 at 14:12
2
\$\begingroup\$

At this point I feel fairly certain the problem was the line

 INTCON2 = 0x0000;

which effectively disabled bit 15 (global interrupt enable). The following is a working initialization function.

void BldcHallSensorInit( void )
{
// Hall Sensor A                | Pin 31    RPI24       RA8     INT2
// Hall Sensor B                | Pin 35    RPI51       RC3     INT1
// Hall Sensor C                | Pin 46    RP39        RB7     not mappable


TRISAbits.TRISA8 = 1 ;
TRISCbits.TRISC3 = 1 ;

RPINR0bits.INT1R = 51;  //001 1000;     // Set Hall B = RPI51/RC3 set INT2
RPINR1bits.INT2R = 24;  //011 0011      // Set Hall A - RPI24/RA8 set INT1 


//CORCONbits.IPL3 = 0;
//INTCON1bits.NSTDIS = 0; // interrupt nesting enabled.
//INTCON2bits.DISI = 0 ;
//INTCON2bits.SWTRAP = 0 ;

//INTCON2 = 0x0000;       // **erroneous line**       

// Reset Interrupt flags.
IFS0bits.INT0IF = 0;      //Reset INT1 interrupt flag 
IFS1bits.INT1IF = 0;    //Reset INT0 interrupt flag
IFS1bits.INT2IF = 0;    //Reset INT0 interrupt flag

// Interrupt edge polarity.
INTCON2bits.INT0EP = 1 ;
INTCON2bits.INT1EP = 1 ;
INTCON2bits.INT2EP = 1 ;

// Set Interrupt Priority.
IPC0bits.INT0IP = 1;    // set low priority.
IPC5bits.INT1IP = 1;    // set low priority.
IPC7bits.INT2IP = 1;    // set low priority.

// Enable Interrupts.
IEC0bits.INT0IE = 1;    // Enable INT0 Interrupt Service Routine.
IEC1bits.INT1IE = 1;    // Enable INT1 Interrupt Service Routine. 
IEC1bits.INT2IE = 1;    // Enable INT2 Interrupt Service Routine.

INTCON2bits.GIE = 1;    // Global Interrupt Enable. Order/placement of this
                        // line is important.
}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.