Question
STM32F4 RTC Alarm problem
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