1
\$\begingroup\$

I have a problem setting up Interrupt Service Routine for PIC24F08KA101.
I have successfully initialized IE,IF,IP for interrupts which I need to use.
Part of the code which initializes these:

void
int_init(void)
{       
IEC1bits.INT2IE=1; //Enable Interrupt
IFS1bits.INT2IF=0; //Clear Interrupt Flag
INTCON2bits.INT2EP=0;   //activate on positive edge
IPC7bits.INT2IP=3; //Set priority (higher gets executed first)
IEC0bits.T1IE=1;   //Enable Interrupt
IFS0bits.T1IF=0;   //Clear IF
IPC0bits.T1IP=2;   //Set priority
}

I have checked them from the PIC24F08KA101.h. The clock prescaler is not shown in this code.
I have problem initializing ISR for INT2 (External interrupt port 2) and T1 (timer1). I tried to use this ISR, but it does not work. Got it from code examples.

void __attribute__((interrupt,no_auto_psv)) _INT2Interrupt(void); //Declare
void 
__attribute__((interrupt,no_auto_psv)) _INT2Interrupt(void)
{
    //Do stuff here
}

I tried the same for timer1, but it does not work too.
I use HI-TECH for dsPIC/PIC24 V9.62 compiler.
INT2 is selectable port for the PIC I use. Pins

\$\endgroup\$
  • \$\begingroup\$ Don't know if it'll make any difference, but the recommended order is to 1st set priority in IPC, then clear flag in IFS, and last enable in IEC ... \$\endgroup\$ – brhans Feb 6 '15 at 20:13
  • \$\begingroup\$ Did you maybe forget to select the INT2 input peripheral pin select? I haven't looked up whether that is a selectable input on this PIC. That's your job. \$\endgroup\$ – Olin Lathrop Feb 6 '15 at 20:20
  • \$\begingroup\$ ISR does not work for T1 either. \$\endgroup\$ – Triak Feb 6 '15 at 20:31
1
\$\begingroup\$

SOLVED: I needed to use this initialization instead of the second code in my question.

void interrupt _T1Interrupt(void); //Initialize
void 
interrupt _T1Interrupt(void) @ T1_VCTR  
{
//Do stuff here
}
\$\endgroup\$
  • 1
    \$\begingroup\$ Aah - so your problem was that you were using the Microchip XC16 compiler declarations for your ISRs but you're actually using the HI-TECH compiler. \$\endgroup\$ – brhans Feb 6 '15 at 20:59

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.