cancel
Showing results for 
Search instead for 
Did you mean: 

RCT alarm interrupt problem

m91tfk
Associate
Posted on January 08, 2014 at 10:30

hello, everyone .

I had problem with the real time clock alarm.I've tried all the configuration to enable rtc calendar in accordance with the example in \ STM32F2xx_StdPeriph_Examples \ RTC \ HW_Calendar,but interrupt for alarm never generated .

hope

anyone can help

me

to

find

the point

where the

problem.

This is the code I'm using to do the configuration:

#include <
stm32f2xx.h
>
#include <
stm32f2xx_pwr.h
>
#include <
stm32f2xx_rcc.h
>
#include <
stm32f2xx_rtc.h
>
#include ''uUSART2.h''
RTC_TimeTypeDef RTC_TimeStructure;
RTC_AlarmTypeDef RTC_AlarmStructure;
RTC_DateTypeDef RTC_DateStructure;
int main (void) {
RealTimeClock_init();
cmdSetTime ();
cmdTime ();
SetAlarm ();
cmdAlarm ();
return 0;
}
void RealTimeClock_init(FunctionalState NewState) {
RTC_InitTypeDef RTC_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
if (NewState == DISABLE) {
return;
}
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); // Enable the PWR clock
PWR_BackupAccessCmd(ENABLE); // Allow access to RTC
RCC_LSEConfig(RCC_LSE_ON); // Enable the LSE OSC
while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET) { // Wait till LSE is ready
}
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE); // Select the RTC Clock Source
RCC_RTCCLKCmd(ENABLE); // Enable the RTC Clock
RTC_WaitForSynchro(); // Wait for RTC APB regs synchronisation
//Configure the RTC data register and RTC prescaler
__IO uint32_t AsynchPrediv = 0x7F;
__IO uint32_t SynchPrediv = 0xFF;
RTC_InitStructure.RTC_AsynchPrediv = AsynchPrediv;
RTC_InitStructure.RTC_SynchPrediv = SynchPrediv;
RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;
// Check on RTC init
if (RTC_Init(&RTC_InitStructure) == ERROR) {
xprintf(''\n\r /!\\***** RTC Prescaler Config failed ********/!\\ \n'');
}
/* RTC Alarm A Interrupt Configuration */
/* 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);
/* Enable the RTC Alarm Interrupt */
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);
}
extern ''C'' void RTC_Alarm_IRQHandler(void) {
if(RTC_GetITStatus(RTC_IT_ALRA) != RESET) {
Lamp(ENABLE);
RTC_ClearITPendingBit(RTC_IT_ALRA);
EXTI_ClearITPendingBit(EXTI_Line17);
}
}
void cmdSetTime (void) {
/* Set the time to 00h 00mn 00s AM */
int tmp_hh = 09, tmp_mm = 08, tmp_ss = 0;
/* Set the time */
RTC_TimStructure.RTC_H12 = RTC_H12_AM;
RTC_TimeStructure.RTC_Hours = tmp_hh;
RTC_TimeStructure.RTC_Minutes = tmp_mm;
RTC_TimeStructure.RTC_Seconds = tmp_ss;
/* Configure the RTC time register */
if(RTC_SetTime(RTC_Format_BIN, &RTC_TimeStructure) == ERROR) {
xprintf(''\n>> !! RTC Set Time failed. !! <<\n'');
}
else {
xprintf(''\n>> !! RTC Set Time success. !! <<\n'');
/* Indicator for the RTC configuration */
RTC_WriteBackupRegister(RTC_BKP_DR0, 0x32F2);
}
}
void cmdTime (void) {
/* Get the current Time */
RTC_GetTime(RTC_Format_BIN, &RTC_TimeStructure);
xprintf(''\n\r The current time is : %d:%d:%d \n'', RTC_TimeStructure.RTC_Hours, RTC_TimeStructure.RTC_Minutes, 
RTC_TimeStructure.RTC_Seconds);
}
void SetAlarm (void) {
int tmp_hh = 09 , tmp_mm = 10 , tmp_ss = 10;
/* Disable the Alarm A */
RTC_AlarmCmd(RTC_Alarm_A, DISABLE);
RTC_AlarmStructure.RTC_AlarmTime.RTC_H12 = RTC_H12_AM;
RTC_AlarmStructure.RTC_AlarmTime.RTC_Hours = tmp_hh;
RTC_AlarmStructure.RTC_AlarmTime.RTC_Minutes = tmp_mm;
RTC_AlarmStructure.RTC_AlarmTime.RTC_Seconds = tmp_ss;
/* Set the Alarm A */
RTC_AlarmStructure.RTC_AlarmDateWeekDay = 0x31;
RTC_AlarmStructure.RTC_AlarmDateWeekDaySel = RTC_AlarmDateWeekDaySel_Date;
RTC_AlarmStructure.RTC_AlarmMask = RTC_AlarmMask_Hours | RTC_AlarmMask_Minutes | RTC_AlarmMask_Seconds;
/* Configure the RTC Alarm A register */
RTC_SetAlarm(RTC_Format_BIN, RTC_Alarm_A, &RTC_AlarmStructure);
xprintf(''\n>> !! RTC Set Alarm success. !! <<\n'');
// 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 cmdAlarm (void) {
/* Get the current Time */
RTC_GetAlarm(RTC_Format_BIN, RTC_Alarm_A, &RTC_AlarmStructure);
xprintf(''\n\r The current alarm is : %d:%d:%d \n'', RTC_AlarmStructure.RTC_AlarmTime.RTC_Hours, 
RTC_AlarmStructure.RTC_AlarmTime.RTC_Minutes, RTC_AlarmStructure.RTC_AlarmTime.RTC_Seconds);
}

#real-time-clock-rtc-alarm
0 REPLIES 0