Deep sleep and wake up using RTC in LPC54618

cancel
Showing results for 
Search instead for 
Did you mean: 

Deep sleep and wake up using RTC in LPC54618

Jump to solution
206 Views
Contributor III

Hi,

I have found an example "utick_wakeup"  for waking up MCU from Deep Sleep mode and it works fine.

I tried to use normal rtc example and test it then I merge both RTC example and utick_wakeup example by commenting utick part since I want to use RTC only.

I have read datasheet and it shows that RTC can wake up MCU from deep sleep but may be I am not configuring it properly.

Do I have to include something below to keep RTC running even in deep sleep?

#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)

Can some one guide me where I am making mistake.

Using MCUXpresso IDE and SDK v2.4.1.

Regards,

SS

Labels (1)
0 Kudos
1 Solution
38 Views
NXP TechSupport
NXP TechSupport

Hello S S,

After check your code, it seems you haven't enable the RTC interrupt for wake-up from deep-sleep mode,

have a look at the register of  Start enable set register 0 (STARTERSET0 ) and Start enable register 0(STARTER0):

pastedImage_6.png

Hope it helps,


Have a great day,
TIC

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

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

View solution in original post

0 Kudos
4 Replies
38 Views
NXP TechSupport
NXP TechSupport

Hello S S,

Could you please share your project and tell me the problem, I will help you check it on my side.

BR

Alice

0 Kudos
38 Views
Contributor III

Hi Alice,

Thanks for reply!

I just want to wake the MCU  from deep sleep mode using RTC.

I  have configured it as below:

#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 )

int main(void)
{
gpio_pin_config_t led_config = {kGPIO_DigitalOutput, 0,};
uint8_t ch;

/* 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_AttachClk(kMAIN_CLK_to_CLKOUT);
/* Init RTC */
RTC_Init(RTC);

/* RTC time counter has to be stopped before setting the date & time in the TSR register */
RTC_StopTimer(RTC);


RTC_SetWakeupCount(RTC, 5000);
RTC_EnableInterrupts(RTC, kRTC_WakeupInterruptEnable);

/* Enable at the NVIC */
EnableIRQ(RTC_IRQn);

PRINTF("Press "Y" to power down the MCU\r\n");
while (1)
{
ch = GETCHAR();
if (ch == 'Y' || ch == 'y') 
{
break;
}
}
PRINTF("\r\n");

PRINTF("\r\n Alarm pending ");

/* Start the RTC time counter */
RTC_StartTimer(RTC);
/* Wait until alarm occurs */
POWER_EnterDeepSleep(APP_EXCLUDE_FROM_DEEPSLEEP);
PRINTF("\r\n Alarm occurs !!!! ");

while(1);
}

Sorry for the long post but I didnt get the option to attach whole project as .rar or .zip.

Kindly point out what else configuration is required.

Regards,

SS

0 Kudos
39 Views
NXP TechSupport
NXP TechSupport

Hello S S,

After check your code, it seems you haven't enable the RTC interrupt for wake-up from deep-sleep mode,

have a look at the register of  Start enable set register 0 (STARTERSET0 ) and Start enable register 0(STARTER0):

pastedImage_6.png

Hope it helps,


Have a great day,
TIC

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

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

View solution in original post

0 Kudos
38 Views
Contributor III

Hi Alice,

Thanks!!

I have redo the example and merge the power down part and it is working now.

#include "fsl_debug_console.h"
#include "board.h"
#include "fsl_rtc.h"

#include "pin_mux.h"
#include <stdbool.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)
{
busyWait = false;

/* Clear alarm flag */
RTC_ClearStatusFlags(RTC, kRTC_AlarmFlag);
}
/* 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
}

/*!
* @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);
GPIO_PinInit(GPIO, 3U, 19U, &led_config);
GPIO_PinInit(GPIO, 3U, 31U, &led_config);
GPIO_PinInit(GPIO, 3U, 27U, &led_config);
GPIO_PinInit(GPIO, 3U, 28U, &led_config);
GPIO_PinInit(GPIO, 3U, 29U, &led_config);
GPIO_PinInit(GPIO, 3U, 30U, &led_config);
GPIO_ClearPinsOutput(BOARD_LED1_GPIO, 3U, 1U << 19);
GPIO_ClearPinsOutput(BOARD_LED1_GPIO, 3U, 1U << 31);
GPIO_ClearPinsOutput(BOARD_LED1_GPIO, 3U, 1U << 27);
GPIO_ClearPinsOutput(BOARD_LED1_GPIO, 3U, 1U << 28);
GPIO_ClearPinsOutput(BOARD_LED1_GPIO, 3U, 1U << 29);
GPIO_ClearPinsOutput(BOARD_LED1_GPIO, 3U, 1U << 30);
/* 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;

/* Add alarm seconds to current time */
currSeconds += sec;

/* Set alarm time in seconds */
RTC->MATCH = 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);
/* Wait until alarm occurs */
while (busyWait)
{
}

PRINTF("\r\n Alarm occurs !!!! ");
}
}

Pasted the solution.

Regards,

SS

0 Kudos