AnsweredAssumed Answered

5 minute Timer (LPTIM1) STM32L073

Question asked by Simon NOWAK on Mar 30, 2018
Latest reply on Mar 30, 2018 by dhenry

Hi everyone, 

 

I would like to use LPTIM1 on my STM32L0 to make it wake up (the micro is in Stop Mode) after 5 minutes but I don't know what is the best configuration to do that. Currently I have the configuration below.

 

 

#include "Lib_Timer.h"

/* USER CODE BEGIN 0 */

/* USER CODE END 0 */

LPTIM_HandleTypeDef lptimHandle;
uint32_t cptCallBack = 0;

 

/* LPTIM1 init function */
void MX_LPTIM1_Init(void)
{

lptimHandle.Instance = LPTIM1;
lptimHandle.Init.Clock.Source = LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC;
lptimHandle.Init.Clock.Prescaler = LPTIM_PRESCALER_DIV128;
lptimHandle.Init.Trigger.Source = LPTIM_TRIGSOURCE_SOFTWARE;
lptimHandle.Init.OutputPolarity = LPTIM_OUTPUTPOLARITY_HIGH;
lptimHandle.Init.UpdateMode = LPTIM_UPDATE_IMMEDIATE;
lptimHandle.Init.CounterSource = LPTIM_COUNTERSOURCE_INTERNAL;
if (HAL_LPTIM_Init(&lptimHandle) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}

}

 

void HAL_LPTIM_MspInit(LPTIM_HandleTypeDef* lptimHandle)
{

if(lptimHandle->Instance==LPTIM1)
{
      /* USER CODE BEGIN LPTIM1_MspInit 0 */

      /* USER CODE END LPTIM1_MspInit 0 */
      /* LPTIM1 clock enable */
      __HAL_RCC_LPTIM1_CLK_ENABLE();

      /* LPTIM1 interrupt Init */
      HAL_NVIC_SetPriority(LPTIM1_IRQn, 0, 0);
      HAL_NVIC_EnableIRQ(LPTIM1_IRQn);
      /* USER CODE BEGIN LPTIM1_MspInit 1 */

      /* USER CODE END LPTIM1_MspInit 1 */
}

}

 

void HAL_LPTIM_MspDeInit(LPTIM_HandleTypeDef* lptimHandle)
{

if(lptimHandle->Instance==LPTIM1)
{
      /* USER CODE BEGIN LPTIM1_MspDeInit 0 */

      /* USER CODE END LPTIM1_MspDeInit 0 */
      /* Peripheral clock disable */
      __HAL_RCC_LPTIM1_CLK_DISABLE();

      /* LPTIM1 interrupt Deinit */
      HAL_NVIC_DisableIRQ(LPTIM1_IRQn);
      /* USER CODE BEGIN LPTIM1_MspDeInit 1 */

      /* USER CODE END LPTIM1_MspDeInit 1 */
}

}

 

void Start_Counter(uint32_t period){
      HAL_LPTIM_TimeOut_Start_IT(&lptimHandle, period, 0x0F);
}

 

void Stop_Counter( void ){
      HAL_LPTIM_Counter_Stop_IT(&lptimHandle);
}

 

uint32_t Read_Counter( void ){
      return HAL_LPTIM_ReadCounter(&lptimHandle);
}

 

void HAL_LPTIM_CompareMatchCallback(LPTIM_HandleTypeDef *hlptim){
      cptCallBack++;
}

 

uint32_t get_cptCallBack( void ){
      return cptCallBack;
}

I don't know if I use the good callback and the good configuration, currently my callback increase my counter each second, it's too fast (when I call "Start_Counter" I put period = 0xFFFFF).
Have you any ideas or advices ?

 

Thank's a lot

 

Regards
Simon

Outcomes