0

Feather M4 Sleep Mode
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Feather M4 Sleep Mode

by EvanMorsch on Sat Feb 09, 2019 10:32 pm

So I've been doing some research on how to put the M4 into sleep mode and I still quite cant figure it out. I've tried to send the "__WFI()", nothing happens. In the end, I'd like to put the board to sleep until I press a button, which is attached to an interrupt

EvanMorsch
 
Posts: 4
Joined: Tue Jan 02, 2018 10:45 pm

Re: Feather M4 Sleep Mode

by EvanMorsch on Sun Feb 17, 2019 8:40 am

okay, so ive gotten the following code to put it to sleep and it totally works, except it only wakes up when both interrupts are activated... How can i make it so only one needs to be active to wake it up?
Code: Select all | TOGGLE FULL SIZE
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
attachInterrupt(A1, wakeIsr, HIGH);
attachInterrupt(A2, wakeIsr, HIGH);
__disable_irq();
__WFI();
__enable_irq();

EvanMorsch
 
Posts: 4
Joined: Tue Jan 02, 2018 10:45 pm

Re: Feather M4 Sleep Mode

by EvanMorsch on Sun Feb 24, 2019 12:14 am

alright, so ive fixed my issue after LOTS of googling. ill post my solution here if anyone else is interested or wants to show me a better way.

Code: Select all | TOGGLE FULL SIZE
void goToSleep() {
  digitalWrite(13,HIGH);
  pinMode(11,INPUT_PULLUP);
  attachInterrupt(11, wakeIsr, LOW);
  pinMode(12,INPUT_PULLUP);
  attachInterrupt(12, wakeIsr, LOW);

  SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; //this first
  SCB->SCR |= SCB_SCR_SLEEPONEXIT_Msk; //this last
  __DSB(); //make sure the above is complete
  __WFI(); //sleep

  detachInterrupt(11);
  detachInterrupt(12);
  digitalWrite(13,LOW);
}

void wakeIsr() {
  wakeIsrFired = true;
  SCB->SCR &= ~SCB_SCR_SLEEPONEXIT_Msk; // Disable SLEEPONEXIT
  __DSB();
}

EvanMorsch
 
Posts: 4
Joined: Tue Jan 02, 2018 10:45 pm

Please be positive and constructive with your questions and comments.