Questions about how some HAL protocoles works in RTC
Hello !
I've been practicing how RTC works in STM32 Nucleo and I've used a code from this website tutorials.
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 don't understand how HAL_RTC_SetAlarm_IT in this while().
I've seen that HAL_RTC_SetAlarm_IT returns either a HAL_OK or HAL_TIMEOUT. So I've checked what happens if the code jumps to this while() expression. At the end HAL_RTC_SetAlarm_IT returned HAL_OK so why it does what is inside of this while() instruction ???
I mean that HAL_RTC_SetAlarm_IT returns the HAL_OK and the expression was that HAL_RTC_SetAlarm_IT != HAL_OK but it is HAL_OK so why it does once the instruction inside of while() ??
It doesn't make sense to me. Also why HAL_RTC_SetAlarm_IT must be putted into while with HAL_OK requirement and other HAL like HAL_GetTime or HAL_GetDate doesn't need this verification ???
