PIC24F: Is it always necessary to implement interrupt vector just to wake on CN?

Thread Starter

Robin66

Joined Jan 5, 2016
252
Hi Circuiteers. I can't find an answer to this. All I want to do is wake my PIC24F04KL device when a button is pressed. I thought I'd get away with the below
in init()
Code:
    // IoC
    IFS1bits.CNIF       = 0;  // clear CN IF
    IEC1bits.CNIE       = 1; // change notification
    CNEN2bits.CN29IE    = 1; // pin 5, button
in main()
Code:
    while(1)
    {
        Sleep();
       IFS1bits.CNIF       = 0;  // clear CN IF
        LED = 1;
        __delay_ms(10);
        LED = 0;
    }
However this results in a device reset on a button press. To make it work I have to define the interrupt vector below

Code:
void __attribute__((__interrupt__, auto_psv )) _ISR _CNInterrupt (void)
{
    IFS1bits.CNIF       = 0;  // clear CN IF
}
I thought in the past I've got away without doing this, but perhaps that was on a PIC16 or PIC18, or perhaps I'm misremembering entirely
 

MrChips

Joined Oct 2, 2009
19,425
The reason you may have gotten away with it in the past depends on the default MCU memory settings when no ISR is in place.
 
Top