Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How HAL_RTC_SetAlarm_IT works in the example

Status
Not open for further replies.
X

Xenon02

Guest
Newbie level 1
I am stuck with this example :

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 ?
 

Hi,

I see no documentation of your code.
No idea what you want to achieve with each line.

We have no crystsl ball.

If you need help .... you need to provide useful informations first.

Klaus
 

Hi,

I see no documentation of your code.
No idea what you want to achieve with each line.

We have no crystsl ball.

If you need help .... you need to provide useful informations first.

Klaus

The code I've placed is the only code I've added to the main.c in STM32 CubeIDE.
What do you mean by documentation ? If it's the model of nucleo then it is STM32L073RZ.

In the "graphical" part the RTC and it's alarm is set like in the picture :

1698805264163.png


The tutorial I was doing is from STM website : https://wiki.st.com/stm32mcu/wiki/Getting_started_with_RTC.

So I don't know if this is enough information. I was basically asking for HAL_RTC_SetAlarm_IT, how it works in the code from post#1 in the while() condition. In which it says HAL_RTC_SetAlarm_IT(hrtc, &sAlarm, FORMAT_BIN)!=HAL_OK. When I've checked step by step every line of the code using the breakpoint, I've went "inside" of this while condition and HAL_RTC_SetAlarm_IT was already HAL_OK, but it still terminated what was inside of the while() which is toggeling the LED and printing the time.

The question is : Why it terminated what is inside of while (statements) which is toggeling the LED and printing the time when HAL_RTC_SetAlarm_IT returned HAL_OK and the condition of while() says to terminate what is inside of while (statements) when HAL_RTC_SetAlarm_IT returned something else than
HAL_OK.
 
Last edited by a moderator:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top