Sleep and Low Power Modes

The first thing you need to know about power saving and sleep modes is that shorting Pin B12 to VCC will erase the flash content. This is important because if the SAM4S MCU is stuck in sleep mode and there is no code to wake it up then there is no way to reporgram it via the JTAG connector.

Before we put the SAM4S in a low power mode or sleep we need to configure a way to wake it up, otherwise it will be stuck in low power mode.

There are 3 low-power modes: backup mode, wait mode and sleep mode.

ModeDescriptionWake Up SourcesEnter Low Power Mode
Backup ModeUsed for a system that has periodic wake-ups to perform tasks but not requiring fast startup times. 1uA typical (VDDIO=1.8V, 25C)WKUP0-15, Supply Monitor, RT or RTCSet VROFF bit in the SUPC_CR Register
Wait ModeUsed to lower power usage for a system that remains powered with a startup time less than 10us. 32uA typical (VDDIO=1.8V, 25C)WKUP0-15, RTC, RTT, USB
  • Selet 4/8/12 MHz fast RC osc as main clock
  • set FLPM bit in PMC_FSMR
  • Set Flash wait state to 0
  • Set WAITMODE bit in CKGR_MOR Register
Sleep ModeSleep mode is used to optimize power consumption of the device instead of startup time.WKUP0-15, RTC, RTT, USB


// 18.4.3 turn off voltage regulator write 1 to the VROFF bit in REG_SUPC_CR and 
void goSleep (void){
	/*disable stuff that may interfere with sleep mode */
	//REG_SUPC_MR |= SUPC_MR_BODDIS_DISABLE; //disable brownout detector
	REG_WDT_MR |= WDT_MR_WDDIS; //disable watchdog
	/* Setup Alarms */
	//set RTT alarm for 1 mintue later
	REG_SUPC_WUMR |= SUPC_WUMR_RTTEN; //enable RTT alarm		
	//REG_SUPC_WUMR |= SUPC_WUMR_LPDBCEN0; //set low power debouncer enable wkup0 for button input
	REG_SUPC_WUMR |= SUPC_WUMR_WKUPDBC_32_SCLK; //wkup0 debounce 32 clock cycles
	//these both need configuring in their respective places
	/* CHeck that all things are finished writing */
	//uart getting cut off
	/* Turn off power and sleep until alarm */
	REG_SUPC_CR |= (SUSC_KEY<<24)|SUPC_CR_VROFF; //turn voltage regulator off	
	//SCB_SCR_SLEEPDEEP_Msk; //sleep in deep sleep not regular sleep