RTC interrupts in peripheral_server_sleep

I’m trying to add RTC clock and alarm interrupts to the peripheral_server_sleep example but can’t seem to get it working with low power sleep. I added the following code to enable the RTC clock and alarm interrupts:

bool alarm_high = false;
void RTC_ALARM_IRQHandler() {
Sys_DIO_Config(10, alarm_high ? DIO_MODE_GPIO_OUT_0 : DIO_MODE_GPIO_OUT_1);
alarm_high = !alarm_high;
ACS_WAKEUP_CTRL->RTC_ALARM_WAKEUP_CLEAR_ALIAS = WAKEUP_RTC_ALARM_CLEAR_BITBAND;
}

bool clock_high = false;
void RTC_CLOCK_IRQHandler() {
Sys_DIO_Config(11, clock_high ? DIO_MODE_GPIO_OUT_0 : DIO_MODE_GPIO_OUT_1);
clock_high = !clock_high;
}

void enable_rtc() {
Sys_RTC_Config(RTC_CNT_START_4294967295, RTC_RESET | RTC_ALARM_2S | RTC_ENABLE | RTC_CLK_SRC_XTAL32K);
NVIC_ClearPendingIRQ(RTC_ALARM_IRQn);
NVIC_ClearPendingIRQ(RTC_CLOCK_IRQn);
NVIC_EnableIRQ(RTC_ALARM_IRQn);
NVIC_EnableIRQ(RTC_CLOCK_IRQn);
ACS_WAKEUP_CTRL->RTC_ALARM_WAKEUP_CLEAR_ALIAS = WAKEUP_RTC_ALARM_CLEAR_BITBAND;
Sys_RTC_Start(RTC_ENABLE_BITBAND);
}

I call enable_rtc(); at the end of the App_Initialize function just before the “stop masking interrupts”. If I comment out the sleep mode in the Main_Loop, I.E. this line:
BLE_Power_Mode_Enter(&sleep_mode_env, POWER_MODE_SLEEP);
then both the alarm and clock interrupts trigger as expected, so my guess is that there’s something I’m not setting correctly with the sleep settings, but I can’t figure out what.

Thanks,
David

Hi @martin.bela ,
I think the issue root cause is ACS->RTC_CTRL configuration.
Customer uses RTC_ALARM_2S. It is not correct.
Please ask him to reference our sleep_ram_retention example:

image

@dgeissler

We believe that the root cause issue is ACS->RTC_CTRL configuration.
You used RTC_ALARM_2S. It is not correct.

Please refer to our sleep_ram_retention example:

image

Thank you for using our community forum!

Thanks for the reply.

I tried changing ACS->RTC_CTRL to use RTC_ALARM_ZERO instead of RTC_ALARM_2S; however this didn’t fix the issue. The RTC interrupt still doesn’t trigger after sleep mode is entered. And if I don’t use sleep then this makes the alarm stop triggering all together!

David

In case anybody stumbles on this in the future, I found what I was doing wrong.
The RTC_ALARM_IRQHandler doesn’t trigger when sleeping, but it does wake up from sleep when the alarm triggers. So you need to check the wakeup source in the Continue_Application() to know if it was woken up due to the alarm triggering. This can be checked with:
if (ACS_WAKEUP_CTRL->RTC_ALARM_WAKEUP_ALIAS == 0x01)

David

1 Like