TIM3通道2引脚是PA7却要开启GPIOB通道时钟?
时间:10-02
整理:3721RD
点击:
如题,做了个TIM3作为外部脉冲计数,选定通道二,代码如下:
- void TIM3_External_Clock_CountingMode(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
- // TIM_ICInitTypeDef TIM_ICInitStructure;
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
-
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
- //TIM_DeInit(TIM3);
-
- TIM_TimeBaseStructure.TIM_Period = 0x3AB6
- TIM_TimeBaseStructure.TIM_Prescaler = 0x00;
- TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;
-
-
- TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
- TIM_TimeBaseInit( TIM3, &TIM_TimeBaseStructure); // Time base configuration
-
- TIM_TIxExternalClockConfig(TIM3,TIM_TIxExternalCLK1Source_TI2,TIM_ICPolarity_Rising,7);
- TIM_SetCounter(TIM3, 0);
- TIM_ClearFlag(TIM3,TIM_FLAG_Update);
- TIM_Cmd(TIM3,ENABLE);
- }
TIM2 CH2也是开启GPIOB的时钟,是为什么,是因为我技术文档读的少吗
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); 你为何没有使能GPIOA的时钟,你的GPIOA.7为什么设置为模拟输入?
这就是我的困惑,我这个引脚是TIM3用于对外部脉冲计数的。明明是PA7脚却要开启GPIOB时钟才能运行,我开A时钟的时候计数器不工作了。