Hi, my code will sleep if I disable INTR_GLOBAL but will not wake from following code.
uP is DSPIC33FJ16GS502
I've tried every combination I can think of. Data sheet says:
"The device will wake-up from Sleep mode on any of
these events:
• Any interrupt source that is individually enabled
• Any form of device Reset
• A WDT time-out"
My interrupt code sets state machine:
Code:
#INT_EXT1
void IntReedSwitch(void)
{
printf("EXT1 fired\r\n");
main_state = POWER_UP_DOWN; //jump to power up/down
}
My power up or down case from my state machine:
case POWER_UP_DOWN:
if (sleep_mode==0)
{
delay_ms(1000);
sleep_mode=1;
disable_interrupts(INTR_GLOBAL);
disable_interrupts(INT_TIMER1);
enable_interrupts(INT_EXT1);
clear_interrupt(INT_EXT1);
printf("Going to sleep now!\r\n");
sleep(); // make processor sleep
delay_cycles(1); //Avoid problem with the next instruction being fetched
// printf("Waking from sleep now!\r\n");
}
else
{
clear_interrupt(INT_EXT1);
sleep_mode=0;
printf("Wakey wakey!\r\n");
// enable_interrupts(INTR_GLOBAL);
enable_interrupts(INT_TIMER1);
}
main_state = TIMEOUT;
break;
The idea is that the EXT1 input makes the uP wake up and also go to sleep (basically an on off push button function).
EXT1 is mapped using RPINR0 = 0x0900; which sets EXT1 to remappable pin 9.
Based on the statement from the datasheet, am I correct to presume I can use EXT1 to wake uP?
Thanks!
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
Posted: Wed Aug 19, 2015 4:43 pm
If you disable global interrupts, your code will never enter the #INT_EXT1
routine. Therefore, the main_state will never be set to POWER_UP_DOWN.
I think you need to post a complete (but still small) test program.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum