2015-05-11 06:27 AM
Hi,
I have a big problem with waking up the STM32F4 MCU from STANDBY mode by RTC alarm and I dont see any solutions...
The problem is that the MCU wakes up only sometimes from the RTC Alarm. Usually like 3 times in a row and then stops. Waking up by user button is fine...
I use LSE and clock itself works fine even when RTC alarm doesnt wake up the MCU...It looks like there is some problem with redefinition of the RTC alarm, possibly some IRQ flags...I found some topics regarding same problems but reading them all I think that I am doing everything right...
The operation itself should be simple...I manually set up RTC alarm and get to STANDBY mode and after that the MCU wakes up does something and then goes back to STANDBY in a loop until I interupt it manually by button...
Manual set up looks like this:
// Load time and date values from RTCRTC_AWU_GetDateTime(&time, RTC_AWU_Format_BIN);// Set up RTC alarmalarm_time.hours = time.hours;alarm_time.minutes = time.minutes;alarm_time.seconds = time.seconds + 5;alarm_time.alarmtype = RTC_AWU_AlarmType_DayInWeek;alarm_time.day = 1;RTC_AWU_SetAlarm(RTC_AWU_Alarm_B, &alarm_time, RTC_AWU_Format_BIN);/* Power down */// Disable wakeup pin (BUTTON = PA0)PWR_WakeUpPinCmd(DISABLE);// Clear standby/wakeup flagPWR_ClearFlag(PWR_FLAG_SB | PWR_FLAG_WU);// Enable wakeup pin (BUTTON = PA0)PWR_WakeUpPinCmd(ENABLE);// Go to standby modePWR_EnterSTANDBYMode();Then the loop exacly the same:
// RTC init (PWR_BackupAccessCmd(ENABLE) present here)RTC_AWU_Init(RTC_AWU_ClockSource_External);if (RTC_GetITStatus(RTC_IT_ALRB) != RESET){ /*Some code here*/ // Load time and date values from RTC RTC_AWU_GetDateTime(&time, RTC_AWU_Format_BIN); // Set up RTC alarm alarm_time.hours = time.hours; alarm_time.minutes = time.minutes; alarm_time.seconds = time.seconds + 5; alarm_time.alarmtype = RTC_AWU_AlarmType_DayInWeek; alarm_time.day = 1; RTC_AWU_SetAlarm(RTC_AWU_Alarm_B, &alarm_time, RTC_AWU_Format_BIN); /* Power down */ // Disable wakeup pin (BUTTON = PA0) PWR_WakeUpPinCmd(DISABLE); // Clear standby/wakeup flag PWR_ClearFlag(PWR_FLAG_SB | PWR_FLAG_WU); // Enable wakeup pin (BUTTON = PA0) PWR_WakeUpPinCmd(ENABLE); // Go to standby mode PWR_EnterSTANDBYMode();}The RTC_AWU_SetAlarm function looks like this...
// Disable Alarm BRTC_AlarmCmd(RTC_Alarm_B, DISABLE);// Disable Alarm B interruptRTC_ITConfig(RTC_IT_ALRB, DISABLE);// Clear Alarm B pending bitRTC_ClearFlag(RTC_IT_ALRB);// Clear RTC Alarm pending bitEXTI_ClearITPendingBit(EXTI_Line17);// Configure EXTI 17 as interruptEXTI_InitStruct.EXTI_Line = EXTI_Line17;EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Rising;EXTI_InitStruct.EXTI_LineCmd = ENABLE;EXTI_Init(&EXTI_InitStruct);// Configure the RTC Alarm InterruptNVIC_InitStruct.NVIC_IRQChannel = RTC_Alarm_IRQn;NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 0;NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0;NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;NVIC_Init(&NVIC_InitStruct);// Set RTC alarm settings// Set alarm timeRTC_AlarmStruct.RTC_AlarmTime.RTC_Hours = DataTime->hours;RTC_AlarmStruct.RTC_AlarmTime.RTC_Minutes = DataTime->minutes;RTC_AlarmStruct.RTC_AlarmTime.RTC_Seconds = DataTime->seconds;RTC_AlarmStruct.RTC_AlarmMask = RTC_AlarmMask_DateWeekDay;etc...// Configure the RTC Alarm BRTC_SetAlarm(format, RTC_Alarm_B, &RTC_AlarmStruct);// Clear Alarm B pending bitRTC_ClearFlag(RTC_IT_ALRB);// Enable Alarm B interruptRTC_ITConfig(RTC_IT_ALRB, ENABLE);// Enable Alarm BRTC_AlarmCmd(RTC_Alarm_B, ENABLE);Thanks very much for your help...
#rtc #stm32f4 #alarm2015-05-15 05:38 AM
Hi problem was with this line....alarm_time.seconds = time.seconds + 5;
Basically an overflow of the usable range...I thought that the RTC modifies the data before using...2015-05-15 05:56 AM
> Hi problem was with this line....alarm_time.seconds = time.seconds + 5;
Thanks for letting us know, this may help others. I fought RTC recently too - setting the time to 12h mode (am/pm) then setting hour to 13 allows the clock to run up to 31:59:59... :) JW