2019-06-16 09:58 PM
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?
2019-06-17 09:30 AM
Which chip? L4-series? What should wake it up?
Also clear all pending interrupts before sleep.
2019-06-17 11:47 PM
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.