2024-04-09 06:47 AM - edited 2024-04-09 06:48 AM
I have timer 3, that i want to set up for input capture. But when enabling the alternate function. The pullup is not working. Also an external pullup of 10K does not work.
GPIO setup:
// TIM 3 Inputs (Pedal rot - PB5 / Torc PWM - PB1)
my_GPIO_InitStruct.Pin = GPIO_PIN_5 | GPIO_PIN_1;
my_GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
my_GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(GPIOB, &my_GPIO_InitStruct);
GPIOC->AFR[0] |= ( GPIO_AFRL_AFSEL1_1 | // AF2 (all)
GPIO_AFRL_AFSEL5_1);
Timer setup:
__disable_irq();
__HAL_RCC_TIM3_CLK_ENABLE();
SET_BIT( TIM3->CCMR1, TIM_CCMR1_CC2S_0);
SET_BIT( TIM3->CCMR2, TIM_CCMR2_CC4S_0); // channel is configured as input, tim_ic1 is mapped on tim_ti1, etc...
// TODO: filter??
SET_BIT( TIM3->CCER, TIM_CCER_CC2E |
TIM_CCER_CC2NP |
TIM_CCER_CC2P |
TIM_CCER_CC4E |
TIM_CCER_CC4NP |
TIM_CCER_CC4P); // capture enable and Rising and falling edge
// TISEL default input channels
SET_BIT( TIM3->DIER, TIM_DIER_CC2IE | TIM_DIER_CC4IE); // enable interrupt on signal
SET_BIT( TIM3->CR1, TIM_CR1_CEN); // enable counter timer 3
NVIC_EnableIRQ(TIM3_IRQn); // enable global interrupt
SET_BIT(TIM3->EGR, TIM_EGR_CC2G); //force interrupt
__enable_irq();
I already tried to set CC2E/CC4E a step after CC2NP, ... . It did not work.
Solved! Go to Solution.
2024-04-09 06:57 AM
2024-04-09 06:57 AM
Oh my....
GPIOC should be GPIOB !!