2714 views|0 replies

258

Posts

0

Resources
The OP

STM32F107VC Golden Dragon Development Board Chapter 2 EXTI [Copy link]

This post was last edited by Wangbao Electronics on 2015-4-10 10:41 Chapter 2 Golden Dragon 107——EXTI 2.1 EXTIIntroduction:
EXTI (External interrupt) refers to external interrupt, which detects input pulses throughGPIO , causing an interrupt event, interrupting the original code execution flow, and entering the interrupt service function for processing. After processing, it returns to the code before the interrupt to execute. For interconnect type (107 series) products, the external interrupt/event controller consists of 20 edge detectors that generate events/interrupt requests. Each input line can be independently configured with input type (pulse or pending) and corresponding trigger event (rising edge or falling edge or both edges). Roman]). Each input line can be masked independently. The suspend register holds the interrupt request of the status line.
First, let's understand what the interrupt vector table is. The Cortex kernel has a powerful exception response system. It divides events that can interrupt the current code execution flow into exceptions and interrupts, and manages them in a table. Numbers 0 to 15 are called kernel exceptions, and those above 16 are called external interrupts (external, relative to the kernel). This table is called the interrupt vector table.
2.2Experimental Description:
In this experiment, external interrupts are triggered by pressing buttons, flags are changed, and different LEDs are flashing.
Main jumper caps:JP4andJP7are both connected to2-3
2.3Hardware Description:
This experiment uses buttons S1andS2, as well as Roman]LEDLight
2.4Program description:
In the mainfunction, the system clock is first configured, and the LEDport and the key port are configured. Next, the interrupt is initialized and configured.
When configuring the key port, the port used by the key should be configured as an external interrupt input pin. It should be noted that all pins ofSTM32F107 can be configured as external interrupt input pins, but only one pin can be used on an external interrupt channel in the program. If you configure two pins on an external interrupt channel, the previous setting will be overwritten by the latter setting.
In the interrupt configuration, the structure is first declared and defined. The functions used can be viewed in the peripheral firmware function library to understand the functions in detail. It mainly configures its interrupt channel and interrupt priority. 193952 In the NVIC_Configuration(void) function, the NVIC_PriorityGroupConfig() library function is called to set the NVIC interrupt priority group to the 2nd group. We can see that NVIC uses the concept of interrupt priority grouping to manage interrupt priorities, and it can assign priorities to up to 256 interrupt vectors at most. NVIC assigns a preemptive priority and a secondary priority to each interrupt. The relationship between the preemptive priority and the secondary priority is described as follows:① An interrupt with a higher preemptive priority can interrupt an interrupt with a lower preemptive priority.② If two preemptive priority interrupts are pending at the same time, the interrupt with the higher secondary priority will be executed first.③ If the priorities of two pending interrupts are the same, the interrupt with the higher position in the interrupt vector table will be executed first.④ Another important point is that the secondary priority will not cause interrupt nesting at any time, which means that interrupt nesting is completely determined by the preemptive priority. Next, write parameters to the NVIC initialization structure. NVIC_IRQChannel = EXTI15_10_IRQn, indicating that the interrupt vector of EXTI lines 15 to 10 is to be configured. These writable parameters can be found in the IRQn type definition in the stm32f10x.h file. Then configure the preemptive priority and the secondary priority. Since this project is simple, just set it to the highest level interrupt. After filling the structure, finally call the NVIC_Init() function to write parameters to the register. Next is the configuration of the external interrupt, configure the corresponding channel and the corresponding trigger mode. 193951 In While, judge the flag bit of flag to achieve different LED flashes. 193950 When the button is pressed, the program will automatically jump into the interrupt service routine. The corresponding interrupt service routine is in stm32f10x_it.c. The interrupt service function of STM32 is also defined in the startup function and the corresponding address is assigned.
When we use the interrupt function, we only need to find the corresponding function in stm32f10x_it.c and write the program you need in it.
In the interrupt service program, we must first determine the interrupt source, then clear the interrupt flag (what we want to say here is that part of the interrupt flag of the controller is cleared by hardware, that is, once an interrupt is entered, the hardware will automatically clear the corresponding interrupt flag without code intervention, but there are some interrupts that require us to write code to clear the corresponding interrupt flag. So please refer to the relevant part of the reference manual for details), and then execute the interrupt handler. When writing the interrupt function entry, we should pay attention to the writing of the interrupt function name. There are only two naming methods. 1-> > EXTI0_IRQHandler ; EXTI Line 0 EXTI1_IRQHandler ; EXTI Line 1 EXTI2_IRQHandler ; EXTI Line 2 EXTI3_IRQHandler ; EXTI Line 3 EXTI4_IRQHandler ; EXTI Line 4 2-> > EXTI9_5_IRQHandler ; EXTI Line 9 ..5
From the naming of the interrupt function, we can see that after the interrupt line exceeds 4, it must be written as EXTI9_5_IRQHandler and EXTI15_10_IRQHandler. If you write it as EXTI5_IRQHandler and EXTI6_IRQHandler, the compiler will not report an error, but the interrupt program will not work. If you don't know, you will spend a lot of time without knowing where the problem lies
2.5Experimental phenomenon:
Download the program, reset, run the program, LD1 flashes; press S1, LD3 flashes, and the others are off; press S2, LD4 flashes, others are off.

图片1.png (16.71 KB, downloads: 0)

图片1.png

图片2.png (7.59 KB, downloads: 0)

图片2.png

图片3.png (12.66 KB, downloads: 0)

图片3.png

图片4.png (18.03 KB, downloads: 0)

图片4.png
This post is from stm32/stm8
Personal signaturehttp://openmcu.taobao.com]77[/url]

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Related articles more>>

    EEWorld
    subscription
    account

    EEWorld
    service
    account

    Automotive
    development
    circle

    Robot
    development
    community

    Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
    快速回复 返回顶部 Return list