Example #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();
}
Example #2
0
int main(void) {
	uint8_t i;
	
	/* Initialize system */
	SystemInit();
	
	/* Initialize delay */
	TM_DELAY_Init();
	
	/* Initialize LEDS */
	TM_DISCO_LedInit();
	
	/* 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);
	
	/* Set time to 0 */
	TM_DELAY_SetTime(0);
	
	while (1) {
		/* Toggle LEDs every 200ms */
		if (TM_DELAY_Time() >= 200000) {
			/* Reset time */
			TM_DELAY_SetTime(0);
			
			/* Toggle leds */
			TM_DISCO_LedToggle(LED_GREEN);
			
			/* Increase counter */
			i++;
			
			/* After 20 toggles, put STM32F4 into sleep mode */
			if (i == 20) {
				/* Reset counter */
				i = 0;
				
				/* Sleep until interrupt occur */
				/* Also disable systick with "1" as parameter */
				/* Because systick makes interrupts and it will wakeup */
				/* device back after some ticks. This is useless */
				
				/* If you set parameter to "0", then this function will not */
				/* affect to Systick timer */
				TM_LOWPOWER_SleepUntilInterrupt(1);
				
				/* Toggle RED LED to indicate wakeup from sleep mode */
				TM_DISCO_LedToggle(LED_RED);
			}
		}
	}
}
Example #3
0
int main(void) {
	uint8_t i;
	
	/* Initialize system */
	SystemInit();
	
	/* Initialize delay */
	TM_DELAY_Init();
	
	/* Initialize LEDS */
	TM_DISCO_LedInit();
	
	/* 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);
	
	/* 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 STOP mode */
			if (i == 20) {
				/* Reset counter */
				i = 0;
				
				/* Stop STM32F4 */
				/* If you stop device, then you can wake him up with interrupt/event on EXTI line */
				
				/* Put it into STOP mode, allowing EXTI interrupts to wake him up */
				/* RTC will wake him up after 10 seconds */
				TM_LOWPOWER_StopUntilInterrupt();
				
				/* Toggle RED LED to indicate wakeup from stop mode */
				TM_DISCO_LedToggle(LED_RED);
			}
		}
	}
}
Example #4
0
int main(void) {	
	/* Initialize system */
	SystemInit();
	
	/* Initialize delay */
	TM_DELAY_Init();
	
	/* Initiaize button */
	TM_DISCO_ButtonInit();
	
	/* Initialize Leds */
	TM_DISCO_LedInit();
	
	/* Initialize USART, TX: PB10, RX: PB11 */
	TM_USART_Init(USART3, TM_USART_PinsPack_1, 115200);
	
	/* Initialize RTC with internal 32768Hz clock */
	/* It's not very accurate */
	if (!TM_RTC_Init(TM_RTC_ClockSource_Internal)) {
		/* RTC was first time initialized */
		/* Do your stuff here */
		/* eg. set default time */
	}
	
	/* Set wakeup interrupt every 125 ms */
	TM_RTC_Interrupts(TM_RTC_Int_125ms);
	
	while (1) {
		/* If button pressed */
		if (TM_DISCO_ButtonPressed()) {
			
			/* Subseconds are ignored when writing new time */
			
			datatime.hours = 0;
			datatime.minutes = 59;
			datatime.seconds = 55;
			datatime.year = 14;
			datatime.month = 6;
			datatime.date = 30;
			datatime.day = 6;
			
			/* Set new time */
			TM_RTC_SetDateTime(&datatime, TM_RTC_Format_BIN);
		}
	}
}
Example #5
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);
			}
		}
	}
}
Example #6
0
int main(void) {	
	/* Initialize system */
	SystemInit();
	
	/* Initialize delay */
	TM_DELAY_Init();
	
	/* Initiaize button */
	TM_DISCO_ButtonInit();
	
	/* Initialize Leds */
	TM_DISCO_LedInit();
	
	/* Initialize USART, TX: PB10, RX: PB11 */
	TM_USART_Init(USART3, TM_USART_PinsPack_1, 115200);
	
	/* Initialize RTC with internal 32768Hz clock */
	/* It's not very accurate */
	if (!TM_RTC_Init(TM_RTC_ClockSource_Internal)) {
		/* RTC was first time initialized */
		/* Do your stuff here */
		/* eg. set default time */
	}
	
	/* Set wakeup interrupt every 1 second */
	TM_RTC_Interrupts(TM_RTC_Int_1s);
	
	while (1) {
		/* If button pressed */
		if (TM_DISCO_ButtonPressed()) {
			
			/* Set new time */
			Time.hours = 21;
			Time.minutes = 11;
			Time.seconds = 00;
			Time.year = 14;
			Time.month = 10;
			Time.date = 20;
			Time.day = 1;
			
			/* Set new RTC time */
			TM_RTC_SetDateTime(&Time, TM_RTC_Format_BIN);
			
			/* Set alarm A each day 1 (Monday) in a week */
			/* Alarm will be first triggered 5 seconds later as time is configured for RTC */
			AlarmTime.hours = Time.hours;
			AlarmTime.minutes = Time.minutes;
			AlarmTime.seconds = Time.seconds + 5;
			AlarmTime.alarmtype = TM_RTC_AlarmType_DayInWeek;
			AlarmTime.day = 1;
			
			/* Set RTC alarm A, time in binary format */
			TM_RTC_SetAlarm(TM_RTC_Alarm_A, &AlarmTime, TM_RTC_Format_BIN);
			
			/* Set alarm B each 20th day in a month */
			/* Alarm will be first triggered 10 seconds later as time is configured for RTC */
			AlarmTime.hours = Time.hours;
			AlarmTime.minutes = Time.minutes;
			AlarmTime.seconds = Time.seconds + 10;
			AlarmTime.day = 20;
			AlarmTime.alarmtype = TM_RTC_AlarmType_DayInMonth;
			
			/* Set RTC alarm B, time in binary format */
			TM_RTC_SetAlarm(TM_RTC_Alarm_B, &AlarmTime, TM_RTC_Format_BIN);
		}
	}
}