Skip to main content
Param sivan
Associate III
April 10, 2020
Question

I could not set the RTC alarm A second time

  • April 10, 2020
  • 3 replies
  • 736 views

Hi,

I am using STM32f429II processor. In my application I need to trigger the RTC in 1hr,2hr,3hr,4 hr intervals. So i decided to use RTC alarm A. For testing purpose, I set a 10 secs interval from the current time into alarm register. But it always triggers the alarm IRQ only once. If I reconfigure the the alarm and read the alarm register, still i could view the old values. The new alarm values didn't write into the RTC registers. Please help me to solve this issue.

void SetlogInterval (AirflowInterval_t Interval)
{
 
 NVIC_InitTypeDef NVIC_InitStructure;
 
 TF_Flag_t Status = FALSE;
 
 RTC_TimeTypeDef Current_Time;
 RTC_DateTypeDef Current_Date; 
 RTC_TimeTypeDef Alarm_Time; 
 RTC_AlarmTypeDef AlarmValue;
 
 //------------------------------------------------------------------------------------------------------
 
 RTC_GetTime(RTC_Format_BIN, &Current_Time);
 RTC_GetDate(RTC_Format_BIN, &Current_Date);
 
//------------------------------------------------------------------------------------------------------
 
 /* EXTI configuration */
 
 EXTI_ClearITPendingBit(EXTI_Line17); 
 EXTI_InitStructure.EXTI_Line = EXTI_Line17; 
 EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; 
 EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; 
 EXTI_InitStructure.EXTI_LineCmd = ENABLE; 
 EXTI_Init(&EXTI_InitStructure);
 
 NVIC_InitStructure.NVIC_IRQChannel = RTC_Alarm_IRQn; 
 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; 
 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; 
 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; 
 NVIC_Init(&NVIC_InitStructure); 
 // NVIC_EnableIRQ(RTC_Alarm_IRQn);
 
 NVIC_DisableIRQ(RTC_Alarm_IRQn);
 
 RTC_GetAlarm(RTC_Format_BIN,RTC_Alarm_A,&AlarmValue); // Read the Alarm Register 
 value
 
 AlarmValue.RTC_AlarmTime.RTC_H12 = Current_Time.RTC_H12;
 AlarmValue.RTC_AlarmTime.RTC_Hours = Current_Time.RTC_Hours;
 AlarmValue.RTC_AlarmTime.RTC_Minutes = Current_Time.RTC_Minutes;
 AlarmValue.RTC_AlarmTime.RTC_Seconds = Current_Time.RTC_Seconds + 10; // add 10 sec interval
 
 
 AlarmValue.RTC_AlarmDateWeekDaySel = RTC_AlarmDateWeekDaySel_Date;
 AlarmValue.RTC_AlarmDateWeekDay = Current_Date.RTC_Date;
 AlarmValue.RTC_AlarmMask = RTC_AlarmMask_DateWeekDay;
 
 /* Makes the DBP bit of PWR_CR register write accessible */
 RCC_APB1PeriphResetCmd(RCC_APB1Periph_PWR, DISABLE);
 
 RTC_WriteProtectionCmd(DISABLE);
 Status = RTC_AlarmCmd(RTC_Alarm_A, DISABLE); 
 Status = RTC_AlarmCmd(RTC_Alarm_B, DISABLE); 
 
 PWR_BackupAccessCmd(ENABLE); 
 
 RTC_SetAlarm(RTC_Format_BIN,RTC_Alarm_A,&AlarmValue);
 
 // for veryfiaction
 
 RTC_GetAlarm(RTC_Format_BIN,RTC_Alarm_A,&AlarmValue); // read the new value
 
 /* Enable RTC Alarm A Interrupt */
 
 RTC_ITConfig(RTC_IT_ALRA, ENABLE);
 
 /* Enable the alarm */
 
 Status = RTC_AlarmCmd(RTC_Alarm_A, ENABLE); 
 
 RTC_ClearFlag(RTC_FLAG_ALRAF); 
 
 PWR_BackupAccessCmd(DISABLE);
 
 /* Locks the DBP bit of PWR_CR register again */
 RCC_APB1PeriphResetCmd(RCC_APB1Periph_PWR, ENABLE);
 
 NVIC_EnableIRQ(RTC_Alarm_IRQn); 
}
 
void RTC_Alarm_IRQHandler(void)
{
 if(RTC_GetITStatus(RTC_IT_ALRA) != RESET)
 {
 RTC_ClearITPendingBit(RTC_IT_ALRA);
 EXTI_ClearITPendingBit(EXTI_Line17); 
 
 RTC_ClearFlag(RTC_FLAG_ALRAF);
 
 RTC_Alarm_Triggered = TRUE; // this flag call again the SetlogInterval() function to trigger after 10 secs
 
 }
 
}

This topic has been closed for replies.

3 replies

Mohamed Aymen HZAMI
ST Employee
April 10, 2020

Hello,

Why you don't use the HAL library ?

Best Regards,

Mohamed Aymen.

Param sivan
Associate III
April 13, 2020

The project developed without HAL library few years back. It will show more number of duplicate and no bit fields error while adding the HAL. So for time being i am continuing with our old library. Is it any advantage using HAL?

Is there any bug in my code?

Thanks,

Param.

Mohamed Aymen HZAMI
ST Employee
April 23, 2020

Hello,

Sorry for the delay, I will check your code and try to figure out the problem.

Best Regards,

Mohamed Aymen.