The MCU normally runs in user mode, that is, in the main function we wrote. However, when some exceptions occur, such as incorrect instructions, data access problems, or reset and other abnormal situations, the CPU will enter a special mode for exception handling.
For example, we want to turn on the LED light when a button is pressed. If we poll the button status in the program, there may be a detection delay. The button is pressed but the program has not yet executed to the point where the button status is queried. By the time the program is executed, the button has been released, so we cannot achieve the desired effect.
In order to respond immediately, there is an exception in the MCU hardware, called interrupt. We can configure the button pin as an external interrupt pin. When the button is pressed, it enters the corresponding interrupt service program, changes the flag bit in the subroutine, processes it in the main program, and lights up the LED.
Before entering the interrupt service routine, we need to save the original program status, mainly the register status, and then jump to the interrupt service routine for processing. After processing, we need to jump back to the original program to continue running. Therefore, the interrupt handling process is as follows:
Save the scene (save various registers);
Call the handler (to handle the interrupt/exception);
Restore the scene (return to the original program and continue execution).
ARM's use of interrupts/exceptions:
First, you need to initialize: a. Set the interrupt source so that it can generate an interrupt; b. Set the interrupt controller (set whether to block, set the priority, etc.); c. Enable the interrupt master switch;
The interrupt is not triggered, so other programs are executed first;
An interrupt is generated, such as pressing a key. The interrupt controller will receive the signal, and then the interrupt controller will send a signal to the CPU;
After each instruction is executed, the CPU will detect whether an interrupt/exception occurs (this function is implemented by hardware);
Detect an exception/interrupt and start processing. For different exceptions, the CPU will jump to different addresses (exception vectors, there is an exception vector table) to execute the program; (at these addresses, there is only a jump instruction to jump to execute other functions. These functions need to save the scene, handle the exception (interrupt) and call the processing function to restore the scene).
The exception vector table of 2440 is as follows:
So, how to call the interrupt function?
Answer: I won’t say much, it’s very basic and you can understand it by looking at the pictures.
Previous article:1.4.3 Relocation_Clearing the BSS segment using C language
Next article:1.5.2 Exceptions and Interrupts_CPU Mode_State and Registers
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- C++ class inheritance
- He was put in jail due to facial recognition error!
- BrainPad development board purchased with E-coins
- Please tell me how to use the regular pad, thermal pad and anti pad of cadence pad
- Recruiting part-time dsp training teachers
- What can DM355 do? Let me analyze it with you
- Check some questions in the MP2315 chip manual
- Infrared control animation
- Overview of PCB Process DFM Technical Requirements
- Can MCx063A achieve DC12V, 1.5A output?