cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f407 dma and interrupt ENCODER mode.

MKara.13
Associate

Hi, I'm pretty new to stm32.

My goal is to use HAL_TIM_Encoder_Start() , HAL_TIM_Encoder_Start_DMA(), HAL_TIM_Encoder_Start_IT() commands from Hal library.

I have the stm32f407 Discovery board.

in polling mode

//-------------------------------------------------------------------------------------
HAL_TIM_Encoder_Start(&htim2, TIM_CHANNEL_ALL);
//-------------------------------------------------------------------------------------
  while (1)
  {
 
	  encoder_value=__HAL_TIM_GET_COUNTER(&htim2);
 
  }

in my code like everything works fine.

now i am trying to start it in interrupt mode.

HAL_TIM_Encoder_Start_IT(&htim2, TIM_CHANNEL_ALL);

TIM2_IRQHandler(void)

TIM2_IRQHandler(void)
 
{
 
 HAL_TIM_IRQHandler(&htim2);
 
uint32_t encoder_value=0;
 
 encoder_value=__HAL_TIM_GET_COUNTER(&htim2);
 
}

I know we have to write it inside the function but I couldn't get the values somehow.

Any Help?

2 REPLIES 2

> HAL_TIM_Encoder_Start_IT(&htim2, TIM_CHANNEL_ALL);

Check return value.

Read out and check/post TIM registers content.

Check if you have enabled respective interrupt(s) in NVIC, if the ISR is properly named etc.

JW

Muhammed Güler
Senior III

The timer interrupt is activated in case of overflow. You can try reading with DMA.