2012-06-15 10:06 AM
Hello Everyone,
I've had issues a couple times getting my Real Time Clock to correctly alarm and wake up my processor. My most recent issue had me reading through many posts on this site to try to figure out my problem. While I didn't find my answer on this site, I did want to share my solution here. My latest problem with the real time clock alarm ended up being that I had ''upgraded'' my STM32F103 libraries to the most recent version. I had forgotten that I had modified ST's real time clock library to add some synchronization and some error checking when I first turned on the alarm (a year or three ago) because I was having problems then too. Once I went back to my old files, things started working again. I have included the files as I modified them. Please note that I did use a couple timing features of an RTOS I am using (Segger's emBOS) to help me create a timeout from a loop. For testing purposes, you could simply comment out the timeouts, or replace them with your own way to do a timeout. No warranties are implied or provided by providing this code for a learning exercise, yada, yada... Hopefully looking at my modifications to ST's files can be helpful to you. If not, sorry I wasted your time... ;) Good luck! Adam #rtc-alarm #rtcalarm-with-wakeup-interrupts2012-10-26 06:11 AM
Hi Adam,
I need a suggesstions regarding RTC Alarm interrutp configuartion.I m using STM3220G-EVAL board. I tried configuring RTC Wakeup interrupt. I succeeded in it.When i was trying to configure RTC Alarm interrupt i parallel, i couldn able to do it...i m not getting the point where the problem is....Can we abe to generate two RTC interrupts from 2 interrupts simultaneously...I have added my config. code for RTC Alarm, kindly let me know if i missed out any configuration. RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); RTC_TimeTypeDef RTC_TimeStructure;RTC_InitTypeDef RTC_InitStructure;RTC_AlarmTypeDef RTC_AlarmStructure; /* Allow access to RTC */ PWR_BackupAccessCmd(ENABLE); NVIC_InitTypeDef NVIC_InitStructure; EXTI_InitTypeDef EXTI_InitStructure; #if defined (RTC_CLOCK_SOURCE_LSI) /* LSI used as RTC source clock*//* The RTC Clock may varies due to LSI frequency dispersion. */ /* Enable the LSI OSC */ RCC_LSICmd(ENABLE); /* Wait till LSI is ready */ while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET) { } /* Select the RTC Clock Source */ RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI); SynchPrediv = 0xFF; AsynchPrediv = 0x7F;#elif defined (RTC_CLOCK_SOURCE_LSE) /* LSE used as RTC source clock */ /* 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); SynchPrediv = 0xFF; AsynchPrediv = 0x7F;#else #error Please select the RTC Clock source inside the main.c file#endif /* RTC_CLOCK_SOURCE_LSI */ /* Enable the RTC Clock */ RCC_RTCCLKCmd(ENABLE); /* Wait for RTC APB registers synchronisation */ RTC_WaitForSynchro(); RTC_AlarmStructInit(&RTC_AlarmStructure); /* 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); /* Configure the RTC data register and RTC prescaler */ RTC_InitStructure.RTC_AsynchPrediv = AsynchPrediv; RTC_InitStructure.RTC_SynchPrediv = SynchPrediv; RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24; RTC_Init(&RTC_InitStructure); RTC_ITConfig(RTC_IT_ALRA, ENABLE);RTC_AlarmCmd(RTC_Alarm_A, DISABLE); RTC_AlarmStructure.RTC_AlarmTime.RTC_Hours = GPS.h; RTC_AlarmStructure.RTC_AlarmTime.RTC_Minutes = GPS.m; RTC_AlarmStructure.RTC_AlarmTime.RTC_Seconds=(GPS.s+TIMER); /* Configure the RTC Alarm A register */ RTC_SetAlarm(RTC_Format_BIN, RTC_Alarm_A, &RTC_AlarmStructure); /* Enable the alarm A */ ErrorStatus rtc_ala=RTC_AlarmCmd(RTC_Alarm_A, ENABLE);if (rtc_ala==SUCCESS){Debug_Print(''ALARM Enabled'');}else{Debug_Print(''ALARM Disabled'');}I could able to enable the RTC Alarm at this point but it is not getting to the Interrupt Context.IRQ Routine:void RTC_Alarm_IRQHandler(void){ if(RTC_GetITStatus(RTC_IT_ALRA) != RESET) { RTC_ClearITPendingBit(RTC_IT_ALRA); EXTI_ClearITPendingBit(EXTI_Line17); } }Kindly letme know your comments.......waiting for your suggestions....thanks in advance........Regards Suresh........