Deep sleep and wake up using RTC in LPC54018

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Deep sleep and wake up using RTC in LPC54018

跳至解决方案
652 次查看
mitchkapa
Contributor III

Hello, I am essentially trying to replicate the success of this post (https://community.nxp.com/t5/LPC-Microcontrollers/Deep-sleep-and-wake-up-using-RTC-in-LPC54618/m-p/9...) but using the LPC54018 processor instead.  I placed a comment within that thread noting that I can see a wakeup occurring via the RTC however I cannot get execution to return to the main function.  Is there some fundamental difference between the LPC54618 and LPC54018 when using the RTC for deep sleep?

0 项奖励
回复
1 解答
606 次查看
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

Pls try to use the line:

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

 

BR

XiangJun Rong

在原帖中查看解决方案

0 项奖励
回复
6 回复数
635 次查看
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

As you know that the waking-up from deep-sleep follows up the interrupt procedure, in other words, when the waking-up happens, it enters ISR  firstly, after executing the ISR, it returns to main from ISR.

So you have to enable the alarm interrupt and create an ISR for the RTC alarm interrupt.

Pls have a try.

If you have issue, pls post your code, I will have a review.

BR

XiangJun Rong

 

0 项奖励
回复
630 次查看
mitchkapa
Contributor III

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 !!!! ");
}
}

 

0 项奖励
回复
617 次查看
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

where you declare the bool variable busyWait?

How about  commenting the following line

while (busyWait)
{
}

BR

XiangJun Rong

0 项奖励
回复
611 次查看
mitchkapa
Contributor III

The variable is declared here:

/*******************************************************************************
* Variables
******************************************************************************/
 
volatile bool busyWait;
 
I tried commenting out the while loop and the code still does not reach the final PRINTF statement.
0 项奖励
回复
607 次查看
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

Pls try to use the line:

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

 

BR

XiangJun Rong

0 项奖励
回复
601 次查看
mitchkapa
Contributor III

Thank you this was the solution I was missing SYSCON_PDRUNCFG_PDEN_VD6_MASK from the exclusions.

0 项奖励
回复