AnsweredAssumed Answered

Wake up using RTC

Question asked by yar on Oct 6, 2014
Latest reply on Oct 22, 2015 by Will X

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();

};

Outcomes