Hi Amey,
which sleep modes do you want? The following is the sample code to enter the sleep mode.
#define STOP_MODE 0x0
#define VLPS_MODE 0x2
#define LLS_MODE 0x3
#define VLLSx_MODE 0x4
#define VLLS0_MODE 0x0
#define VLLS1_MODE 0x1
#define VLLS2_MODE 0x2
#define VLLS3_MODE 0x3
#define LOW_PWR_MODE "choose each of VLPS_MODE, LLS_MODE or VLLSx_MODE"
#define LOW_PWR_SMODE "if LOW_PWR_MODE is VLLSx_MODE then choose each of VLLS0_MODE, VLLS1_MODE, VLLS2_MODE or VLLS3_MODE"
void stop (void)
{
/* Set the SLEEPDEEP bit to enable deep sleep mode (STOP) */
SCB_SCR |= SCB_SCR_SLEEPDEEP_MASK;
/* WFI instruction will start entry into STOP mode */
asm("WFI");
}
void STOP_Mode(void)
{
/* Write to PMPROT to allow AVLP/LLS/AVLLS power modes this write-once
bit allows the MCU to enter the AVLP/LLS/AVLLS low power mode*/
SMC_PMPROT = SMC_PMPROT_AVLP_MASK
| SMC_PMPROT_ALLS_MASK
| SMC_PMPROT_AVLLS_MASK;
/* Set the STOPM field to 0b011 for LLS mode */
SMC_PMCTRL &= ~SMC_PMCTRL_STOPM_MASK;
SMC_PMCTRL |= (SMC_PMCTRL_STOPM(LOW_PWR_MODE)|SMC_PMCTRL_LPWUI_MASK);
#if (LOW_PWR_MODE == VLLSx_MODE)
SMC_STOPCTRL &= ~SMC_STOPCTRL_VLLSM_MASK;
SMC_STOPCTRL |= LOW_PWR_SMODE;
#endif
/*wait for write to complete to SMC before stopping core */
while((SMC_PMCTRL & SMC_PMCTRL_STOPM_MASK) != LOW_PWR_MODE);
/* Now execute the stop instruction (deep sleep) to go into LLS */
stop();
}
To exit the sleep mode, you can choose one of
LPTMR (Low Power Timer),
CMP0 (Comparator0),
CMP1 (Comparator1),
CMP2 (Comparator2)
TSI (Touch sense input),
RTC (Real Time Clock) or
external imnterrupts
as the wake-up factor.
Which do you want? According to the wake-up method, the procedure varies.
Best regards,
Yasuhiko Koumoto.