1. Different Subjects
Internal interrupt: An interrupt is an algorithm instruction, which is initiated by a soft interrupt instruction.
External interrupt: It is an internal mechanism for the microcontroller to process external events in real time.
2. Different mechanisms
Internal interrupt: When executing a division instruction, if the divisor is 0 or the quotient exceeds the range that the register can express, an internal interrupt of type 0 is generated. It is the internal interrupt with the highest priority.
External interrupt: When some external event occurs, the interrupt system of the microcontroller will force the CPU to suspend the program being executed and turn to handle the interrupt event; after the interrupt is handled, it returns to the interrupted program and continues to execute.
/********************************************************************************
* @file bsp_exti.c
* @author jianqiang.xue
* @version V1.0.0
* @date 2021-04-09
* @brief NULL
********************************************************************************/
/* Includes ------------------------------------------------------------------*/
#include #include #include #include "RTE_Components.h" #include CMSIS_device_header #include "cx32l003_hal_def.h" #include "cx32l003_hal_conf.h" #include "sys_api.h" /* Private Includes ----------------------------------------------------------*/ /* Private Define ------------------------------------------------------------*/ /* Private Variables ---------------------------------------------------------*/ bool bsp_exti_init = false; typedef void(*bsp_gpio_exti_callback)(void *gpiox, uint16_t gpio_pin); static bsp_gpio_exti_callback g_irq_callback; /* Public Function Prototypes ------------------------------------------------*/ void HAL_GPIO_EXTI_Callback(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin) { if (g_irq_callback) { g_irq_callback(GPIOx, GPIO_Pin); } } /** * @brief Set external interrupt NVIC * @note NULL * @param irqn: interrupt number (in typedef enum IRQn, for example: USART1_IRQn) * @param priority: interrupt priority * @retval None */ void bsp_exit_set(uint8_t irqn, uint32_t priority) { bsp_exit_init = true; HAL_NVIC_SetPriority((IRQn_Type)(irqn), priority); HAL_NVIC_EnableIRQ((IRQn_Type)(irqn)); } /** * @brief Clear external interrupt settings * @note NULL * @param irqn: interrupt number (in typedef enum IRQn, for example: USART1_IRQn) * @retval None */ void bsp_exit_clear_set(uint8_t irqn) { HAL_NVIC_DisableIRQ((IRQn_Type)(irqn)); } /** * @brief Clear external interrupt flag * @note NULL * @param *gpiox: reserved * @param pin: pin number * @retval None */ void bsp_exit_clear_flag(void *gpiox, uint8_t pin) { GPIO_TypeDef *gpiox_t = gpiox; __HAL_GPIO_EXTI_CLEAR_FLAG(gpiox_t, pin); } /** * @brief Register external event callback function * @note NULL * @param *event: event function * @retval None */ bool bsp_gpio_exit_irq_register_callback(void *event) { if (g_irq_callback != NULL) { return false; } else { g_irq_callback = (bsp_gpio_exti_callback)event; } return true; } /******************************************************************************** * @file bsp_exti.h * @author jianqiang.xue * @version V1.0.0 * @date 2021-04-09 * @brief NULL ********************************************************************************/ #ifndef __BSP_EXTI_H #define __BSP_EXTI_H /* Includes ------------------------------------------------------------------*/ #include /* Public Function Prototypes ------------------------------------------------*/ void bsp_exit_set(uint8_t irqn, uint32_t priority); void bsp_exit_clear_set(uint8_t irqn); void bsp_exit_clear_flag(void *gpiox, uint8_t pin); //Pin external interrupt callback bool bsp_gpio_exit_irq_register_callback(void *event); #endif
Previous article:[MCU framework][bsp layer][cx32l003][bsp_flash] FLASH configuration and use
Next article:[MCU framework][bsp layer][cx32l003][bsp_gpio] GPIO configuration and use
Recommended ReadingLatest update time:2024-11-16 22:38
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Why is the output impedance of the common emitter amplifier circuit Rc itself?
- STM32MP157A-DK1 Review
- TouchGFX Design + Make a Rubik's Cube (3)
- Detailed analysis of static in C language
- Using MicroPython on Lego EV3
- 【Showing goods】The third wave
- High-speed DAC
- Aperture Tuning: An Essential Technology in 5G Smartphones
- Why are MLCC measurements either low or high?
- 【RT-Thread Reading Notes】5 Chapter Reading Notes