示例#1
0
void goSleep(void) {
  TM_RTC_Interrupts(TM_RTC_Int_Disable);
  TM_USART_Puts(MENU_USART,"Going to sleep state now!\n\r");
  USART_DeInit(MENU_USART);
  USART_DeInit(GSM_USART);
  USART_DeInit(GPS_USART);
  I2C_DeInit(I2C3);
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOE, DISABLE);
  TM_RTC_Interrupts(TM_RTC_Int_1s); // 500ms;1,2,5,10,15,30,60 seconds to choose from
  TM_LOWPOWER_Standby();
  //TM_LOWPOWER_StopUntilInterrupt();
  //TM_LOWPOWER_SleepUntilInterrupt(1);
  //TM_LOWPOWER_EnableWakeUpPin();
}
示例#2
0
int main(void) {
	uint8_t i;
	
	/* Initialize system */
	SystemInit();
	
	/* Initialize delay */
	TM_DELAY_Init();
	
	/* Initialize LEDS */
	TM_DISCO_LedInit();
	
	/* Checks if reset was because of wakeup from standby */
	if (TM_LOWPOWER_StandbyReset()) {
		for (i = 0; i < 10; i++) {
			/* Toggle LED red to indicate this */
			TM_DISCO_LedToggle(LED_RED);
			/* Delay */
			Delayms(100);
		}
	}
	
	/* Initialize RTC with internal clock */
	TM_RTC_Init(TM_RTC_ClockSource_Internal);
	
	/* Set RTC to generate wakeup interrupt every 10 seconds */
	TM_RTC_Interrupts(TM_RTC_Int_10s);
	
	/* Enable wakeup pin, PA0 */
	TM_LOWPOWER_EnableWakeUpPin();
	
	/* Set time to 0 */
	TM_DELAY_SetTime(0);
	
	while (1) {
		/* Toggle LEDs every 200ms */
		if (TM_DELAY_Time() >= 200) {
			/* Reset time */
			TM_DELAY_SetTime(0);
			
			/* Toggle leds */
			TM_DISCO_LedToggle(LED_GREEN);
			
			/* Increase counter */
			i++;
			
			/* After 20 toggles, put STM32F4 into STANDBY mode */
			if (i == 20) {
				/* Reset counter */
				i = 0;
				
				
				/* Put STM32F4 into standby mode */
				/* You can wake up MCU with rising edge on PA0 pin */
				/* Or with some special interrupts, like RTC, etc */
				TM_LOWPOWER_Standby();
				
				/* Toggle RED LED to indicate wakeup from STANDBY mode */
				/* This should never happen, because STM32F4 will reset after wakeup from STANDBY */
				TM_DISCO_LedToggle(LED_RED);
			}
		}
	}
}