主要功能是想实现使用EC11旋转编码器控制 LED灯的亮度,尝试移植stm32f103的代码,但是一直没有成功,有大佬能帮忙看下么
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
- RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
-
- GPIO_InitTypeDef GPIO_InitStructure;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
- GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
-
- GPIO_PinAFConfig(GPIOA, GPIO_PinSource6, GPIO_AF_1);
- GPIO_PinAFConfig(GPIOA, GPIO_PinSource7, GPIO_AF_2);
-
- TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
- TIM_TimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
- TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
- TIM_TimeBaseInitStructure.TIM_Period = 65535-1;
- TIM_TimeBaseInitStructure.TIM_Prescaler = 1-1;
- TIM_TimeBaseInitStructure.TIM_RepetitionCounter = 0;
- TIM_TimeBaseInit(TIM3, &TIM_TimeBaseInitStructure);
-
- TIM_ICInitTypeDef TIM_ICInitStructure;
- TIM_ICStructInit(&TIM_ICInitStructure);
- TIM_ICInitStructure.TIM_Channel = TIM_Channel_1;
- TIM_ICInitStructure.TIM_ICFilter = 0xF;
- TIM_ICInit(TIM3, &TIM_ICInitStructure);
-
- TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;
- TIM_ICInitStructure.TIM_ICFilter = 0xF;
- TIM_ICInit(TIM3, &TIM_ICInitStructure);
-
- TIM_EncoderInterfaceConfig(TIM3, TIM_EncoderMode_TI12, TIM_ICPolarity_Rising, TIM_ICPolarity_Rising);
- TIM_Cmd(TIM3, ENABLE);
复制代码
|