基于stm32f103zet6的外部中断学习
扫描二维码
随时随地手机看文章
一、关于中断中的结构体EXTI_InitTypeDef
原型:uint32_t EXTI_InitTypeDef::EXTI_Line
{
uint32_t EXTI_Line
FunctionalState EXTI_LineCmd
EXTIMode_TypeDef EXTI_Mode
EXTITrigger_TypeDef EXTI_Trigger
}含有4个成员
1、Specifies the EXTI lines to be enabled or disabled. This parameter can be any combination of
EXTI_Lines
EXTI_Lines的取值可以是下面的数字
#define EXTI_Line0 ((uint32_t)0x00001)
#define EXTI_Line1 ((uint32_t)0x00002)
#define EXTI_Line10 ((uint32_t)0x00400)
#define EXTI_Line11 ((uint32_t)0x00800)
#define EXTI_Line12 ((uint32_t)0x01000)
#define EXTI_Line13 ((uint32_t)0x02000)
#define EXTI_Line14 ((uint32_t)0x04000)
#define EXTI_Line15 ((uint32_t)0x08000)
#define EXTI_Line16 ((uint32_t)0x10000)
#define EXTI_Line17 ((uint32_t)0x20000)
#define EXTI_Line18 ((uint32_t)0x40000)
#define EXTI_Line19 ((uint32_t)0x80000)
#define EXTI_Line2 ((uint32_t)0x00004)
#define EXTI_Line3 ((uint32_t)0x00008)
#define EXTI_Line4 ((uint32_t)0x00010)
#define EXTI_Line5 ((uint32_t)0x00020)
#define EXTI_Line6 ((uint32_t)0x00040)
#define EXTI_Line7 ((uint32_t)0x00080)
#define EXTI_Line8 ((uint32_t)0x00100)
#define EXTI_Line9 ((uint32_t)0x00200)
#define IS_EXTI_LINE(LINE) ((((LINE) & (uint32_t)0xFFF00000) == 0x00) && ((LINE) != (uint16_t)0x00))
#define IS_GET_EXTI_LINE(LINE)
2、Specifies the new state of the selected EXTI lines. This parameter can be set either
to ENABLE or DISABLE
3、Specifies the mode for the EXTI lines. This parameter can be a value of EXTIMode_TypeDef
EXTIMode_TypeDef的取值有枚举类型
EXTI_Mode_Interrupt //中断模式
EXTI_Mode_Event //事件模式
4、Specifies the trigger signal active edge for the EXTI lines. This parameter can be a value of
EXTIMode_TypeDef
EXTIMode_TypeDef的取值有:
EXTI_Trigger_Rising //上升沿
EXTI_Trigger_Falling //下降沿
EXTI_Trigger_Rising_Falling // 上升下降沿
以上只是配置中断
然后还需要初始化
初始化函数: void EXTI_Init ( EXTI_InitTypeDef * EXTI_InitStruct )
作用 Initializes the EXTI peripheral according to the specified parameters in the EXTI_InitStruct
还有一个很重要的函数
void GPIO_EXTILineConfig(uint8_tGPIO_PortSource,uint8_tGPIO_PinSource
)
这个函数的作用就是用于配置哪个GPIO的哪个管脚用于中断!!!!!!!
二、中断向量配置结构体 NVIC_InitTypeDef
作用: NVIC Init Structure definition.
参数成员:
uint8_t NVIC_IRQChannel
FunctionalState NVIC_IRQChannelCmd
uint8_t NVIC_IRQChannelPreemptionPriority
uint8_t NVIC_IRQChannelSubPriority
1、NVIC_IRQChannel
Specifies the IRQ channel to be enabled or disabled. This parameter can be a value of IRQn_Type
它的取值有
00170 NonMaskableInt_IRQn = -14, /*!< 2 Non Maskable Interrupt */
00171 MemoryManagement_IRQn = -12, /*!< 4 Cortex-M3 Memory Management Interrupt */
00172 BusFault_IRQn = -11, /*!< 5 Cortex-M3 Bus Fault Interrupt */
00173 UsageFault_IRQn = -10, /*!< 6 Cortex-M3 Usage Fault Interrupt */
00174 SVCall_IRQn = -5, /*!< 11 Cortex-M3 SV Call Interrupt */
00175 DebugMonitor_IRQn = -4, /*!< 12 Cortex-M3 Debug Monitor Interrupt */
00176 PendSV_IRQn = -2, /*!< 14 Cortex-M3 Pend SV Interrupt */
00177 SysTick_IRQn = -1, /*!< 15 Cortex-M3 System Tick Interrupt */
00178
00179 /****** STM32 specific Interrupt Numbers *********************************************************/
00180 WWDG_IRQn = 0, /*!< Window WatchDog Interrupt */
00181 PVD_IRQn = 1, /*!< PVD through EXTI Line detection Interrupt */
00182 TAMPER_IRQn = 2, /*!< Tamper Interrupt */
00183 RTC_IRQn = 3, /*!< RTC global Interrupt */
00184 FLASH_IRQn = 4, /*!< FLASH global Interrupt */
00185 RCC_IRQn = 5, /*!< RCC global Interrupt */
00186 EXTI0_IRQn = 6, /*!< EXTI Line0 Interrupt */
00187 EXTI1_IRQn = 7, /*!< EXTI Line1 Interrupt */
00188 EXTI2_IRQn = 8, /*!< EXTI Line2 Interrupt */
00189 EXTI3_IRQn = 9, /*!< EXTI Line3 Interrupt */
00190 EXTI4_IRQn = 10, /*!< EXTI Line4 Interrupt */
00191 DMA1_Channel1_IRQn = 11, /*!< DMA1 Channel 1 global Interrupt */
00192 DMA1_Channel2_IRQn = 12, /*!< DMA1 Channel 2 global Interrupt */
00193 DMA1_Channel3_IRQn = 13, /*!< DMA1 Channel 3 global Interrupt */
00194 DMA1_Channel4_IRQn = 14, /*!< DMA1 Channel 4 global Interrupt */
00195 DMA1_Channel5_IRQn = 15, /*!< DMA1 Channel 5 global Interrupt */
00196 DMA1_Channel6_IRQn = 16, /*!< DMA1 Channel 6 global Interrupt */
00197 DMA1_Channel7_IRQn = 17, /*!< DMA1 Channel 7 global Interrupt
对于我的片子还有
00297 #ifdef STM32F10X_HD
00298 ADC1_2_IRQn = 18, /*!< ADC1 and ADC2 global Interrupt */
00299 USB_HP_CAN1_TX_IRQn = 19, /*!< USB Device High Priority or CAN1 TX Interrupts */
00300 USB_LP_CAN1_RX0_IRQn = 20, /*!< USB Device Low Priority or CAN1 RX0 Interrupts */
00301 CAN1_RX1_IRQn = 21, /*!< CAN1 RX1 Interrupt */
00302 CAN1_SCE_IRQn = 22, /*!< CAN1 SCE Interrupt */
00303 EXTI9_5_IRQn = 23, /*!< External Line[9:5] Interrupts */
00304 TIM1_BRK_IRQn = 24, /*!< TIM1 Break Interrupt */
00305 TIM1_UP_IRQn = 25, /*!< TIM1 Update Interrupt */
00306 TIM1_TRG_COM_IRQn = 26, /*!< TIM1 Trigger and Commutation Interrupt */
00307 TIM1_CC_IRQn = 27, /*!< TIM1 Capture Compare Interrupt */
00308 TIM2_IRQn = 28, /*!< TIM2 global Interrupt */
00309 TIM3_IRQn = 29, /*!< TIM3 global Interrupt */
00310 TIM4_IRQn = 30, /*!< TIM4 global Interrupt */
00311 I2C1_EV_IRQn = 31, /*!< I2C1 Event Interrupt */
00312 I2C1_ER_IRQn = 32, /*!< I2C1 Error Interrupt */
00313 I2C2_EV_IRQn = 33, /*!< I2C2 Event Interrupt */
00314 I2C2_ER_IRQn = 34, /*!< I2C2 Error Interrupt */
00315 SPI1_IRQn = 35, /*!< SPI1 global Interrupt */
00316 SPI2_IRQn = 36, /*!< SPI2 global Interrupt */
00317 USART1_IRQn = 37, /*!< USART1 global Interrupt */
00318 USART2_IRQn = 38, /*!< USART2 global Interrupt */
00319 USART3_IRQn = 39, /*!< USART3 global Interrupt */
00320 EXTI15_10_IRQn = 40, /*!< External Line[15:10] Interrupts */
00321 RTCAlarm_IRQn = 41, /*!< RTC Alarm through EXTI Line Interrupt */
00322 USBWakeUp_IRQn = 42, /*!< USB Device WakeUp from suspend through EXTI Line Interrupt */
00323 TIM8_BRK_IRQn = 43, /*!< TIM8 Break Interrupt */
00324 TIM8_UP_IRQn = 44, /*!< TIM8 Update Interrupt */
00325 TIM8_TRG_COM_IRQn = 45, /*!< TIM8 Trigger and Commutation Interrupt */
00326 TIM8_CC_IRQn = 46, /*!< TIM8 Capture Compare Interrupt */
00327 ADC3_IRQn = 47, /*!< ADC3 global Interrupt */
00328 FSMC_IRQn = 48, /*!< FSMC global Interrupt */
00329 SDIO_IRQn = 49, /*!< SDIO global Interrupt */
00330 TIM5_IRQn = 50, /*!< TIM5 global Interrupt */
00331 SPI3_IRQn = 51, /*!< SPI3 global Interrupt */
00332 UART4_IRQn = 52, /*!< UART4 global Interrupt */
00333 UART5_IRQn = 53, /*!< UART5 global Interrupt */
00334 TIM6_IRQn = 54, /*!< TIM6 global Interrupt */
00335 TIM7_IRQn = 55, /*!< TIM7 global Interrupt */
00336 DMA2_Channel1_IRQn = 56, /*!< DMA2 Channel 1 global Interrupt */
00337 DMA2_Channel2_IRQn = 57, /*!< DMA2 Channel 2 global Interrupt */
00338 DMA2_Channel3_IRQn = 58, /*!< DMA2 Channel 3 global Interrupt */
00339 DMA2_Channel4_5_IRQn = 59 /*!< DMA2 Channel 4 and Channel 5 global Interrupt */
00340 #endif /* STM32F10X_HD */
2、第二个参数NVIC_IRQChannelCmd
作用:Specifies whether the IRQ channel defined in NVIC_IRQChannel will be enabled or disabled.
This parameter can be set either to ENABLE or DISABLE
3、第三个参数 IRQChannelPreemptionPriority
Specifies the pre-emption priority for the IRQ channel specified in NVIC_IRQChannel.
This parameter can be a value between 0 and 15
4、第四个参数 uint8_t NVIC_IRQChannelSubPriority
Specifies the pre-emption priority for the IRQ channel specified in NVIC_IRQChannel.
This parameter can be a value between 0 and 15