STM32L152 Timer10/11 - Compare capture interrupt
Hi,
I want to use TIM10 or 11 for generating the interrupt when the counter CNT reaches the value stored in CCR1 register (capture/compare). I want NO output to be generated on output pins. I also want run from internal clock.
My problem? - no interrupt occurs even the CNT value is higher than CCR1 value.
My TIM init:
/* TIM11 init function */
void MX_TIM11_Init(void){ TIM_ClockConfigTypeDef sClockSourceConfig; TIM_OC_InitTypeDef sConfigOC;htim11.Instance = TIM11;
htim11.Init.Prescaler = 2097; // run from 2,097 Mhz - so now 1 tick = 1 ms htim11.Init.CounterMode = TIM_COUNTERMODE_UP; htim11.Init.Period = 65535; htim11.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;if (HAL_TIM_Base_Init(&htim11) != HAL_OK)
{ _Error_Handler(__FILE__, __LINE__); }sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
if (HAL_TIM_ConfigClockSource(&htim11, &sClockSourceConfig) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); }if (HAL_TIM_OC_Init(&htim11) != HAL_OK)
{ _Error_Handler(__FILE__, __LINE__); }sConfigOC.OCMode = TIM_OCMODE_TIMING; //just timing - no output
sConfigOC.Pulse = 1000; //Want interrupt after 1000 cycles sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; sConfigOC.OCFastMode = TIM_OCFAST_DISABLE; if (HAL_TIM_OC_ConfigChannel(&htim11, &sConfigOC, TIM_CHANNEL_1) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); }}
Now I enable the interrupt after Compare match:
LL_TIM_DisableIT_CC1(TIM11);
LL_TIM_ClearFlag_CC1(TIM11); //Clear flag Compare interrupt LL_TIM_EnableIT_CC1(TIM11); //Enable Compare interruptNow Clear the counter and start the counter:
LL_TIM_SetCounter(TIM_SERVER,0); //star count from zero
LL_TIM_OC_SetCompareCH1(TIM_SERVER,obj->CompareValue);Finally the callback function from cube...
void TIM11_IRQHandler(void)
{ /* USER CODE BEGIN TIM11_IRQn 0 *//* USER CODE END TIM11_IRQn 0 */
HAL_TIM_IRQHandler(&htim11); /* USER CODE BEGIN TIM11_IRQn 1 *//* USER CODE END TIM11_IRQn 1 */
}But no interrupt is generated, Could you please help me what I do wrong?
Thank you, Jan.
#tim10 #output-compare #compare #stm32l1 #tim11