初级会员
- 积分
- 134
- 金钱
- 134
- 注册时间
- 2018-3-26
- 在线时间
- 286 小时
|
10金钱
我用示波器测量了,A+、A-均有规则方波输出,硬件没问题,但是串口没有反应,大家帮我看一下程序
- void Encoder_Init_TIM2(void)
- {
- /*GPIO??,???TIM2-CH1?TIM2-CH2??,????PA0?PA1*/
- TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
- TIM_ICInitTypeDef TIM_ICInitStructure;
- GPIO_InitTypeDef GPIO_InitStructure;
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); //??TIM2
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);//??PA
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1; //PA0 PA1
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //FLOATING
- GPIO_Init(GPIOA, &GPIO_InitStructure); //???
- /*TIM2 ?????*/
- TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
- TIM_TimeBaseStructure.TIM_Prescaler = 0x0; // ?????
- TIM_TimeBaseStructure.TIM_Period = 0xff; //????
- TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; //??????:???
- TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //TIM????
- TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
-
- /*?????*/
- TIM_EncoderInterfaceConfig(TIM2, TIM_EncoderMode_TI12, TIM_ICPolarity_Rising, TIM_ICPolarity_Rising);
- TIM_ICStructInit(&TIM_ICInitStructure);
- TIM_ICInitStructure.TIM_ICFilter = 10;
- TIM_ICInit(TIM2, &TIM_ICInitStructure);
- TIM_ClearFlag(TIM2, TIM_FLAG_Update); //??TIM??????
- TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
- //Reset counter
- TIM_SetCounter(TIM2,0);
- TIM_Cmd(TIM2, ENABLE);
- }
- //????
- int Read_Encoder(u8 TIMX)
- {
- int Encoder_TIM;
- switch(TIMX)
- {
- case 2: Encoder_TIM= (short)TIM2 -> CNT; TIM2 -> CNT=0;break;
- case 3: Encoder_TIM= (short)TIM3 -> CNT; TIM3 -> CNT=0;break;
- case 4: Encoder_TIM= (short)TIM4 -> CNT; TIM4 -> CNT=0;break;
- default: Encoder_TIM=0;
- }
- return Encoder_TIM;
- }
- //??
- void TIM2_IRQHandler(void)
- {
- if(TIM2->SR&0X0001)//????
- {
- }
- TIM2->SR&=~(1<<0);//?????
- }
复制代码- while(1)
- {
-
-
- if(Read_Encoder(2)>=1000) //????10???????
- {
- printf("ffdfd\r\n");;
- }
- }
复制代码 串口没有输出
|
|