cancel
Showing results for 
Search instead for 
Did you mean: 

RTC Alarm not working more than once

JGarc.5
Associate III

Hello all,

I'm trying to prototype a shutdown mode with a RTC alarm.

I'm flashing the LED 5 times, then I set-up the RTC calendar, clock and alarm A (5 seconds after set-up clock). Then I go to shutdown mode.

Everything works when I program my system (now testing with a 432KC Nucleo) and go to debugging. I see 5 LED flashes, then a 5s pause, and then 5 flashes again (forever).

But when I unplug the USB, and plug it again, the system goes to shutdown but never wakes again.

I'm using

__HAL_RCC_PWR_CLK_ENABLE();

 HAL_PWR_EnableBkUpAccess();

just before configurating RTC to avoid parasitic protection, and also wait for sync after each write to RTC registers,but no success.

This is my code, mainly MX generated and ST firmware examples

int main(void)

{

 HAL_Init();

 SystemClock_Config();

  MX_GPIO_Init();

 __HAL_RCC_PWR_CLK_ENABLE();

 HAL_PWR_EnableBkUpAccess();

 MX_RTC_Init();

 MX_USART2_UART_Init();

 while (1)

 {

for(int i =0; i < 5; i++ ){

HAL_Delay(250);

HAL_GPIO_WritePin(LD3_GPIO_Port,LD3_Pin,GPIO_PIN_SET);

 HAL_Delay(250);

 HAL_GPIO_WritePin(LD3_GPIO_Port,LD3_Pin,GPIO_PIN_RESET);

}

HAL_PWREx_EnableInternalWakeUpLine();

RTC_AlarmConfig();

HAL_PWREx_EnterSHUTDOWNMode();

Error_Handler_Ticks(4);

 }

}

void RTC_AlarmConfig(void)

{

 RTC_DateTypeDef sdatestructure;

 RTC_TimeTypeDef stimestructure;

 RTC_AlarmTypeDef salarmstructure;

 HAL_PWR_EnableBkUpAccess();

 /* Clear the RTC Alarm-A Flag */

 __HAL_RTC_ALARM_CLEAR_FLAG(&hrtc,RTC_FLAG_ALRAF);

 /*##-1- Configure the Date #################################################*/

 /* Set Date: Tuesday February 18th 2014 */

 sdatestructure.Year = 0x14;

 sdatestructure.Month = RTC_MONTH_FEBRUARY;

 sdatestructure.Date = 0x18;

 sdatestructure.WeekDay = RTC_WEEKDAY_TUESDAY;

 if(HAL_RTC_SetDate(&hrtc,&sdatestructure,RTC_FORMAT_BCD) != HAL_OK)

 {

  /* Initialization Error */

 Error_Handler_Ticks(5);

 }

 HAL_RTC_WaitForSynchro(&hrtc);

 /*##-2- Configure the Time #################################################*/

 /* Set Time: 02:20:00 */

 stimestructure.Hours = 0x02;

 stimestructure.Minutes = 0x20;

 stimestructure.Seconds = 0x00;

 stimestructure.TimeFormat = RTC_HOURFORMAT12_AM;

 stimestructure.DayLightSaving = RTC_DAYLIGHTSAVING_NONE ;

 stimestructure.StoreOperation = RTC_STOREOPERATION_RESET;

 if(HAL_RTC_SetTime(&hrtc,&stimestructure,RTC_FORMAT_BCD) != HAL_OK)

 {

  /* Initialization Error */

 Error_Handler_Ticks(6);

 }

 HAL_RTC_WaitForSynchro(&hrtc);

 /*##-3- Configure the RTC Alarm peripheral #################################*/

 /* Set Alarm to 02:20:30

   RTC Alarm Generation: Alarm on Hours, Minutes and Seconds */

 salarmstructure.Alarm = RTC_ALARM_A;

 salarmstructure.AlarmDateWeekDay = RTC_WEEKDAY_MONDAY;

 salarmstructure.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_WEEKDAY;

 salarmstructure.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY;

 salarmstructure.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_NONE;

 salarmstructure.AlarmTime.TimeFormat = RTC_HOURFORMAT12_AM;

 salarmstructure.AlarmTime.Hours = 0x02;

 salarmstructure.AlarmTime.Minutes = 0x20;

 salarmstructure.AlarmTime.Seconds = 0x02;

 salarmstructure.AlarmTime.SubSeconds = 0x56;

 HAL_RTC_DeactivateAlarm(&hrtc,RTC_ALARM_A);

 if(HAL_RTC_SetAlarm_IT(&hrtc,&salarmstructure,RTC_FORMAT_BCD) != HAL_OK)

 {

  /* Initialization Error */

 Error_Handler_Ticks(7);

 }

 HAL_RTC_WaitForSynchro(&hrtc);

}

1 ACCEPTED SOLUTION

Accepted Solutions
JGarc.5
Associate III

Just when I stopped, trying, I found the solution.

I was using LSI as RTC source, and it does not work while on Shutdown mode.

My question is now, why was it working when programming the microcontroller? Is the ST-Link using it in some way and is it working even in shutdown mode?

View solution in original post

2 REPLIES 2
JGarc.5
Associate III

Just when I stopped, trying, I found the solution.

I was using LSI as RTC source, and it does not work while on Shutdown mode.

My question is now, why was it working when programming the microcontroller? Is the ST-Link using it in some way and is it working even in shutdown mode?

Couldn't the debugger effectively have prevented the mcu to really go into the Shutdown mode? There's quite a couple of options in DBGMCU and possibly elsewhere, related to the low-power modes and debugger can possibly exploit them. See documentation to your debugger, and perhaps try clicking through any related options available .

The Unstable LSI when it clocks RTC or CSS on LSE erratum also hints that it's possible to have Shutdown while LSI is running (cites (CSS) on LSE, but maybe also some of the watchdogs may keep it running).

JW