STM32F103 timer2 input capture
I'm trying to use timer2 ch2 for input capture, but I don't seem to get it to work.
I wonder what am I doing wrong?
I don't use CMSIS or any other libraries.
Here's my set-up:
nvic[NVIC_ICER_0] |= 0x10000000; // disable tim2 IRQ
nvic[NVIC_ICPR_0] |= 0x10000000; // clear tim2 pending tim2[TIM_DIER] &= 0xffffa0a0; // disable timer interrupts tim2[TIM_CCER] = 0x000000000; // disable channels /* switch timer2 ch2 for input capture on falling edge *//* put input capture routine to 'interrupt vector' */
dht_intvec = dht_irq_capt;/* T2 should be PA1 by default */
tim2[TIM_CCMR1] = (tim2[TIM_CCMR1] & 0x00000000) | 0x00000100; // CC2S=T2, OC1M = 000, IC2F = 000 tim2[TIM_CCER] = 0x00000030; // ch2 falling edge, capture enable /* pin PA1 = tmr2_ch2 *//* Input pull-up/down: min. 30kOhm, typ. 40kOhm, max. 50kOhm */
gpioa[GPIO_CRL] = (gpioa[GPIO_CRL] & 0xffffff0f) | 0x00000080; /* PA1 pull-up - line up to end the start pulse */ gpioa[GPIO_ODR] |= 0x00000002;/* enable interrupts */
tim2[TIM_SR] &= 0xffffe1a0; // clear flags tim2[TIM_DIER] = (tim2[TIM_DIER] & 0xffffa0a0) | 4; // CC2IE (enable capture 2 interrupt) nvic[NVIC_ICPR_0] |= 0x10000000; // clear tim2 pending nvic[NVIC_ISER_0] |= 0x10000000; // enable tim2 IRQ (28)The time base runs fine - I've checked by reading the CNT-register, and
output compare seems to work.
#timer2 #input-capture #stm32f103