由于引脚不够用,我想采用复用的方式,将编码模式对应的引脚复用到可用的引脚上。
本次是将TIM2的通道1和2完全复用到PA15和PB3(不复用是A0和A1),但是配置没有成功。
大家帮我看看配置的正不正确吧。
[mw_shl_code=c,true]void MY_CONFIG2_FullRemap(u16 arr,u16 psc)
{
GPIO_InitTypeDef GPIO_InitStructure;
TIM_ICInitTypeDef TIM_ICInitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
/* TIM4 clock source enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
/* Enable GPIOA, clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
GPIO_PinRemapConfig(GPIO_FullRemap_TIM2, ENABLE);//完全复用到A15,B3
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15; //初始化IO口
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; //初始化IO口
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
//TIM2 TIM_DeInit(TIM4);
TIM_TimeBaseStructure.TIM_Period = arr; //一圈共4000个脉冲
TIM_TimeBaseStructure.TIM_Prescaler = psc;
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Down;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
TIM_EncoderInterfaceConfig(TIM2, TIM_EncoderMode_TI12,TIM_ICPolarity_Falling, TIM_ICPolarity_Falling);
TIM_ICStructInit(&TIM_ICInitStructure);
TIM_ICInitStructure.TIM_ICFilter = 0;//ICx_FILTER
TIM_ICInit(TIM2, &TIM_ICInitStructure);
TIM_SetCounter(TIM2, 10000);
TIM_ARRPreloadConfig(TIM2, ENABLE);
TIM_Cmd(TIM2, ENABLE);
TIM_ClearFlag(TIM2, TIM_TS_TI2FP2|TIM_TS_TI2FP2);
TIM_ITConfig(TIM2, TIM_TS_TI2FP2|TIM_TS_TI2FP2, ENABLE);
}
[/mw_shl_code]
一周热门 更多>