cancel
Showing results for 
Search instead for 
Did you mean: 

low power sleep mode in stm32

mrsmile
Associate III

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 */
}
3 REPLIES 3
Diane POMABIA
ST Employee

Hello @mrsmile 

Can you precised the STM32 that is used?

Regards

Diane

mrsmile
Associate III

Hi Diane,

your reply I can't understand pls tell about clearly

I think @Diane POMABIA was asking which stm32 processor you’re using. Different families have different limitations. What are you experimenting with? Just saying e.g. stm32L4xx (if you haven’t finally decided on a particular one) will direct answers to that family.

A way it might work is to leave the real-time clock RTC running while the processor core is sleeping, and have RTC trigger a wakeup interrupt. Your code would have to use the respond to that interrupt by e.g. reading the ADC and deciding whether to go back to sleep.

Some stm32 families have ADCs that can wake the processor if the input exceeds a threshold. Although I remember reading this in a Reference Manual for a particular stm32, I’ve never used that feature and I don’t know the restrictions.

Do read the Reference Manual for your stm32. It describes all the features ST added to the Arm processor core.