Skip to main content
vitthal muddapur
Associate III
June 17, 2019
Question

Enter and Exit Low Power Sleep Mode?

  • June 17, 2019
  • 2 replies
  • 971 views

Hi,

I have configured MCU in Sleep Mode, I have Configured SPI,UART and Some GPIO. and also configured Interrupt RTC. I have Wrote entering Sleep mode like,

main()

{

 MX_GPIO_Init();

 MX_LPUART1_UART_Init();

 MX_SPI1_Init();

while(1)

{

Disable_Pheripheral(void);

Enter_Sleep_Mode(void);

Enable_Pheripheral(void);

//After wakeup do somthing

}

}

void Disable_Pheripheral(void)

{

CLEAR_BIT(LPUART1->CR1,USART_CR1_RXNEIE);

HAL_UART_MspDeInit(&hlpuart1);

CLEAR_BIT(SPI1->CR1,SPI_CR1_SPE);

HAL_SPI_MspDeInit(&hspi1);

GPIO_InitTypeDef GPIO_InitStructure;

GPIO_InitStructure.Pin = GPIO_PIN_2 |GPIO_PIN_3|GPIO_PIN_5 |GPIO_PIN_6 |GPIO_PIN_7;

GPIO_InitStructure.Mode = GPIO_MODE_ANALOG;

GPIO_InitStructure.Pull = GPIO_NOPULL;

HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);

/* Disable GPIOA clock */

__HAL_RCC_GPIOA_CLK_DISABLE();

}

void Enter_Sleep_Mode(void)

{

 __HAL_FLASH_SLEEP_POWERDOWN_ENABLE();

  HAL_SuspendTick();

  /* Enter Sleep Mode , wake up is done once Interrupt Generates */

  HAL_PWR_EnterSLEEPMode(PWR_LOWPOWERREGULATOR_ON, PWR_SLEEPENTRY_WFI);

  /* Resume Tick interrupt if disabled prior to sleep mode entry */

  HAL_ResumeTick();

 __HAL_FLASH_SLEEP_POWERDOWN_DISABLE();

}

void Enable_Pheripheral(void)

{

/* Enable GPIOA clock */

 __HAL_RCC_GPIOA_CLK_ENABLE();

HAL_SPI_MspInit(&hspi1);

SET_BIT(SPI1->CR1,SPI_CR1_SPE);

HAL_UART_MspInit(&hlpuart1);

SET_BIT(LPUART1->CR1,USART_CR1_RXNEIE);

}

This is right way to entering sleep mode?

This topic has been closed for replies.

2 replies

turboscrew
Senior III
June 17, 2019

Which chip? L4-series? What should wake it up?

Also clear all pending interrupts before sleep.

vitthal muddapur
Associate III
June 18, 2019

Hi,

I am using STM32L071 series,

MCU makeup From sleep mode after RTC wakeup and RTC alarm (interrupt), after wakeup Enable Pheripheral

After wakeup will write some data to EEPROM and Send the data to Server after successfull will Disable Pheripheral and again enter to the sleep mode.