|
今天配置定时器通道一捕获事件复位并启动计数器,配置如下 TIM_TimeBaseStructInit(&TIM_TimeBaseInitStructure); TIM_TimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV4; TIM_TimeBaseInit(TIM1 , &TIM_TimeBaseInitStructure);% Z$ X: P! M2 T1 ?1 q 2 u7 U- f% M- P7 o/ b TIM_SelectSlaveMode(TIM1, TIM_SlaveMode_Combined_ResetTrigger); : j |9 ?+ t: D& y& c8 q TIM_SelectInputTrigger(TIM1, TIM_TS_TI1FP1); 5 i- m2 @& ^ q! A TIM_ICStructInit(&TIM_ICInitStructure); g, ~- @: R- J2 h% l TIM_ICInit(TIM1, &TIM_ICInitStructure);$ R' t2 r. J$ L, L# k 调试发现寄存器值并不是预期结果,单步调试发现bug在TIM_SelectInputTrigger函数。5 A. R3 _1 x' i1 Z1 h! K
从参考手册查到复位并触发计数器需要把sms设为1000,关键在sms[3]。sms[3]又被TIM_SelectInputTrigger函数清掉了 void TIM_SelectInputTrigger(TIM_TypeDef* TIMx, uint16_t TIM_InputTriggerSource) {. L) H, Q1 ~1 m; C uint16_t tmpsmcr = 0;* L7 m" w# Z, A: |( L3 E0 d B+ A$ H1 Z8 P' N+ x' C' ~, J /* Check the parameters */ assert_param(IS_TIM_LIST2_PERIPH(TIMx)); assert_param(IS_TIM_TRIGGER_SELECTION(TIM_InputTriggerSource)); /* Get the TIMx SMCR register value */4 C8 H+ y) u! k6 x+ ? tmpsmcr = TIMx->SMCR;$ B; M2 _7 N' D+ n+ @' n( x! K* |& ~ /* Reset the TS Bits */ tmpsmcr &= (uint16_t)~TIM_SMCR_TS; : g; F1 R6 L# ^$ i [* E' B" f. j2 C) g /* Set the Input Trigger source */$ [' L( U- h/ C9 C: o tmpsmcr |= TIM_InputTriggerSource; ' W8 {! m0 Z" M8 L9 _9 z /* Write to TIMx SMCR */8 t. f; C/ B1 m: @0 g6 G TIMx->SMCR = tmpsmcr; } / X4 V; T! c: |6 y 解决方法是调换一下函数顺序 / T0 L0 _# G+ s0 N2 s0 Q 又看了一下其他函数也发现了形如 reg=data的语句,像这种直接对寄存器赋值就有可能会出现误操作 |
没啥卵用!!!!因为标准库早就不支持更新了!!!![]() ![]() |
微信公众号
手机版