2014-06-23 08:02 AM
Hi,
I'm using a STM32L151 and would like to connect the pin PA2 to one of the timer capture inputs. According to the reference manual and the example InputCaptureRouting in the STM32L1xx_StdPeriph_Lib_V1.1.1, this code should do the trick:RCC_AHBPeriphClockCmd(RCC_AHBENR_GPIOAEN, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2 | RCC_APB1Periph_COMP | RCC_APB1Periph_PWR, ENABLE); GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_OD; GPIO_InitStructure.GPIO_PuPd = 0; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); &sharpif 1// Route PA2 to TIM2_IC3
GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_RI); SYSCFG_RITIMSelect(TIM_Select_TIM2); SYSCFG_RITIMInputCaptureConfig(RI_InputCapture_IC3, RI_InputCaptureRouting_0/*0: PA2*/); &sharpelse// Use PA2 as TIM2_CH3
GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_TIM2); &sharpendif TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_TimeBaseStructure.TIM_Period = 65535; TIM_TimeBaseStructure.TIM_Prescaler = (uint16_t)(SystemCoreClock/*Hz*/ / 100000/*10us/s*/) - 1; TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); // Use TIM2_IC3 as Input Capture TIM_ICInitTypeDef TIM_ICInitStructure; TIM_ICInitStructure.TIM_Channel = TIM_Channel_3; TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising; TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; TIM_ICInitStructure.TIM_ICFilter = 3; // Filter: 8 clocks TIM_ICInit(TIM2, &TIM_ICInitStructure); TIM_Cmd(TIM2, ENABLE); This should connect the pin PA2 to the Timer Capture Input TIM2_IC3. I would expect that pin PA2 is in a high impedance state in this case, but on a scope it is easy to see that it is driven low by the STM32. If I change the&sharpif 1
in the snippet above to&sharpif 0
, everything works as expected: PA2 is in high impedance state and a rising edge captures TIM2_CNT in register TIM2_CCR3. Actually, I need to use PA10 as a Timer Capture Input which is only possible if it's routed via the RI module. I assumed that (if correctly configured) theTIMx_ICy
signals are equivalent to the accordingTIMx_CHy
signals. Is this correct (the documentation is not 100% clear in this point)? #worst-forum-software-ever #stm32-timer-capture-input2014-07-10 07:44 AM
Hello Thomas,
I encountered the same issue. My line is always set to 0 when I routed TIM4 IC channel 4 to C.11. Also, I don't get any input capture interrupt. I set it in both edge.Did you find something to fix it?Christian2014-07-22 07:09 PM
edit: And another extra post which I can't delete. Turns out the edit button doesn't do what I expected it to either.
2014-07-22 07:11 PM
edit: whoops, double post.
2014-07-23 12:35 AM
Thanks for sharing this info. It's a shame the UM couldn't be clear enough in these important details.
The link you gave needs login; this does not (ugly, but that how this crap of a forum works): [DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/STM32L100%20RI%20for%20TIM%20IC%20routing&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B¤tviews=16]https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2Fcortex_mx_stm32%2FSTM32L100%20RI%20for%20TIM%20IC%20routing&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B¤tviews=16 JW