cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 RTC Alarm problem

sami
Associate II
Posted on April 28, 2013 at 23:08

Hello

I am trying to setup he alarim to wakeup my MCU from standby everyday at 12:00 but it seems that some times the alarm nor occurs and some it occurs .. what i miss in my code?

RTC_AlarmCmd(RTC_Alarm_A, DISABLE); 
RTC_GetTime(RTC_Format_BIN, &RTC_TimeStructure); 
//RTC_GetDate(RTC_Format_BIN,&RTC_DateStructure); 
/* Set the alarm to current time + 5s */ 
RTC_AlarmStructure.RTC_AlarmTime.RTC_H12 = RTC_H12_PM; 
RTC_AlarmStructure.RTC_AlarmTime.RTC_Hours =12; 
RTC_AlarmStructure.RTC_AlarmTime.RTC_Minutes =0; 
RTC_AlarmStructure.RTC_AlarmTime.RTC_Seconds = 0; 
RTC_AlarmStructure.RTC_AlarmDateWeekDay = 1; 
RTC_AlarmStructure.RTC_AlarmDateWeekDaySel = RTC_AlarmDateWeekDaySel_Date; 
RTC_AlarmStructure.RTC_AlarmMask = RTC_AlarmMask_DateWeekDay; 
RTC_SetAlarm(RTC_Format_BIN, RTC_Alarm_A, &RTC_AlarmStructure); 
/* Enable RTC Alarm A Interrupt: this Interrupt will wake-up the system from 
STANDBY mode (RTC Alarm IT not enabled in NVIC) */ 
RTC_ITConfig(RTC_IT_ALRA, ENABLE); 
/* Enable the Alarm A */ 
RTC_AlarmCmd(RTC_Alarm_A, ENABLE); 
/* Clear RTC Alarm Flag */ 
RTC_ClearFlag(RTC_FLAG_ALRAF); 
//----------------------------------------------- 
for(i=0;i<0xffffff;i++); 
PWR_WakeUpPinCmd(ENABLE); 
/* Request to enter STANDBY mode (Wake Up flag is cleared in PWR_EnterSTANDBYMode function) */ 
PWR_EnterSTANDBYMode();

here the start of my code :

RTC_AlarmCmd(RTC_Alarm_A, DISABLE); 
RTC_ITConfig(RTC_IT_ALRA, DISABLE); 
if(RTC_GetITStatus(RTC_IT_ALRA)==1) 
{ 
wake_flag=1; 
RTC_ClearFlag(RTC_FLAG_ALRAF); 
} 
else 
{ 
wake_flag=0; 
}

The second problem that i could not find its solution is :

#define r77 0f 
#define r78 0f 
#define rtotal r77+r78 
#define vref 3.0f 
unsigned short temp; 
float volt,vbat; 
temp=read_battery();//adc 
volt= (float)temp * vref; 
volt= volt/4094; 
vbat = (rtotal* volt); 

rtotal must be 85 but it get very diffirent valuels for debug i used a float RR=rtotal i can see very diffirent value here ..diffirent from what is wrong here ? Thank you in advanced Esat
4 REPLIES 4
Posted on April 29, 2013 at 04:11

STANDBY exits via a RESET, the start up code, and the RTC initialization code need special handling. You need to provide a more clear and concise example, rather than random code fragments. Why is there an odd timing delay there?

Again, absent some clear test case values and examples, I'm not sure what the issue is with the second case you presented. I'd probably use 4096.0f for the divisor given the 0..4095 range of the 12-bit value.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
sami
Associate II
Posted on April 29, 2013 at 11:21

Thank you Clive for your help as usual .

My project use same button PA0 to enter standbymode and to wake up from same mode. that delay is just to insure that there is nothing to do after entering the standby mode .

The ode that i post the just the reoutine that is called before entering standby mode  to set up the alarm .

the alarm sometimes doesnot work , i still dont know why ..

the scond part of teh code is the first thing i check in the main after reset .

So what should I change in the startup.s?

Amel NASRI
ST Employee
Posted on April 29, 2013 at 16:51

Hello Esat,

If you are in the same conditions as stated in this [DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Leaving%20Standby%20by%20WakeUp%20pin%20and%20RTC%20Alarm&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=497]thread, you have to apply the workaround described by STOne-32 to leave standby mode using RTC alarm.

Regards,

ST.MCU

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

sami
Associate II
Posted on April 30, 2013 at 09:32

Thank you St.MCU

I wıill check that .