AnsweredAssumed Answered

STM32L476 input capture

Question asked by CONSTANT.Jonathan on Jul 13, 2016
Latest reply on Jul 18, 2016 by CONSTANT.Jonathan
Hello,

I am working with the board Nucleo-L476RG and I want to capture frequency on the pin PA0 with TIM2 Channel1. My timer is working but I can't get the interrupt in the function TIM2_IRQHandler(). I am probably doing something wrong but I can't find example with this board. Here is my code :
#include "mbed.h"
 
TIM_HandleTypeDef  timerStruct;
TIM_IC_InitTypeDef counterStruct;
 
void TIM2_Configuration(void);
 
void TIM2_Configuration()
{
    __HAL_RCC_TIM2_CLK_ENABLE();
    __HAL_RCC_GPIOA_CLK_ENABLE();
     
    // Clock source
    TIM_ClockConfigTypeDef sClockSourceConfig;
    sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
    HAL_TIM_ConfigClockSource(&timerStruct, &sClockSourceConfig);
 
    // GPIO
    GPIO_InitTypeDef GPIO_InitStruct;
    GPIO_InitStruct.Pin = GPIO_PIN_0;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
    GPIO_InitStruct.Alternate = GPIO_AF1_TIM2;
    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
     
    // Interrupt enable
    HAL_NVIC_SetPriority(TIM2_IRQn, 0, 1);
    HAL_NVIC_EnableIRQ(TIM2_IRQn);
 
    /* Input Capture Init */
    timerStruct.Instance = TIM2;
    timerStruct.Init.Period = 0xffff;
    timerStruct.Init.CounterMode = TIM_COUNTERMODE_UP;
    timerStruct.Init.Prescaler = 0;
    timerStruct.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
    HAL_TIM_IC_Init(&timerStruct);
         
    /* Config Channel */
    counterStruct.ICFilter = 0;
    counterStruct.ICPolarity = TIM_ICPOLARITY_RISING;
    counterStruct.ICPrescaler = TIM_ICPSC_DIV1;
    counterStruct.ICSelection = TIM_ICSELECTION_DIRECTTI;
    HAL_TIM_IC_ConfigChannel(&timerStruct, &counterStruct, TIM_CHANNEL_1);
}
 
 
 
int main(void)
{
    TIM2_Configuration();    
 
    HAL_TIM_IC_Start_IT(&timerStruct, TIM_CHANNEL_1);
  
    printf("Timer configured \r\n");
 
    while(1)
    {
    }
}
 
 
/* IRQ */
void TIM2_IRQHandler(void)
{
   printf("IRQ");
}

Thanks for your help.
Best Regards,
Jonathan
 

Outcomes