Why is the PIC32 not entering sleep mode?
I am setting the Sleep Mode Enable bit (SLPEN) in the OSCCON register, but why is the device not going to sleep?
A write to the OSCCON register requires an unlock sequence first. Refer to the device datasheet for more information on this unlock sequence. Here is an example:
SYSKEY = 0xAA996655;
SYSKEY = 0x556699AA;
// now change the OSCCON register
OSCCONbits.SLPEN = 1;
// now lock again
SYSKEY = 0x0;
// now go to sleep
asm volatile("wait");
while(1);