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