Question
Timer22 never reach IRQ
Hi everyone,
It seems that I have a problem with my Timer 22 configuration, on my Microcontroller, STM32L031 I would like to stop it then restart them with a lower speed to go into sleep mode, except that my interrupt is never triggered.
Do you have an idea ?
//-----------------------------------------------------------------------------
void SLEEP_LP(uint16_t time)
//-----------------------------------------------------------------------------
{
HAL_NVIC_DisableIRQ(TIM21_IRQn); //---- Disable other timer IRQ for debug
HAL_NVIC_DisableIRQ(TIM2_IRQn);
RCC->APB2ENR &= ~RCC_APB2ENR_TIM22EN; //--- Disable Clock to reconf tim 22
TIM22->CR1 &= ~TIM_CR1_CEN; //--- Disable count
TIM22->SR = 0x00;
//--- Re Configuration Timer22 ---
RCC->APB2ENR |= RCC_APB2ENR_TIM22EN; //--- Enable Clock Tim22
TIM22->PSC = 65; //--- Prescaler : clock timer = 65536Hz/(prescaler+1) => ~1kHz
TIM22->ARR = time; //--- Auto reload Register
TIM22->DIER |= TIM_DIER_UIE; //--- Enable interrupt
RCC->APB1ENR |= RCC_APB1ENR_PWREN;
RCC->ICSCR &= (~RCC_ICSCR_MSIRANGE); //--- MSI to 65,536kHz
// volatile uint64_t ii = HAL_RCC_GetSysClockFreq();
TIM22->CR1 |= TIM_CR1_CEN; //--- Enable count
PWR->CR |= PWR_CR_LPSDSR; //--- voltage regulator in low-power mode during sleep
SCB->SCR &= ~( SCB_SCR_SLEEPDEEP_Msk ); //--- low-power mode = sleep mode
FLASH->ACR |= FLASH_ACR_SLEEP_PD; //-- Flash OFF
while (end_sleep_flag == FALSE) __WFI(); //--- enter low-power mode
}
//-----------------------------------------------------------------------------
void TIM22_IRQHandler(void)
//-----------------------------------------------------------------------------
{
TIM22->SR = 0; //--- Clear Flag
end_sleep_flag = TRUE;
}
Thanks,
