新手上路
- 积分
- 27
- 金钱
- 27
- 注册时间
- 2022-8-22
- 在线时间
- 6 小时
|
5金钱
想将STM32F103RE的PB1复用 为TIM3-CH4,作为计时器输入捕获,下面的配置进不了计时更新中断和捕获中断,请大佬帮看看问题出在哪呢?
void P_INIT(void)
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//设置系统中断优先级分组2
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_ICInitTypeDef TIM_ICInitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);//TIM3时钟使能
//端口初始化,输入端口
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //复用浮空
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);//初始化
GPIO_SetBits(GPIOB,GPIO_Pin_1);
TIM_TimeBaseStructure.TIM_Period=(10000-1); //设定计数器自动重装值 最大10ms溢出
TIM_TimeBaseStructure.TIM_Prescaler=(72-1); //预分频器,1M的计数频率,1us加1.
TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1; //
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up; //向上计数模式
TIM_TimeBaseInit(TIM3,&TIM_TimeBaseStructure);
//初始化TIM3输入捕获参数
TIM_ICInitStructure.TIM_Channel = TIM_Channel_4; //选择输入端 IC4映射到TI4上
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising; //上升沿捕获,下降沿捕获
TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; //映射到TI4上(直通)
TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; //配置输入分频,不分频
TIM_ICInitStructure.TIM_ICFilter = 0x03; // 8个定时器时钟周期滤波
TIM_ICInit(TIM3, &TIM_ICInitStructure); //初始化定时器3输入捕获通道
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; //TIM3捕获中断
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=2;//抢占优先级0
NVIC_InitStructure.NVIC_IRQChannelSubPriority =2; //子优先级0
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
NVIC_Init(&NVIC_InitStructure); //初始化NVIC寄存器
TIM_ITConfig(TIM3,TIM_IT_Update|TIM_IT_CC4,ENABLE);//允许更新中断,允许CC4IE捕获中断
TIM_Cmd(TIM3,ENABLE ); //使能定时器3
}
|
|