1

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

Dave Tweed
  • 168,369
  • 17
  • 228
  • 393
Triak
  • 916
  • 8
  • 14
  • 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 ... – brhans Feb 06 '15 at 20:13
  • 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. – Olin Lathrop Feb 06 '15 at 20:20
  • ISR does not work for T1 either. – Triak Feb 06 '15 at 20:31

1 Answers1

1

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
}
Dave Tweed
  • 168,369
  • 17
  • 228
  • 393
Triak
  • 916
  • 8
  • 14
  • 1
    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. – brhans Feb 06 '15 at 20:59