X
Xenon02
Guest
I am stuck with this example :
I've checked what HAL_RTC_SetAlarm_IT returns and it is either HAL_OK or HAL_TIMEOUT. The problem I have is when I've been doing step by step debugging, and trying to see what HAL_RTC_SetAlarm_IT returns it lead me to the HAL_OK so HAL_RTC_SetAlarm_IT returned HAL_OK and the while shouldn't be executed but it somehow executed. Can someone explain to me why it executed what is inside of while() even though HAL_OK is equal HAL_OK so the requirements wasn't fulfilled.
Also maybe someone knows, why this method "while(HAL_RTC_SetAlarm_IT(hrtc, &sAlarm, FORMAT_BIN)!=HAL_OK)" is used ? I've seen it in STM32 websites of how to use RTC alarm example. Why HAL_GetTime or HAL_GetDate doesn't need this type of check if they return HAL_OK ?
Code:
void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc) {
z ++;
RTC_AlarmTypeDef sAlarm;
HAL_RTC_GetTime(hrtc, &RTC_TimeStruct, FORMAT_BIN);
HAL_RTC_GetDate(hrtc, &RTC_DateStruct, FORMAT_BIN);
HAL_RTC_GetAlarm(hrtc,&sAlarm,RTC_ALARM_A,FORMAT_BIN);
if(sAlarm.AlarmTime.Seconds>54) {
sAlarm.AlarmTime.Seconds=0;
}else{
sAlarm.AlarmTime.Seconds=sAlarm.AlarmTime.Seconds+5;
}
while(HAL_RTC_SetAlarm_IT(hrtc, &sAlarm, FORMAT_BIN)!=HAL_OK){}
HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);
if (z == 2)
{
printf("y =%d\n", RTC_TimeStruct.Minutes);
printf("x =%d\n", RTC_TimeStruct.Seconds);
z = 0;
}
}
I've checked what HAL_RTC_SetAlarm_IT returns and it is either HAL_OK or HAL_TIMEOUT. The problem I have is when I've been doing step by step debugging, and trying to see what HAL_RTC_SetAlarm_IT returns it lead me to the HAL_OK so HAL_RTC_SetAlarm_IT returned HAL_OK and the while shouldn't be executed but it somehow executed. Can someone explain to me why it executed what is inside of while() even though HAL_OK is equal HAL_OK so the requirements wasn't fulfilled.
Also maybe someone knows, why this method "while(HAL_RTC_SetAlarm_IT(hrtc, &sAlarm, FORMAT_BIN)!=HAL_OK)" is used ? I've seen it in STM32 websites of how to use RTC alarm example. Why HAL_GetTime or HAL_GetDate doesn't need this type of check if they return HAL_OK ?