External interrupt experiment

External Interrupt 1. Introduction
1.1 EXTI profile
     STM32F10x external interrupt / event controller (the EXTI) containing up to 20 for generating an event / edge detector interrupt request. Each EXTI input lines can be individually configured to select the type (interrupt or event) and the corresponding
     trigger event (rising edge triggered, falling edge, or edge-triggered), it may independently be shielded.
EXTI block diagram 1.2
                                  

 

 

 1.3 External Interrupt / Event line mapping
         STM32F10x of EXTI has 20 interrupt / event line, as follows:
           

 

 

                       

 

2. External Interrupt Configuration steps

To use an external interrupt we need to configure it, usually subject to these steps: (EXTI related library functions in stm32f10x_exti.c and stm32f10x_exti.h file)

   1) the clock enable port IO, IO port configuration mode is the input
(2) open AFIO clock, and the mapping between the IO port disconnected
           RCC_APB2PeriphClockCmd (RCC_APB2Periph_AFIO, the ENABLE);
           void GPIO_EXTILineConfig (uint8_t GPIO_PortSource, uint8_t GPIO_PinSource);
          GPIO_EXTILineConfig ( GPIO_PortSourceGPIOA, GPIO_PinSource0);
(. 3) to configure the interrupt packet (NVIC), enable interrupts

(4) the initialization EXTI, select trigger mode
  

void EXTI_Init (EXTI_InitTypeDef * EXTI_InitStruct); 
typedef struct 
{ 
  uint32_t EXTI_Line;                // interrupt / event line 
  EXTIMode_TypeDef EXTI_Mode;        // the EXTI mode 
  EXTITrigger_TypeDef EXTI_Trigger; // the EXTI trigger 
  FunctionalState EXTI_LineCmd;      // interrupt is enabled or disabled 
} EXTI_InitTypeDef ;

 

(5) the preparation of EXTI interrupt service function

EXTI0_IRQHandler                                                          
EXTI1_IRQHandler                                                           
EXTI2_IRQHandler                                                          
EXTI3_IRQHandler                                                         
EXTI4_IRQHandler 
EXTI9_5_IRQHandler 
EXTI15_10_IRQHandler

3. The hardware circuit

 

 4. Preparation of the external interrupt control program

To achieve an external interrupt to control LED, the following framework:
(1) initializing the corresponding port EXTI
(2) prepared EXTI interrupt function
(3) to write the main function

 

 


        

Guess you like

Origin www.cnblogs.com/DXGG-Bond/p/11831027.html