2017-10-16 06:52 AM
Hi
I was running RTC with stm32f I use cmsis and using LSE(768 khz) for rtc.
I want to trig the RTC_IRQ on each second. How can I active it ? Its my code for adjusting rtc
static void RTC_Config(void) { RTC_TimeTypeDef RTC_TimeStruct; RTC_InitTypeDef RTC_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; /* Enable the PWR clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); /* Allow access to RTC */ PWR_BackupAccessCmd(ENABLE); /* Reset RTC Domain */ RCC_BackupResetCmd(ENABLE); RCC_BackupResetCmd(DISABLE); /* Enable the LSE OSC */ RCC_LSEConfig(RCC_LSE_ON); /* Wait till LSE is ready */ while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET) {} /* Select the RTC Clock Source */ RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE); /* Configure the RTC data register and RTC prescaler */ /* ck_spre(1Hz) = RTCCLK(LSI) /(AsynchPrediv + 1)*(SynchPrediv + 1)*/ RTC_InitStructure.RTC_AsynchPrediv = 0x7F; RTC_InitStructure.RTC_SynchPrediv = 0xFF; RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24; RTC_Init(&RTC_InitStructure); /* Set the time to 00h 00mn 00s AM */ RTC_TimeStruct.RTC_H12 = RTC_H12_AM; RTC_TimeStruct.RTC_Hours = 0x00; RTC_TimeStruct.RTC_Minutes = 0x00; RTC_TimeStruct.RTC_Seconds = 0x00; RTC_SetTime(RTC_Format_BCD, &RTC_TimeStruct); /////////////////////////////////////////////////////////////////////////////////////////////////////// /* Enable AlarmA interrupt */ RTC_ITConfig(RTC_IT_TS, ENABLE); /* Enable the RTC Alarm Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = RTC_IRQn; NVIC_InitStructure.NVIC_IRQChannelPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); RCC_RTCCLKCmd(ENABLE); // Enable RTC RTC_WaitForSynchro(); }�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?
Regards
hamed
#stm32 #rtc Note: this post was migrated and contained many threaded conversations, some content may be missing.2017-10-16 10:30 AM
2017-10-16 12:37 PM
Thanks for reply
How can I define this mask combination? Can you give the code?
2017-10-16 01:00 PM
I don't use the SPL, I use the HAL. In the HAL its part of your alarm initialization struct. Probably in the SPL, too. Read the app note and look at how the alarm struct is defined in the header file you use.
2017-10-16 03:32 PM
I use this code for enabling alarm for every one second. but it does not call the RTC_IRQHandler()
static void RTC_AlarmConfig(void){// EXTI_InitTypeDef EXTI_InitStructure; RTC_AlarmTypeDef RTC_AlarmStructure;// NVIC_InitTypeDef NVIC_InitStructure;/* Enable the RTC Alarm Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = RTC_IRQn; NVIC_InitStructure.NVIC_IRQChannelPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* Set the alarmA Masks */ RTC_AlarmStructure.RTC_AlarmMask = RTC_AlarmMask_All; RTC_SetAlarm(RTC_Format_BCD, RTC_Alarm_A, &RTC_AlarmStructure); RTC_AlarmSubSecondConfig(RTC_Alarm_A, 0x1, RTC_AlarmSubSecondMask_SS14);
/* Enable AlarmA interrupt */
RTC_ITConfig(RTC_IT_ALRA, ENABLE); }2017-10-16 05:34 PM
Isn't there a specific 1 Hz interrupt, try doing an alarm at multiple seconds in the future.
2017-10-17 07:02 AM
I realize that I cant set the alarm .I think it is the reason that rtc interrupt dont trig. for example I set the below variable:
RTC_AlarmStructure.RTC_AlarmTime.RTC_Hours = 5;
RTC_AlarmStructure.RTC_AlarmTime.RTC_Minutes = 5;
RTC_AlarmStructure.RTC_AlarmTime.RTC_Seconds = 5;
But the returned values of them is zero.
Its my code for set time and alarm value.
void RTC_TimeRegulate(void)
{
RTC_TimeTypeDef RTC_TimeStructure;
RTC_AlarmTypeDef RTC_AlarmStructure;
printf('\n\r==============Time Settings=====================================\n\r');
RTC_TimeStructure.RTC_H12 = RTC_H12_AM;
RTC_TimeStructure.RTC_Hours = 1;
RTC_TimeStructure.RTC_Minutes = 1;
RTC_TimeStructure.RTC_Seconds = 5;
}
/* Configure the RTC time register */
if(RTC_SetTime(RTC_Format_BIN, &RTC_TimeStructure) == ERROR)
{
printf('\n\r>> !! RTC Set Time failed. !! <<\n\r');
}
else
{
printf('\n\r>> !! RTC Set Time success. !! <<\n\r');
RTC_TimeShow();
/* Indicator for the RTC configuration */
RTC_WriteBackupRegister(RTC_BKP_DR0, BKP_VALUE);
}
/* Disable the Alarm A */
RTC_AlarmCmd(RTC_Alarm_A, DISABLE);
printf('\n\r==============Alarm A Settings=====================================\n\r');
RTC_AlarmStructure.RTC_AlarmTime.RTC_H12 = RTC_H12_AM;
RTC_AlarmStructure.RTC_AlarmTime.RTC_Hours = 1;
RTC_AlarmStructure.RTC_AlarmTime.RTC_Minutes = 1;
RTC_AlarmStructure.RTC_AlarmTime.RTC_Seconds = 10;
/* Set the Alarm A */
RTC_AlarmStructure.RTC_AlarmDateWeekDaySel = RTC_AlarmDateWeekDaySel_Date;
RTC_AlarmStructure.RTC_AlarmDateWeekDay = RTC_Weekday_Monday;
RTC_AlarmStructure.RTC_AlarmMask =RTC_AlarmMask_DateWeekDay;//RTC_AlarmMask_All;// RTC_AlarmMask_DateWeekDay;
/* Configure the RTC Alarm A register */
RTC_SetAlarm(RTC_Format_BIN, RTC_Alarm_A, &RTC_AlarmStructure);
printf('\n\r>> !! RTC Set Alarm success. !! <<\n\r');
RTC_AlarmShow();
/* Enable the RTC Alarm A Interrupt */
RTC_ITConfig(RTC_IT_ALRA, ENABLE);
/* Enable the alarm A */
RTC_AlarmCmd(RTC_Alarm_A, ENABLE);
}
void RTC_AlarmShow(void)
{
RTC_AlarmTypeDef RTC_AlarmStructure;
/* Get the current Alarm */
RTC_GetAlarm(RTC_Format_BIN, RTC_Alarm_A, &RTC_AlarmStructure);
printf('\n\r The current alarm is : %0.2d:%0.2d:%0.2d \n\r', RTC_AlarmStructure.RTC_AlarmTime.RTC_Hours, RTC_AlarmStructure.RTC_AlarmTime.RTC_Minutes, RTC_AlarmStructure.RTC_AlarmTime.RTC_Seconds);
}
Regards,
Hamed
2017-10-17 12:31 PM
How can I adjust alarm correctly?
2017-10-17 02:14 PM
printf('\n\r==============Alarm A Settings=====================================\n\r');
RTC_AlarmStructure.RTC_AlarmTime.RTC_H12 = RTC_H12_AM;
RTC_AlarmStructure.RTC_AlarmTime.RTC_Hours = 1;
RTC_AlarmStructure.RTC_AlarmTime.RTC_Minutes = 1;
RTC_AlarmStructure.RTC_AlarmTime.RTC_Seconds = 10;
I think you need to readAN3371