cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f429 rtc alarm problem

er3481
Associate III
Posted on October 25, 2016 at 10:37

Hi,

I am trying to use cubemx hal library for 1 second rtc interrupt. The call back function is called every time the ''minutes'' has changed. So it does not work for every 1 second. My rtc init and call back functions are below.

void MX_RTC_Init(void)

{

    /**Initialize RTC and set the Time and Date

    */

  hrtc.Instance = RTC;

  hrtc.Init.HourFormat = RTC_HOURFORMAT_24;

  hrtc.Init.AsynchPrediv = 127;

  hrtc.Init.SynchPrediv = 255;

  hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;

  hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;

  hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;

  HAL_RTC_Init(&hrtc);

      /**Enable the Alarm A

    */

  sAlarm.AlarmTime.Hours = 0x0;

  sAlarm.AlarmTime.Minutes = 0x0;

  sAlarm.AlarmTime.Seconds = 0x1;

  sAlarm.AlarmTime.SubSeconds = 0x0;

  sAlarm.AlarmTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;

  sAlarm.AlarmTime.StoreOperation = RTC_STOREOPERATION_RESET;

  sAlarm.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY|RTC_ALARMMASK_HOURS|RTC_ALARMMASK_MINUTES;

  sAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_ALL;

  sAlarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE;

  sAlarm.AlarmDateWeekDay = 0x1;

  sAlarm.Alarm = RTC_ALARM_A;

  HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, RTC_FORMAT_BCD);

}

void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc)

{  

  HAL_RTC_GetAlarm(hrtc,&sAlarm,RTC_ALARM_A,FORMAT_BIN);

  //functions_1s();

  if(sAlarm.AlarmTime.Seconds>58)

  {

    sAlarm.AlarmTime.Seconds=0;

  }

  else

  {

    sAlarm.AlarmTime.Seconds=sAlarm.AlarmTime.Seconds+1;

  }  

  while(HAL_RTC_SetAlarm_IT(hrtc, &sAlarm, FORMAT_BIN)!=HAL_OK){}

}

Any advise ??
5 REPLIES 5
Walid FTITI_O
Senior II
Posted on October 26, 2016 at 12:47

Hi rapid84, 

It seems that you are using the LSI as RTC clock source. The Predivisors (127, 255) are dedicated for LSE use case. for LSI clock source case , you should use (127, 304) as  (Asynch Prediv ,Synchro Prediv )

-Hannibal-

er3481
Associate III
Posted on October 26, 2016 at 15:19

Hi,

No, I am using external 32Khz crystal. At startup, i have to set the second to ''0'' and call the set time function, like this:

  sTime.Seconds = 0 ;  

  HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BIN);

Otherwise the rtc alarm interrupt routine is not called until the second of the time has changed to ''0''. So i need to find the solution of calling the rtc alarm interrupt at startup whatever the second of time value is. Any advise ??

jpeacock23
Associate II
Posted on October 26, 2016 at 16:29

I use an STM32L152 where I set the RTC alarm to trigger on subseconds = 0, or once per second.  I don't use the cube or HAL so can't give a code example.

Walid FTITI_O
Senior II
Posted on November 04, 2016 at 10:34

Hi rapid84, 

Since you haven't shared your code, I don't know how you have configurate your RTC and calendar. I recommend to have a look , to the example in STM32CubeF4 ''RTC_Calendar'' at this path : STM32Cube_FW_F4_V1.13.0\Projects\STM324xG_EVAL\Examples\RTC\RTC_Calendar

-Hannibal-

l90mehdi
Associate II
Posted on August 20, 2017 at 16:32

hi 

sAlarm.AlarmMask = RTC_ALARMMASK_All;

i tested it

it works good