Below is the source code. I am running this code on the LPCXpresso54018 development board. Within the RTC_IRQHandler function I put multiple PRINTF statements and those do print so the wake up from sleep is happening. But the "Alarm Occurs" message from the main body never prints. Here is an example of the debug output:
RTC example: set up time to wake up an alarm
Current datetime: 2014-12-25 19: 0: 0
Please input the number of second to wait for alarm
The second must be positive value
5
currSecond =: 1419534002Alarm will occur at: 2014-12-25 19: 0: 7
Interrupt occurs !!!!
I cleared the alarm flag !!!!
I got past the IF errata statement !!!!
_______________________________________________________
Here is the source code:
#include "fsl_debug_console.h"
#include "board.h"
#include "fsl_rtc.h"
#include "pin_mux.h"
#include <stdbool.h>
#include "peripherals.h"
#include "fsl_common.h"
#include "fsl_power.h"
/*******************************************************************************
* Definitions
******************************************************************************/
#define APP_EXCLUDE_FROM_DEEPSLEEP \
(SYSCON_PDRUNCFG_PDEN_SRAMX_MASK | SYSCON_PDRUNCFG_PDEN_SRAM0_MASK | SYSCON_PDRUNCFG_PDEN_SRAM1_2_3_MASK | SYSCON_PDRUNCFG_PDEN_WDT_OSC_MASK \
)
/*******************************************************************************
* Prototypes
******************************************************************************/
/*******************************************************************************
* Variables
******************************************************************************/
volatile bool busyWait;
/*******************************************************************************
* Code
******************************************************************************/
/*!
* @brief ISR for Alarm interrupt
*
* This function changes the state of busyWait.
*/
void RTC_IRQHandler(void)
{
if (RTC_GetStatusFlags(RTC) & kRTC_AlarmFlag)
{
PRINTF("\r\n Interrupt occurs !!!! ");
busyWait = false;
/* Clear alarm flag */
RTC_ClearStatusFlags(RTC, kRTC_AlarmFlag);
PRINTF("\r\n I cleared the alarm flag !!!! ");
}
/* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
exception return operation might vector to incorrect interrupt */
#if defined __CORTEX_M && (__CORTEX_M == 4U)
__DSB();
#endif
PRINTF("\r\n I got past the IF errata statement !!!! ");
}
/*!
* @brief Main function
*/
int main(void)
{
gpio_pin_config_t led_config = {kGPIO_DigitalOutput, 0,};
uint32_t sec;
uint32_t currSeconds;
uint8_t index;
rtc_datetime_t date;
/* Board pin, clock, debug console init */
/* attach 12 MHz clock to FLEXCOMM0 (debug console) */
CLOCK_AttachClk(BOARD_DEBUG_UART_CLK_ATTACH);
/* Enable the RTC 32K Oscillator */
SYSCON->RTCOSCCTRL |= SYSCON_RTCOSCCTRL_EN_MASK;
BOARD_InitPins();
BOARD_BootClockFROHF48M();
BOARD_InitDebugConsole();
CLOCK_EnableClock(kCLOCK_Gpio3);
/* Init RTC */
RTC_Init(RTC);
PRINTF("RTC example: set up time to wake up an alarm\r\n");
/* Set a start date time and start RT */
date.year = 2014U;
date.month = 12U;
date.day = 25U;
date.hour = 19U;
date.minute = 0;
date.second = 0;
/* RTC time counter has to be stopped before setting the date & time in the TSR register */
RTC_StopTimer(RTC);
/* Set RTC time to default */
RTC_SetDatetime(RTC, &date);
/* Enable RTC alarm interrupt */
RTC_EnableInterrupts(RTC, kRTC_AlarmInterruptEnable);
/* Enable at the NVIC */
EnableIRQ(RTC_IRQn);
EnableDeepSleepIRQ(RTC_IRQn);
/* Start the RTC time counter */
RTC_StartTimer(RTC);
/* This loop will set the RTC alarm */
while (1)
{
busyWait = true;
index = 0;
sec = 0;
/* Get date time */
RTC_GetDatetime(RTC, &date);
/* print default time */
PRINTF("Current datetime: %04d-%02d-%02d %02d:%02d:%02d\r\n",
date.year,
date.month,
date.day,
date.hour,
date.minute,
date.second);
/* Get alarm time from user */
PRINTF("Please input the number of second to wait for alarm \r\n");
PRINTF("The second must be positive value\r\n");
while (index != 0x0D)
{
index = GETCHAR();
if((index >= '0') && (index <= '9'))
{
PUTCHAR(index);
sec = sec * 10 + (index - 0x30U);
}
}
PRINTF("\r\n");
/* Read the RTC seconds register to get current time in seconds */
currSeconds = RTC->COUNT;
PRINTF("currSecond =: %d", currSeconds);
/* Add alarm seconds to current time */
currSeconds += sec;
/* Set alarm time in seconds */
RTC->MATCH = currSeconds;
//RTC_SetAlarm(RTC, currSeconds);
/* Get alarm time */
RTC_GetAlarm(RTC, &date);
/* Print alarm time */
PRINTF("Alarm will occur at: %04d-%02d-%02d %02d:%02d:%02d\r\n",
date.year,
date.month,
date.day,
date.hour,
date.minute,
date.second);
POWER_EnterDeepSleep(APP_EXCLUDE_FROM_DEEPSLEEP);
//POWER_EnterSleep();
/* Wait until alarm occurs */
while (busyWait)
{
}
PRINTF("\r\n Alarm occurs !!!! ");
}
}