AnsweredAssumed Answered

timers IC

Question asked by sher.evgeni on Jan 24, 2017
Latest reply on Feb 21, 2017 by waclawek.jan

Why timer IC mode doent work?

 

I've configured everything thround Cube, enabled interups and cant get it to work. Some channels just doent work.

 

__IO uint64_t impData=0;
__IO uint32_t icnt=0;

...

main part

 

 __HAL_RCC_TIM2_CLK_ENABLE();

__HAL_RCC_GPIOA_CLK_ENABLE();
 __HAL_RCC_DMA1_CLK_ENABLE();
 __HAL_RCC_USART1_CLK_ENABLE();


 pin.Pin=GPIO_PIN_2;
 pin.Mode=GPIO_MODE_AF_PP;
 pin.Pull=GPIO_NOPULL;
 pin.Speed=GPIO_SPEED_FREQ_LOW;
 pin.Alternate=GPIO_AF1_TIM2;
 HAL_GPIO_Init(GPIOA,&pin);
 TIM_MasterConfigTypeDef smcfg;
 TIM_IC_InitTypeDef scfgIC;
 timIC.Instance=TIM2;
 timIC.Init.Prescaler=0;
 timIC.Init.CounterMode=TIM_COUNTERMODE_UP;
 timIC.Init.Period=0;
 timIC.Init.ClockDivision=TIM_CLOCKDIVISION_DIV1;
 if(HAL_TIM_IC_Init(&timIC)!=HAL_OK)err('v');
 smcfg.MasterOutputTrigger=TIM_TRGO_RESET;
 smcfg.MasterSlaveMode=TIM_MASTERSLAVEMODE_DISABLE;
 if(HAL_TIMEx_MasterConfigSynchronization(&timIC,&smcfg)!=HAL_OK)err('z');
 scfgIC.ICPolarity=TIM_INPUTCHANNELPOLARITY_RISING;
 scfgIC.ICSelection=TIM_ICSELECTION_DIRECTTI;
 scfgIC.ICPrescaler=TIM_ICPSC_DIV1;
 scfgIC.ICFilter=0;
 if(HAL_TIM_IC_ConfigChannel(&timIC,&scfgIC,TIM_CHANNEL_3)!=HAL_OK)err('x');
 scfgIC.ICSelection=TIM_ICSELECTION_INDIRECTTI;
 if(HAL_TIM_IC_ConfigChannel(&timIC,&scfgIC,TIM_CHANNEL_4)!=HAL_OK)err('y');

 

 HAL_NVIC_SetPriority(DMA1_Channel4_IRQn,1,1); // dma uart T
 HAL_NVIC_EnableIRQ(DMA1_Channel4_IRQn);
 HAL_NVIC_SetPriority(DMA1_Channel5_IRQn,1,1); // dma uart R
 HAL_NVIC_EnableIRQ(DMA1_Channel5_IRQn);
 HAL_NVIC_SetPriority(USART1_IRQn,2,2); // uart interupts
 HAL_NVIC_EnableIRQ(USART1_IRQn);
 HAL_UART_Receive_DMA(&uart,rbuf,4); // uart recieve
 HAL_NVIC_SetPriority(TIM2_IRQn,3,3); // tim IC
 HAL_NVIC_EnableIRQ(TIM2_IRQn);
 HAL_NVIC_SetPriority(TIM3_IRQn,4,4); // ticking for uart
 HAL_NVIC_EnableIRQ(TIM3_IRQn);

 

and interupt itself

 

void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef*timIC)
{if(ready!=SET)return;
 impData+=HAL_TIM_ReadCapturedValue(timIC,TIM_CHANNEL_3);
 icnt++;}

 

uart checkes for values every 0.1 secs.

What am i doing wrong?

 

MCU is STM32F373CC

Outcomes