SAMD21 has insomnia [Solved]

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Problem statement: I want my SAMD21 to wake on an RTC (match) interrupt or EXTIRQ button push, but it continues immediately from the __WFI statement.

 

My hunch is that there's a pending interrupt at the time I call __WFI, but I haven't been able to determine which one it is.  Unwinding the ASF4 code, my setup goes like this:

    // _set_sleep_mode to STANDBY
    SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
    // wait for interrupt
    __DSB();
    __WFI();
    // returns immediately without sleeping

What register(s) should I examine to see if there's a pending interrupt?  As far as I can see, it's not the RTC.

 

This topic has a solution.
Last Edited: Sun. Jul 19, 2020 - 01:36 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Update:

 

In a rather heavy-handed attempt to cure the chip's insomnia, I tried the following:

static void go_to_sleep(void) {
  NVIC_DisableIRQ(EIC_IRQn);
  NVIC_ClearPendingIRQ(EIC_IRQn);
  NVIC_ClearPendingIRQ(RTC_IRQn);
  NVIC_EnableIRQ(EIC_IRQn);
  sleep(3); // in hal_sleep
}

... but execution still continues past the __WFI without stopping.

 

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Solved.  There was pending data in the serial transmit buffer that kept the interrupt bit set.  Flushing the transmit data before sleeping fixed it.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

fearless_fool wrote:
Solved. 

Please see Tip #5 in my signature, below, for how to mark a thread as solved:

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...