之前只用过51单片机,编程的时候全是设定寄存器,现在接触STM32发现寄存器太多了,头大了三天。。。之前一直对着103的资料设定407的定时器,但是这哥俩区别真是有的,一开始就进错了门,还想找对人?407输入捕获要把GPIO设定成复用模式,还要做管脚复用的映射,`GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_TIM5); `进入`GPIO_PinAFConfig` 看看注释后才豁然开朗,原来要这么设置AF。
@brief changes the mapping of the specified pin.
@param gpiox:where x can be (A). I) to select the GPIO peripheral.
@param gpio_pinsource:specifies The PIN for the Alternate function.
This parameter can is Gpio_pinsourcex where x can be (0..15).
@param gpio_afselection:selects the pin to used as Alternate function.
This parameter can is one of the following values:
@arg Gpio_af_rtc_50hz:connect rtc_50hz pin to AF0 (default after Reset)
@arg gpio_af_mco:connect MCO Pin (MCO1 and MCO2) to AF0 (default after Reset)
@arg gpio_af_tamper:connect TAMPER pins (tamper_1 and tamper_2) to AF0 (default after Reset)
@arg gpio_af_swj:connect SWJ pins (SWD and JTAG) to AF0 (default after Reset)
@arg gpio_af_trace:connect TRACE pins to AF0 (default after Reset)
@arg gpio_af_tim1:connect TIM1 pins to AF1
@arg gpio_af_tim2:connect TIM2 pins to AF1
@arg gpio_af_tim3:connect TIM3 pins to AF2
@arg gpio_af_tim4:connect TIM4 pins to AF2
@arg gpio_af_tim5:connect TIM5 pins to AF2
By the way, note the configuration entry that captures the input:
=============================================================================== Input Capture Managem ENT functions =============================================================================== =================== ================================================ TIM Driver:how toUseit inchInput Capture Mode =================================================================== to use theTimerinchInput Capture mode, theFollowing steps is mandatory:1.Enable TIM clock using Rcc_apbxperiphclockcmd (RCC_APBXPERIPH_TIMX, ENABLE) function2.Configure theTIM Pins byConfiguring theCorresponding GPIO pins is this step except the wrong, IO port is not configured correctly, should = add multiplexing mapping.2.Configure theTime Base Unit asDescribedinch the FirstPart ofThis driver,ifNeededElse theTimer wouldRun with theDefault configuration:-Autoreload value =0xFFFF-Prescaler value =0x0000-Counter mode = up Counting-clock Division = TIM_CKD_DIV13.Fill theTim_icinitstruct with theDesired parameters including:-TIM channel:tim_channel-tim Input Capture polarity:tim_icpolarity -TIM input capture Selection:tim_icselection-tim input capture prescaler:tim_icprescaler-t IM Input CApture Filter Value:tim_icfilter4.Call Tim_icinit (TIMX, &tim_icinitstruct) toConfigure theDesired Channel with thecorresponding configuration and toMeasure only frequencyorDuty cycle of theInput signal,or, call Tim_pwmiconfig (TIMX, &tim_icinitstruct) toConfigure theDesired channels with thecorresponding configuration and toMeasure theFrequency and theDuty cycle of theInput signal5.Enable theNVICor theDma to Read theMeasured frequency.6.Enable theCorresponding Interrupt (orDMA request) to Read theCaptured value, using thefunction Tim_itconfig (TIMX, TIM_IT_CCX) (orTim_dma_cmd (Timx, TIM_DMA_CCX))7.Pager theTim_cmd (ENABLE) function toEnable theTIM counter.8.Use Tim_getcapturex (TIMX); to Read theCaptured value. Note1:all other functions can used separately toModifyifNeeded, a specific feature of theTimer.
stm32f407 Input Capture-muddying