Wake up using RTC

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Wake up using RTC

1,928 Views
yar
Contributor III

Hi everyone, I faced a strange problem. I need to wake up my MKL15Z128VFT4 board from deep sleep mode using RTC Alarm interrupt. Here is my code:

void RTCTimer::rtc_dump_isr(void) {

  __disable_irq();

  printf("RTC ALARM interrupt!\r\n");

  RTC->TAR = RTC_TAR_TAR(time(NULL) + 1);

  /* disable alarm interrupt */

  RTC->IER &= ~RTC_IER_TAIE_MASK;

  /* disable RTC */

  SIM->SCGC6 &= ~SIM_SCGC6_RTC_MASK;

  __enable_irq();

};

void RTCTimer::init() {

  /* enable global interrupts */

  __enable_irq();

  /* turn on TRC */

  SIM->SCGC6 |= SIM_SCGC6_RTC_MASK;

  /* set LLWU exit source as RTC */

  LLWU->ME |= LLWU_ME_WUME5_MASK;

  /* set interruption handler */

  NVIC_SetVector(RTC_IRQn, (uint32_t)RTCTimer::rtc_dump_isr);

  NVIC_EnableIRQ(RTC_IRQn);

};

void RTCTimer::deepsleep_for(unsigned int seconds) {

  init();

  /* enable alarm interrupt */

  RTC->TAR = RTC_TAR_TAR(time(NULL) + 1);

  RTC->IER |= RTC_IER_TAIE_MASK;

  /* Set RTC time to Wed, 28 Oct 2009 11:35:37 */

  set_time(1256729737); 

  /* get current time */

  time_t start = time(NULL);

  /* set alarm after 10 seconds */

  RTC->TAR = RTC_TAR_TAR(start + seconds);

  deepsleep();

};

0 Kudos
3 Replies

1,140 Views
willx
Contributor IV

Hi yar, did you ever solve this ? I'm facing a similar problem and unable to wake up a K64 from any VLLS level using the RTC Alarm.

0 Kudos

1,140 Views
yar
Contributor III

Exuse me, message not completed. Here is the full version:

Hi everyone, I faced a strange problem. I need to wake up my MKL15Z128VFT4 board from deep sleep mode using RTC Alarm interrupt. Here is my code:

void RTCTimer::rtc_dump_isr(void) {

  __disable_irq();

  printf("RTC ALARM interrupt!\r\n");

  RTC->TAR = RTC_TAR_TAR(time(NULL) + 1);

  /* disable alarm interrupt */

  RTC->IER &= ~RTC_IER_TAIE_MASK;

  /* disable RTC */

  SIM->SCGC6 &= ~SIM_SCGC6_RTC_MASK;

  __enable_irq();

};

void RTCTimer::init() {

  /* enable global interrupts */

  __enable_irq();

  /* turn on TRC */

  SIM->SCGC6 |= SIM_SCGC6_RTC_MASK;

  /* set LLWU exit source as RTC */

  LLWU->ME |= LLWU_ME_WUME5_MASK;

  /* set interruption handler */

  NVIC_SetVector(RTC_IRQn, (uint32_t)RTCTimer::rtc_dump_isr);

  NVIC_EnableIRQ(RTC_IRQn);

};

void RTCTimer::deepsleep_for(unsigned int seconds) {

  init();

  /* enable alarm interrupt */

  RTC->TAR = RTC_TAR_TAR(time(NULL) + 1);

  RTC->IER |= RTC_IER_TAIE_MASK;

  /* Set RTC time to Wed, 28 Oct 2009 11:35:37 */

  set_time(1256729737);

  /* get current time */

  time_t start = time(NULL);

  /* set alarm after 10 seconds */

  RTC->TAR = RTC_TAR_TAR(start + seconds);

  deepsleep();

};

The problem is this code works okay in LLS(Low Leakage Stop), but doesn't work in VLLS(Very Low Leakage Stop). I mean, the interrupt doesn't happen and my board doesn't wake up. Did I forget something?

0 Kudos

1,140 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi yar,

    Thank you for your interest in our kinetis product, I would like to provide service for you!

    About your quesiton, our AN4503 will help you:

http://cache.freescale.com/files/32bit/doc/app_note/AN4503.pdf?fromsite=zh-Hans

    In page 32, there has a statement of how to exit from VLLSx mode with RTC.

"

If the exit from VLLSx mode is with the RTC or LPTMR, the order of code execution becomes important. If the

LLWU interrupt is enabled before the RTC or LPTMR and the RTC or LPTMR flags are not cleared by the LLWU

service routine, the execution will hang, never leaving the LLWU service routine. If, however, the RTC or LPTMR

interrupts are enabled, the interrupt vector for the timer causing the LLWU wake-up will be taken immediately. Upon

the return from interrupt, the timer flag is cleared and the LLWU interrupt will not be taken once enabled.

"

So, I think , if you have the LLWU interrupt, you should clear your RTC interrupt flag in the LLWU interrupt service function.

Wish it helps you!

If you still have quesition, please contact me!


Have a great day,
Jingjing

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos