21ic问答首页 - MM32SPIN系统高级定时器输入捕获 没办法进入TIM_CC_IRQH中断
MM32SPIN系统高级定时器输入捕获 没办法进入TIM_CC_IRQH中断
lihubing20232024-06-17
MM32SPIN系统单片机高级定时器输入捕获 没办法进入TIM_CC_IRQH中断void Remote_1(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);//使能GPIOB时钟
GPIO_PinAFConfig(GPIOB, GPIO_PinSource4, GPIO_AF_7);//GPIOB4复用为TIM1
//GPIO
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;//下拉输入
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
}
void Remote_Init(uint16_t period, uint8_t prescaler)
{
TIM_TimeBaseInitTypeDef TIM_StructInit;
TIM_ICInitTypeDef TIM_ICInitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
TIM_TimeBaseStructInit(&TIM_StructInit);
TIM_StructInit.TIM_Period = period;
TIM_StructInit.TIM_Prescaler = prescaler;
TIM_StructInit.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_StructInit.TIM_CounterMode = TIM_CounterMode_Up;
TIM_StructInit.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM1, &TIM_StructInit);
//TIM1输入捕获参数设置
TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;//CC2S=01 选择输入端 IC2映射到TI1上
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;//上升沿捕获
TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;//映射到TI1上
TIM_ICInitStructure.TIM_ICFilter = 0x0;
TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;//配置输入分频,不分频
TIM_ICInit(TIM1, &TIM_ICInitStructure);
TIM_ARRPreloadConfig(TIM1, ENABLE);
TIM_ITConfig(TIM1,TIM_IT_CC2 | TIM_IT_Update, ENABLE);
TIM_CtrlPWMOutputs(TIM1, ENABLE);
TIM_Cmd(TIM1, ENABLE);
}
void Remote_2(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = TIM1_BRK_UP_TRG_COM_IRQn;//定时中断3
NVIC_InitStructure.NVIC_IRQChannelPriority = 1;//中断优先级
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;//使能中断
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = TIM1_CC_IRQn;//定时中断3
NVIC_InitStructure.NVIC_IRQChannelPriority = 0;//中断优先级
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;//使能中断
NVIC_Init(&NVIC_InitStructure);
}
void TIM1_BRK_UP_TRG_COM_IRQHandler(void)
{
if(TIM_GetITStatus(TIM1, TIM_IT_Update) != RESET)//溢出中断
{
LED3_TOGGLE();
TIM_ClearITPendingBit(TIM1, TIM_IT_Update); //清除TIMx更新中断标志
}
}
void TIM1_CC_IRQHandler(void)
{
if(TIM_GetITStatus(TIM1, TIM_IT_CC2) != RESET)//捕获中断
{
LED2_TOGGLE();
TIM_ClearITPendingBit(TIM1, TIM_IT_CC2); //清除TIMx更新中断标志
}
}
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);//使能GPIOB时钟
GPIO_PinAFConfig(GPIOB, GPIO_PinSource4, GPIO_AF_7);//GPIOB4复用为TIM1
//GPIO
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;//下拉输入
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
}
void Remote_Init(uint16_t period, uint8_t prescaler)
{
TIM_TimeBaseInitTypeDef TIM_StructInit;
TIM_ICInitTypeDef TIM_ICInitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
TIM_TimeBaseStructInit(&TIM_StructInit);
TIM_StructInit.TIM_Period = period;
TIM_StructInit.TIM_Prescaler = prescaler;
TIM_StructInit.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_StructInit.TIM_CounterMode = TIM_CounterMode_Up;
TIM_StructInit.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM1, &TIM_StructInit);
//TIM1输入捕获参数设置
TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;//CC2S=01 选择输入端 IC2映射到TI1上
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;//上升沿捕获
TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;//映射到TI1上
TIM_ICInitStructure.TIM_ICFilter = 0x0;
TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;//配置输入分频,不分频
TIM_ICInit(TIM1, &TIM_ICInitStructure);
TIM_ARRPreloadConfig(TIM1, ENABLE);
TIM_ITConfig(TIM1,TIM_IT_CC2 | TIM_IT_Update, ENABLE);
TIM_CtrlPWMOutputs(TIM1, ENABLE);
TIM_Cmd(TIM1, ENABLE);
}
void Remote_2(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = TIM1_BRK_UP_TRG_COM_IRQn;//定时中断3
NVIC_InitStructure.NVIC_IRQChannelPriority = 1;//中断优先级
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;//使能中断
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = TIM1_CC_IRQn;//定时中断3
NVIC_InitStructure.NVIC_IRQChannelPriority = 0;//中断优先级
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;//使能中断
NVIC_Init(&NVIC_InitStructure);
}
void TIM1_BRK_UP_TRG_COM_IRQHandler(void)
{
if(TIM_GetITStatus(TIM1, TIM_IT_Update) != RESET)//溢出中断
{
LED3_TOGGLE();
TIM_ClearITPendingBit(TIM1, TIM_IT_Update); //清除TIMx更新中断标志
}
}
void TIM1_CC_IRQHandler(void)
{
if(TIM_GetITStatus(TIM1, TIM_IT_CC2) != RESET)//捕获中断
{
LED2_TOGGLE();
TIM_ClearITPendingBit(TIM1, TIM_IT_CC2); //清除TIMx更新中断标志
}
}
赞0
评论
2024-06-28
赞0
评论
2024-06-28
赞0
评论
2024-06-18
赞0
评论
2024-06-18
赞0
评论
2024-06-18
赞0
评论
2024-06-18
赞0
评论
2024-06-18
赞0
评论
2024-06-18
您需要登录后才可以回复 登录 | 注册