程序移植到GD32,用的还是ST的外设库,输入捕获一直出问题。其他功能正常。麻烦大家帮看一下。
TIM2初始化
//输入捕获
static void TIM2_Mode_Config(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_ICInitTypeDef TIM_ICInitStructure;
TIM_DeInit(TIM2);
/* Time base configuration */
TIM_TimeBaseStructure.TIM_Period = 0xffff;
//TIM_TimeBaseStructure.TIM_Prescaler = 719;
TIM_TimeBaseStructure.TIM_Prescaler = 287;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
//TIM输入2,3或4选择对应地与IC1或IC2或IC3或IC4相连
TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV4;
//选择输入比较滤波器 0x0 - 0xF
TIM_ICInitStructure.TIM_ICFilter = 0x8; //0x8
TIM_PWMIConfig(TIM2, &TIM_ICInitStructure);
/* Select the TIM3 Input Trigger: TI2FP2 */
TIM_SelectInputTrigger(TIM2, TIM_TS_TI2FP2);
/* Select the slave Mode: Reset Mode */
TIM_SelectSlaveMode(TIM2, TIM_SlaveMode_Reset);
/* Enable the Master/Slave Mode */
TIM_SelectMasterSlaveMode(TIM2, TIM_MasterSlaveMode_Enable);
/* Enable the CC2 Interrupt Request */
TIM_ITConfig(TIM2, TIM_IT_CC2, ENABLE);
/* TIM enable counter */
TIM_Cmd(TIM2, ENABLE);
}
TIM2中断
void TIM2_ISR(void)
{
Uint16 IC2Value;
if (TIM_GetITStatus(TIM2, TIM_IT_CC2) != RESET)
{
TIM_ClearITPendingBit(TIM2, TIM_IT_CC2); //清除中断标志位
IC2Value = TIM_GetCapture2(TIM2);
}
//此处软件清除也没用
//TIM2->SR &= ~0x0404; //软件清除CC2IF和CC2OF标志
}
断点调试的时候,只能进中断一次,IC2Value为0,就再也进不去中断了。
STM32中一切正常。
|