我同时配置上升沿触发和下降沿触发,在上升沿的时候启动定时器,在下降沿的时候关闭定时器,求距离,但是目前是上升沿触发进不去中断呀,
代码如下:
/*超声波使能引脚定义*/
#define CHAOSHENGBO_1_H GPIOA->BSRR = GPIO_Pin_11
#define CHAOSHENGBO_1_L GPIOA->BRR = GPIO_Pin_11
#define CHAOSHENGBO_2_H GPIOA->BSRR = GPIO_Pin_12
#define CHAOSHENGBO_2_L GPIOA->BRR = GPIO_Pin_12
#define CHAOSHENGBO_3_H GPIOA->BSRR = GPIO_Pin_13
#define CHAOSHENGBO_3_L GPIOA->BRR = GPIO_Pin_13
#define CHAOSHENGBO1_read_H GPIOC->IDR & GPIO_Pin_2
#define CHAOSHENGBO2_read_H GPIOC->IDR & GPIO_Pin_3
#define CHAOSHENGBO3_read_H GPIOC->IDR & GPIO_Pin_4
/*
********************************************************************************
** 函数名称 : INIT_EXIT(void)
** 函数功能 : 外部中断初始化
** 输 入 : 无
** 输 出 : 无
** 返 回 : 无
********************************************************************************
*/
void INIT_EXIT(void)
{
RCC->APB2ENR |= 0X00000001; // enable clock for Alternate Function
AFIO->EXTICR[0] &= 0xFFFF; // clear used pin
AFIO->EXTICR[0] |= (0xFFFF & 0x2222); // set pin to use
AFIO->EXTICR[1] &= 0xFFFF; // clear used pin
AFIO->EXTICR[1] |= (0xFFFF & 0x0002); // set pin to use
EXTI->IMR |= ((1 << 0) & 0X0000000F); // unmask interrupt
EXTI->EMR |= ((1 << 0) & 0X00000000); // unmask event
EXTI->RTSR |= ((1 << 0) & 0X0000000F); // set rising edge
EXTI->FTSR |= ((1 << 0) & 0X00000000); // set falling edge
EXTI->IMR |= ((1 << 1) & 0X0000000F); // unmask interrupt
EXTI->EMR |= ((1 << 1) & 0X00000000); // unmask event
EXTI->RTSR |= ((1 << 1) & 0X0000000F); // set rising edge
EXTI->FTSR |= ((1 << 1) & 0X00000000); // set falling edge
EXTI->IMR |= ((1 << 2) & 0X0000000F); // unmask interrupt
EXTI->EMR |= ((1 << 2) & 0X00000000); // unmask event
EXTI->RTSR |= ((1 << 2) & 0X0000000F); // set rising edge
EXTI->FTSR |= ((1 << 2) & 0X0000000F); // set falling edge
EXTI->IMR |= ((1 << 3) & 0X0000000F); // unmask interrupt
EXTI->EMR |= ((1 << 3) & 0X00000000); // unmask event
EXTI->RTSR |= ((1 << 3) & 0X0000000F); // set rising edge
EXTI->FTSR |= ((1 << 3) & 0X0000000F); // set falling edge
EXTI->IMR |= ((1 << 4) & 0X0000000F); // unmask interrupt
EXTI->EMR |= ((1 << 4) & 0X00000000); // unmask event
EXTI->RTSR |= ((1 << 4) & 0X0000000F); // set rising edge
EXTI->FTSR |= ((1 << 4) & 0X0000000F); // set falling edge
NVIC->ISER[0] |= (1 << (EXTI0_IRQChannel & 0x1F)); // enable interrupt EXTI 0
NVIC->ISER[0] |= (1 << (EXTI1_IRQChannel & 0x1F)); // enable interrupt EXTI 1
NVIC->ISER[0] |= (1 << (EXTI2_IRQChannel & 0x1F)); // enable interrupt EXTI 2
NVIC->ISER[0] |= (1 << (EXTI3_IRQChannel & 0x1F)); // enable interrupt EXTI 3
NVIC->ISER[0] |= (1 << (EXTI4_IRQChannel & 0x1F)); // enable interrupt EXTI 4
}
/*
********************************************************************************
** 函数名称 : EXTI2_IRQHandler(void)
** 函数功能 : 右轮计数中断
** 输 入 : 无
** 输 出 : 无
** 返 回 : 无
********************************************************************************
*/
void EXTI2_IRQHandler(void)
{
if (EXTI->PR & (1<<2)) { // 是否是外部中断2
if(CHAOSHENGBO1_read_H==1){
//启动定时器
count=0;
TIM3->CNT=0;
TIM_Cmd(TIM3, ENABLE); //开启时钟
}
else{
//关闭定时器
TIM_Cmd(TIM3, DISABLE); //开启时钟
count=TIM3->CNT;
juli=(17/1000)*count;
if(juli<25)
zhangai_qian=1;
else
zhangai_qian=0;
}
EXTI->PR |= (1<<2); // 清除中断标志
}
}
|