cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L0 stop mode using low power timer

Ash G
Associate II

I'm trying to stop the processor for 9s and run for 1s using the low power timer. All my attempts have failed and I can't get it to work. Once its running it needs to switch ON the LED, transmit a packet and wait for few seconds for commands from a LoRa radio module. Before it goes to stop mode it needs to switch OFF the LED. I'm using STM32 systemworkbench and CubeMX for development. I would appreciate if someone could give me any help with this.

LPTIM is configured as follows:

Clock source: LSI

Prescaler: DIV16

Update Mode: Immediate

Trigger Source: Software Trigger

Timeout Period = 9s

Compare = (Timeout period*LSI_Frequency/Prescaler )-1

= 20,812

Period = 41,634

Below I have attached a sketch of the code.

void HAL_LPTIM_CompareMatchCallback(LPTIM_HandleTypeDef *hlptim)
{
	/* Timeout was reached */
 
	Sleep_Timeout = 1;
 
}
void Sleep(){
 
//Switch off PWM to turn off LED
 if(!run_once){
          if (HAL_LPTIM_TimeOut_Start_IT(&hlptim1, LPTIM_Period, LPTIM_Timeout) != HAL_OK)
		{
			Error_Handler();
		}
   run_once = 1
 //Transmit sleep message
}
 
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
 
 
	/* ### - 4 - Enter in Stop mode ########################################### */
	HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
 
  if(Sleep_Timeout) {
       //Switch ON LED
 
      //Transmit sleep message
 
     //Wait 1s for incoming commands
  Sleep_Timout = 0
 }
}

0 REPLIES 0