2025-01-14 07:41 AM
I do have problem to check wake up flag after wake-up from RTC timer or interrupt pin. This is my code block to check flag after wake-up:
void InitiateMode(int timeValue)
{
turnOffPeripherals();
timeValue = getTimeValue(timeValue);
printf("\ngetMilSecBInSecond : %d\ntimeValue : %d\n\n", getMilSecBInSecond(), timeValue);
HAL_SuspendTick();
HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, timeValue, RTC_WAKEUPCLOCK_CK_SPRE_16BITS);
printf("Boot : ");
printf("%d\n", bootCount);
printf("Sleep mode Start\n");
printf("Enable deep sleep, Will wake up in %d seconds\n\n", timeValue);
/* Enter STOP 2 mode */
// HAL_PWREx_EnterSTOP0Mode(PWR_STOPENTRY_WFI);
// HAL_PWREx_EnterSTOP1Mode(PWR_STOPENTRY_WFI);
getTotalTime();
// betol2 sebelom
HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI);
printf(" 2\n");
// Check RTC Wake-Up Timer Flag
if (__HAL_RTC_WAKEUPTIMER_GET_FLAG(&hrtc, RTC_FLAG_WUTF) != RESET)
{
// Wake-up event detected, clear the flag
__HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(&hrtc, RTC_FLAG_WUTF);
// Your code to turn on the LED or perform other actions
printf("Wake-up event detected by RTC timer, clear the flag\n");
}
if(__HAL_GPIO_EXTI_GET_FLAG(GPIO_PIN_7) != RESET)
{
// Wake-up event detected, clear the flag
__HAL_GPIO_EXTI_CLEAR_FLAG(GPIO_PIN_7);
// Your code to turn on the LED or perform other actions
printf("Wake-up event detected by interrupt pin, clear the flag\n");
}
HAL_RTCEx_DeactivateWakeUpTimer(&hrtc);
SystemClock_Config();
// processable start hidup sini
// printf("\nBetol 2 lepas wake up : %d\n", HAL_GetTick());
printf("\nBetol 2 lepas wake up : %lu\n", HAL_GetTick());
HAL_ResumeTick();
getTickTimeStart();
printf("Sleep mode End\n");
printf("Wake Up!!\n");
printf("----------------------------------------------------------------\n\n");
// Increment the bootCount
++bootCount;
printf("Bootcount : %d\n", bootCount);
}
The section:
// Check RTC Wake-Up Timer Flag
if (__HAL_RTC_WAKEUPTIMER_GET_FLAG(&hrtc, RTC_FLAG_WUTF) != RESET)
{
// Wake-up event detected, clear the flag
__HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(&hrtc, RTC_FLAG_WUTF);
// Your code to turn on the LED or perform other actions
printf("Wake-up event detected by RTC timer, clear the flag\n");
}
// Check GPIO 7 interrupt pin Flag
if(__HAL_GPIO_EXTI_GET_FLAG(GPIO_PIN_7) != RESET)
{
// Wake-up event detected, clear the flag
__HAL_GPIO_EXTI_CLEAR_FLAG(GPIO_PIN_7);
// Your code to turn on the LED or perform other actions
printf("Wake-up event detected by interrupt pin, clear the flag\n");
}
I set 10 second timer during STOP2 mode, after that the system wake-up, but when i check the log, no line is printed mean that __HAL_RTC_WAKEUPTIMER_GET_FLAG(&hrtc, RTC_FLAG_WUTF) == RESET or __HAL_GPIO_EXTI_CLEAR_FLAG(GPIO_PIN_7) == RESET, is there any problem in my code? please help me sifu, i am already struck by lighting
2025-01-15 01:09 AM - edited 2025-01-15 01:09 AM
Hello @hlmn7,
Could you check the initial state of flags before entering stop2 mode?
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.
2025-01-15 06:18 AM
Thanks for the reply, I just checked the initial state with the code added in void InitiateMode below:
// Check RTC Wake-Up Timer Flag
if (__HAL_RTC_WAKEUPTIMER_GET_FLAG(&hrtc, RTC_FLAG_WUTF) == SET)
{
// Your code to turn on the LED or perform other actions
printf("Wake-up RTC timer flag is SET\n");
} else {
printf("Wake-up RTC timer flag is RESET\n");
}
// Check GPIO 7 interrupt pin Flag
if (__HAL_GPIO_EXTI_GET_FLAG(GPIO_PIN_7) == SET)
{
// Your code to turn on the LED or perform other actions
printf("Interrupt GPIO_PIN_7 flag is SET\n");
} else {
printf("Interrupt GPIO_PIN_7 flag is RESET\n");
}
the output:
22:12:22:545 -> Total time process : 6119
22:12:22:545 -> Wake-up RTC timer flag is RESET
22:12:22:545 -> Interrupt GPIO_PIN_7 flag is RESET
both are in reset state like I taught on top of the topic, I have no idea what to do next, I really need help on this.
@Sarra.S
2025-01-20 07:33 PM
Hi @Sarra.S, please check my latest reply. Thanks.