本帖最后由 核子霹雳 于 2017-3-13 17:03 编辑
void IR_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_ICInitTypeDef TIM_ICInitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOG,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4,ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOG, &GPIO_InitStructure);
GPIO_SetBits(GPIOG,GPIO_Pin_15);
TIM_TimeBaseStructure.TIM_Period = 10000;
TIM_TimeBaseStructure.TIM_Prescaler =71;
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
TIM_ICInitStructure.TIM_Channel = TIM_Channel_4;
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 = 0x03;
TIM_ICInit(TIM4, &TIM_ICInitStructure);
TIM_Cmd(TIM4,ENABLE );
NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
TIM_ITConfig( TIM4,TIM_IT_Update|TIM_IT_CC4,ENABLE);
}
void TIM4_IRQHandler(void)
{
if(TIM_GetITStatus(TIM4,TIM_IT_CC4)!=RESET)
{
}
TIM_ClearFlag(TIM4,TIM_IT_Update|TIM_IT_CC4);
}
为什么选用通道TIM_Channel_4
一直在这里file:///跳不出来
if(TIM_GetITStatus(TIM4,TIM_IT_CC4)!=RESET){
在里面循环,不出来
}
,如果换成,TIM_ICInitStructure.TIM_Channel ==TIM_Channel_1/2/3 就可以 TIM_Channel_4就是不行,是什么原因?
有没有大神知道,指点一二file:///C:UsersADMINI~1AppDataLocalTempG@YVKCPZR)X}3UKB(_VF`LW.gif
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
恩是的 原子哥 STM32F103ZET6
有哪几种原因会导致CH4 不行呢?
PG15 是没有这个CH4 ? 我看手册也有说不能用CH4啊
STM32F103ZET6 TIM4_CH4 默认是PB9 重映射是PD15 额
一周热门 更多>