Question
low power sleep mode in stm32
Hi,
I work with low power sleep mode in stm32 and it is sleep mode works well in our programme.MCU goes sleep mode after 5 seconds and wakup for external interrupt pin to connect for MCU wake up.But I need a output for MCU sleep for 1 min without ADC function and I wakeup the MCU to ADC value to increase to wake the MCU. If any possibilities to use ADC value to wakeup the MCU. If anyone know help for us. I attach my code. This code work well.
#include "main.h"
#include "string.h"
UART_HandleTypeDef huart1;
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_USART1_UART_Init(void);
/* USER CODE BEGIN 0 */
char *str = {0};
uint8_t Rx_data;
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
// HAL_UART_Receive_IT(&huart1, &Rx_data, 1);
// str = "WokeUP from SLEEP by UART\r\n";
// HAL_UART_Transmit(&huart1, (uint8_t *) str, strlen (str), 100);
}
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
// str = "WokeUP from SLEEP by EXTI\r\n";
// HAL_UART_Transmit(&huart1, (uint8_t *) str, strlen (str), 100);
HAL_ResumeTick();
HAL_PWR_DisableSleepOnExit();
}
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USART1_UART_Init();
/* USER CODE BEGIN 2 */
HAL_UART_Receive_IT(&huart1, &Rx_data, 1);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
// str = "Going into Sleep MODE in 5 Seconds\r\n";
// HAL_UART_Transmit(&huart1, (uint8_t *)str, strlen(str), 100);
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, 0);
HAL_Delay(5000);
HAL_SuspendTick();
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, 1); // Just to indicate sleep mode is activated
HAL_PWR_EnableSleepOnExit();
// Enter the sleep MODE NOW....
HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFE); // interrupt for wake up
// HAL_ResumeTick();
// str = "Woke UP from Sleep MODE\r\n";
// HAL_UART_Transmit(&huart1, (uint8_t *)str, strlen(str), 100);
for (int i=0; i<20; i++)
{
HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13);
HAL_Delay(150);
}
}
/* USER CODE END 3 */
}
