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

#### Robin66

Joined Jan 5, 2016
266
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
21,373
If you do not define the ISR then your system will do weird things or crash.
Try not enabling the CNIE bit.

#### Robin66

Joined Jan 5, 2016
266
Worth a try but that didn't work. The device stayed asleep indefinitely with the CN disabled

#### MrChips

Joined Oct 2, 2009
21,373
Worth a try but that didn't work. The device stayed asleep indefinitely with the CN disabled
Right, of course. The MCU needs an interrupt to wake up.

#### Robin66

Joined Jan 5, 2016
266
It's no biggie. I'll just have to implement the barebones interrupt vector.

#### MrChips

Joined Oct 2, 2009
21,373
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.