1

你能帮我在这里告诉我我做错了什么吗?EXTI1 和 EXTI2 不会触发,而 EXTI4 工作正常。这不是硬件。如果我切换引脚,新的 EXTI4 按钮将继续触发,而我切换它的按钮不再触发。

我已经彻底检查了所有段,但我无法弄清楚为什么 EXTI0_1_IRQHandler 不会触发,而 EXTI4_15_IRQHandler 会触发。请参阅下面我用于库的两个文件。我将 SPL 与 OpenSTM32 IDE 一起使用。“main.c”只调用

ENCODER_STM32_configureInterface();

所以真的没有其他事情发生。

// ENCODER_STM32 library: This library shall enable interfacing an encoder on an STM32F0 chip.

// GPIO Definitions
#define    ENCODER_GPIO_PORT       GPIOA
#define    ENCODER_GPIO_CLK_PIN    GPIO_Pin_1
#define    ENCODER_GPIO_DT_PIN     GPIO_Pin_2
#define    ENCODER_GPIO_SW_PIN     GPIO_Pin_4
#define    ENCODER_GPIO_PERIPH     RCC_AHBPeriph_GPIOA

// EXTI Definitions
#define    ENCODER_EXTI_PORTSRC    EXTI_PortSourceGPIOA
#define    ENCODER_EXTI_CLK_PINSRC EXTI_PinSource1
#define    ENCODER_EXTI_CLK_LINE   EXTI_Line1
#define    ENCODER_EXTI_DT_PINSRC  EXTI_PinSource2
#define    ENCODER_EXTI_DT_LINE    EXTI_Line2
#define    ENCODER_EXTI_SW_PINSRC  EXTI_PinSource4
#define    ENCODER_EXTI_SW_LINE    EXTI_Line4
#define    ENCODER_EXTI_PERIPH     RCC_APB2Periph_SYSCFG
#define    ENCODER_EXTI_MODE       EXTI_Mode_Interrupt
#define    ENCODER_EXTI_TRIGGER    EXTI_Trigger_Falling

// NVIC Definitions
#define    ENCODER_NVIC_CLK_CHA    EXTI0_1_IRQn
#define    ENCODER_NVIC_DT_CHA     EXTI2_3_IRQn
#define    ENCODER_NVIC_SW_CHA     EXTI4_15_IRQn
#define    ENCODER_NVIC_PRIORITY   0x03

// Variable Definitions

// Parameter Definitions

// Function Definitions

// Function Declarations
void ENCODER_STM32_configureInterface(void);

和...

#include "stm32f0xx.h"
#include "usart_stm32_console.h"
#include "encoder_stm32.h"

void ENCODER_STM32_configureInterface(void) {

    // Enabling Clocks
    RCC_AHBPeriphClockCmd(ENCODER_GPIO_PERIPH, ENABLE);
    RCC_APB2PeriphClockCmd(ENCODER_EXTI_PERIPH, ENABLE);

    // Configuring GPIO
    GPIO_InitTypeDef GPIO_InitStructure;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
    GPIO_InitStructure.GPIO_Pin = ENCODER_GPIO_CLK_PIN | ENCODER_GPIO_DT_PIN | ENCODER_GPIO_SW_PIN;
    GPIO_Init(ENCODER_GPIO_PORT, &GPIO_InitStructure);

    // Configuring EXTI
    EXTI_InitTypeDef EXTI_InitStructure;
    EXTI_InitStructure.EXTI_Line = ENCODER_EXTI_CLK_LINE | ENCODER_EXTI_DT_LINE | ENCODER_EXTI_SW_LINE;
    EXTI_InitStructure.EXTI_Mode = ENCODER_EXTI_MODE;
    EXTI_InitStructure.EXTI_Trigger = ENCODER_EXTI_TRIGGER;
    EXTI_InitStructure.EXTI_LineCmd = ENABLE;
    SYSCFG_EXTILineConfig(ENCODER_EXTI_PORTSRC, ENCODER_EXTI_CLK_PINSRC);
    SYSCFG_EXTILineConfig(ENCODER_EXTI_PORTSRC, ENCODER_EXTI_DT_PINSRC);
    SYSCFG_EXTILineConfig(ENCODER_EXTI_PORTSRC, ENCODER_EXTI_SW_PINSRC);
    EXTI_Init(&EXTI_InitStructure);

    // Configuring NVIC
    NVIC_InitTypeDef NVIC_InitStructure;
    NVIC_InitStructure.NVIC_IRQChannel = ENCODER_NVIC_CLK_CHA | ENCODER_NVIC_DT_CHA | ENCODER_NVIC_SW_CHA;
    NVIC_InitStructure.NVIC_IRQChannelPriority = ENCODER_NVIC_PRIORITY;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);

}


void EXTI0_1_IRQHandler(void) {

    USART_STM32_sendToUSART("IRQ0_1 triggered");

    if(EXTI_GetITStatus(ENCODER_EXTI_CLK_LINE) != RESET) {
        USART_STM32_sendToUSART("CLK triggered");
        EXTI_ClearITPendingBit(ENCODER_EXTI_CLK_LINE);
    }

}


void EXTI2_3_IRQHandler(void) {

    USART_STM32_sendToUSART("IRQ2_3 triggered");

    if(EXTI_GetITStatus(ENCODER_EXTI_DT_LINE) != RESET) {
        USART_STM32_sendToUSART("DT triggered");
        EXTI_ClearITPendingBit(ENCODER_EXTI_DT_LINE);
    }

}


void EXTI4_15_IRQHandler(void) {

    USART_STM32_sendToUSART("IRQ4_15 triggered");

    if(EXTI_GetITStatus(ENCODER_EXTI_SW_LINE) != RESET) {
        USART_STM32_sendToUSART("SW triggered");
        EXTI_ClearITPendingBit(ENCODER_EXTI_SW_LINE);
    }

}
4

1 回答 1

5

NVIC_Init()一次处理一个中断,因为NVIC_InitStructure.NVIC_IRQChannel它不是位掩码,而是一个简单的标识符。

查看header中IRQ通道的定义:

  EXTI0_1_IRQn                = 5,      /*!< EXTI Line 0 and 1 Interrupts                            */
  EXTI2_3_IRQn                = 6,      /*!< EXTI Line 2 and 3 Interrupts                            */
  EXTI4_15_IRQn               = 7,      /*!< EXTI Line 4 to 15 Interrupts                            */

将它们像掩码位一样组合在一起是没有意义的,但在这种特殊情况下,5|6|7 产生 7,它意外地等于 EXTI4 中断的数量,这就是这个按钮起作用的原因。

只需调用NVIC_Init()三遍:

NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = ENCODER_NVIC_CLK_CHA;
NVIC_InitStructure.NVIC_IRQChannelPriority = ENCODER_NVIC_PRIORITY;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = ENCODER_NVIC_DT_CHA;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = ENCODER_NVIC_SW_CHA;
NVIC_Init(&NVIC_InitStructure);
于 2017-07-17T07:10:58.377 回答