Hello Ahn Joesph,
1. You can write the enter stop code like this:
void stop (void)
{
/* Set the SLEEPDEEP bit to enable deep sleep mode (STOP) */
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
/* WFI instruction will start entry into STOP mode */
#ifndef KEIL
// If not using KEIL's uVision use the standard assembly command
asm("WFI");
#else
// If using KEIL's uVision, use the CMSIS intrinsic
__wfi();
#endif
}
void wait (void)
{
/* Clear the SLEEPDEEP bit to make sure we go into WAIT (sleep) mode instead
* of deep sleep.
*/
SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk;
/* WFI instruction will start entry into WAIT mode */
#ifndef KEIL
// If not using KEIL's uVision use the standard assembly command
asm("WFI");
#else
// If using KEIL's uVision, use the CMSIS intrinsic
__wfi();
#endif
}
2. Don't enter the stop mode in the interrupt.
You can use a flag to indicate the interrupt, then check the flag in the main while(1), if the flag is set, then enter stop mode.
Please try it again on your side.
If you still have problem, please tell me what the IDE you are using, I will check it on my side.
Have a great day,
Kerry
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------