Can't get Input Capture mode to work
I want to use input capture mode in my stm32l432kc nucleo-32 board to measure the length of a signal from a sensor of mine. I have set it up the following way:
int main(void) {
// ...
MX_USART2_UART_Init();
MX_TIM16_Init();
HAL_TIM_IC_Start_IT(&htim16, TIM_CHANNEL_1);
}
static void MX_TIM16_Init(void)
{
TIM_IC_InitTypeDef sConfigIC = {0};
htim16.Instance = TIM16;
htim16.Init.Prescaler = 0;
htim16.Init.CounterMode = TIM_COUNTERMODE_UP;
htim16.Init.Period = 8999;
htim16.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim16.Init.RepetitionCounter = 0;
htim16.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
HAL_TIM_IC_Init(&htim16);
sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_FALLING;
sConfigIC.ICSelection = TIM_ICSELECTION_DIRECTTI;
sConfigIC.ICPrescaler = TIM_ICPSC_DIV1;
sConfigIC.ICFilter = 0;
HAL_TIM_IC_ConfigChannel(&htim16, &sConfigIC, TIM_CHANNEL_1);
}
void HAL_TIM_IC_MspInit(TIM_HandleTypeDef* htim_ic)
{
GPIO_InitTypeDef GPIO_InitStruct;
if(htim_ic->Instance == TIM16)
{
__HAL_RCC_TIM16_CLK_ENABLE();
// Init PA6
GPIO_InitStruct.Pin = GPIO_PIN_6;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF14_TIM16;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
}
}
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
{
const char* msg = "Detected!\r\n";
HAL_UART_Transmit(&huart2, (uint8_t*)msg, strlen(msg), HAL_MAX_DELAY);
}
I have used GPIO_AF14_TIM16 in the GPIO configuration, since the datasheet in the manual contained the following table: https://imgur.com/a/BwVqaxh, I'm not 100% sure that it's correct though.
Does someone have an idea on what I'm doing wrong here?
Thanks in advance!
