新手入门
- 积分
- 6
- 金钱
- 6
- 注册时间
- 2017-7-13
- 在线时间
- 0 小时
|
1金钱
折腾了一天了,就是进入不了捕获中断,求教各位,配置函数如下。谢谢各位了。
void TIM3CH1_CAP_Init(u16 pres,u16 cnt)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStruct;
GPIO_InitTypeDef GPIO_InitTypeStruct;
TIM_ICInitTypeDef TIM_ICInitTypeStruct;
NVIC_InitTypeDef NVIC_InitTypeStruct;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
GPIO_InitTypeStruct.GPIO_Pin=GPIO_Pin_6;
GPIO_InitTypeStruct.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitTypeStruct.GPIO_Mode=GPIO_Mode_IPU; //éÏà-êäèë
GPIO_Init(GPIOA, &GPIO_InitTypeStruct);
GPIO_SetBits(GPIOA, GPIO_Pin_6); //Çåáã
TIM_TimeBaseInitStruct.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_TimeBaseInitStruct.TIM_CounterMode=TIM_CounterMode_Up;
TIM_TimeBaseInitStruct.TIM_Period=cnt; //×Ô¶ˉÖØ×°ÔØÖμ
TIM_TimeBaseInitStruct.TIM_Prescaler=pres; //Ô¤·ÖÆμÏμêy
TIM_TimeBaseInit(TIM3,&TIM_TimeBaseInitStruct);
TIM_ICInitTypeStruct.TIM_Channel=TIM_Channel_1;
TIM_ICInitTypeStruct.TIM_ICFilter=0x00;
TIM_ICInitTypeStruct.TIM_ICPolarity=TIM_ICPolarity_Falling; //ϽμÑØ′¥·¢
TIM_ICInitTypeStruct.TIM_ICPrescaler=TIM_ICPSC_DIV1;
TIM_ICInitTypeStruct.TIM_ICSelection=TIM_ICSelection_DirectTI;
TIM_ICInit(TIM3,&TIM_ICInitTypeStruct);
NVIC_InitTypeStruct.NVIC_IRQChannel=TIM3_IRQn;
NVIC_InitTypeStruct.NVIC_IRQChannelCmd=ENABLE;
NVIC_InitTypeStruct.NVIC_IRQChannelPreemptionPriority=0;
NVIC_InitTypeStruct.NVIC_IRQChannelSubPriority=0;
NVIC_Init(&NVIC_InitTypeStruct);
TIM_ITConfig(TIM3,TIM_IT_CC1|TIM_IT_Update,ENABLE);
TIM_Cmd(TIM3, ENABLE);
}
|
|