Principle of Microcomputer Based on ARM Technology 26
Principle of Microcomputer Based on ARM Technology (26) 主讲人:陈桂友
CONTENTS • Objectives • Overview of STM 32 interrupts • Priority of STM 32 interrupts • External interrupt/event controller (EXTI) • Using external interrupts 2 /21
★Objectives: Know the structure of EXTI Grasp how to use the external interrupts 3 /21
External interrupt/event controller (EXTI) Overview The external interrupt/event controller consists of up to 20 edge detectors in connectivity line devices, or 19 edge detectors in other devices for generating event/interrupt requests. Each input line can be independently configured to select the type (pulse or pending) and the corresponding trigger event (rising or falling or both). Each line can also masked independently. A pending register maintains the status line of the interrupt requests. 4 /21
External interrupt/event controller (EXTI) Main features The EXTI controller main features are the following: ● Independent trigger and mask on each interrupt/event line ● Dedicated status bit for each interrupt line ● Generation of up to 20 software event/interrupt requests ● Detection of external signal with pulse width lower than APB 2 clock period. 5 /21
External interrupt/event controller (EXTI) Block diagram 6 /21
External interrupt/event controller (EXTI) External interrupt/event line mapping To configure the AFIO_EXTICRx for the mapping of external interrupt/event lines onto GPIOs, the AFIO clock should first be enabled. In firmware library reference manual, Value of EXTI_Line:P 99 Value of NVIC_IRQChannel:P 166 Other four EXTI lines are connected as follows: ● EXTI line 16 is connected to the PVD output ● EXTI line 17 is connected to the RTC Alarm event ● EXTI line 18 is connected to the USB Wakeup event ● EXTI line 19 is connected to the Ethernet Wakeup event (available only in connectivity line devices) 7 /21
External interrupt/event controller (EXTI) EXTI registers P 211 of reference manual of STM 32 F 10 x 8 /21
Using external interrupt/event Event and interrupt Event: A trigger event occurs. Interrupt: An event occurs and interrupt takes place, then corresponding handling program is executed. Event can trigger an interrupt, and maybe not. Interrupts can be masked by other interrupts with higher priority, whereas events can not be masked. An event is a trigger signal in fact, and is used to trigger specified peripherals or CM 3 core (Wake up). 9 /21
Using external interrupt/event To use external interrupt EXTI lines should be configured and enabled firstly to produce an interrupt. Configure the two trigger selection registers according to the edge detection requirement. Write ‘ 1’ to corresponding bit of Interrupt mask register to enable the interrupt request. When the edge occurs on EXTI line, interrupt request will be produced, and the corresponding pending bit is set to ‘ 1’. If write ‘ 1’ to the pending bit, the interrupt request will be cleared. This is often done in interrupt handling function to clear the interrupt request. 10 /21
Using external interrupt/event To use event Event lines should be configured and enabled firstly to produce an event. Configure the two trigger selection registers according to the edge detection requirement. Write ‘ 1’ to corresponding bit of Event mask register to enable the event request. When an edge occures on event line, an event request pulse will be produced, and the corresponding pending bit is NOT set to ‘ 1’. Writing a 1 to corresponding bit in Software interrupt event register when it is at 0 sets the corresponding pending bit in EXTI_PR. If the interrupt is enabled on this line on the EXTI_IMR and EXTI_EMR, an interrupt request is generated. This bit is cleared by clearing the corresponding bit of EXTI_PR (by writing a 1 into the bit). 11 /21
Using external interrupt/event Interrupt selection ● Configure Interrupt mask register (EXTI_IMR). ● Configure trigger selection registers(EXTI_RTSR and EXTI_FTSR). ● Configure NVIC Interrupt Set Enable Registers and Interrupt Clear Enable Registers to enable interrupt channel. (SETENA 0, SETENA 1…CLRENA 0, CLRENA 1…) 12 /21
Using external interrupt/event Event selection ● Configure Event mask register (EXTI_EMR). ● Configure trigger selection registers(EXTI_RTSR and EXTI_FTSR). 13 /21
Using external interrupt/event Software interrupt/Event selection ● Configure Interrupt or Event mask register (EXTI_IMR, EXTI_EMR). ● Configure Software interrupt event register (EXTI_SWIER). 14 /21
Using external interrupt/event Steps of programming: *1. System initialization. For example, clock configuration can be performed. System. Init() function can be called in firmware. 2. Configure GPIO. Enable GPIO clock and AFIO clock. 3. Configure EXTI. Select a pin as interrupt input. 4. Configure NVIC. Enable the interrupt channel in NVIC and configure the priority. 5. Wait for the interrupt in the main program. And write the handling code in interrupt service routine. 15 /21
Using external interrupt/event void GPIO_Configuration(void) //Configure GPIO { GPIO_Init. Type. Def GPIO_Init. Structure; //Configure PE 8 GPIO_Init. Structure. GPIO_Pin = GPIO_Pin_8; GPIO_Init. Structure. GPIO_Speed = GPIO_Speed_50 MHz; GPIO_Init. Structure. GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOE, &GPIO_Init. Structure); //Configure PA 0 GPIO_Init. Structure. GPIO_Pin = GPIO_Pin_0; GPIO_Init. Structure. GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOA, &GPIO_Init. Structure); } 16 /21
Using external interrupt/event void NVIC_Configuration(void) //Configure NVIC { NVIC_Init. Type. Def NVIC_Init. Structure; al 6 16 P u e r wa n ma m r NVIC_Priority. Group. Config(NVIC_Priority. Group_1); Fi //Select the priority group NVIC_Init. Structure. NVIC_IRQChannel = EXTI 0_IRQn; //Select interrupt channel: EXTI Line 0, as PA 0 pin is select for input NVIC_Init. Structure. NVIC_IRQChannel. Preemption. Priority = 0; //preemption is set to 0 NVIC_Init. Structure. NVIC_IRQChannel. Sub. Priority = 0; //subpriority is set to 0 NVIC_Init. Structure. NVIC_IRQChannel. Cmd = ENABLE; //enable pin as interrupt input NVIC_Init(&NVIC_Init. Structure); //call NVIC_Init() } 17 /21 !
Using external interrupt/event void EXTI_Configuration(void) { //call GPIO_EXTILine. Config function GPIO_EXTILine. Config(GPIO_Port. Source. GPIOB, GPIO_Pin. Source 0); EXTI_Init. Structure. EXTI_Line = EXTI_Line 0; are w m r //map the interrupt to Line 0 Fi EXTI_Init. Structure. EXTI_Mode = EXTI_Mode_Interrupt; //interrupt mode EXTI_Init. Structure. EXTI_Trigger = EXTI_Trigger_Falling //set to the falling trigger EXTI_Init. Structure. EXTI_Line. Cmd = ENABLE; //eanble interrupt EXTI_Init(&EXTI_Init. Structure); //call EXTI_Init firmware library funtion //to write the parameters to registers. ! P 99 l ua man } 18 /21
Using external interrupt/event void EXTI 0_IRQHandler(void) { if(EXTI_Get. ITStatus(EXTI_Line 0) != RESET) {/* interrupt occurs */ GPIO_Write. Bit(GPIOD, GPIO_Pin_8, (Bit. Action)((1 GPIO_Read. Output. Data. Bit(GPIOD, GPIO_Pin_8)))); //clear interrupt to avoid getin the IRQHandler wrong. EXTI_Clear. ITPending. Bit(EXTI_Line 0); } } 19 /21
Summary ● Definition of priority in STM 32 ● External interrupt/event controller ● Difference between interrupt and event. ● How to select interrupt or event. ● Using external interrupt with FWLIB. 20 /21
Next lecture chapter 8 STM 32 Sys. Tick Timer 21 /21
- Slides: 21