Experimental platform: Zhengdian Atomic Battleship Development Board
System: Windows 7 64-bit
Compiler: MDK 4.72a
Reference routines: ATK serial port routines, Wildfire ISO serial port routines
External interrupt
There are two main types of interrupts:
1. System abnormal interrupts can also be called kernel abnormalities. Some of these abnormal interrupts cannot be controlled, such as RESET, NMI, and FAULT.
2. External interrupts. These interrupts can be set. Each GPIO can be set as an interrupt.
1. NVIC controller
When you want to use interrupts, you must set up the NVIC
void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct);
NVIC_IRQChannel The interrupt line that needs to be configured
NVIC_IRQChannelCmd enables or disables the interrupt response of the corresponding interrupt vector
NVIC_IRQChannelPreemptionPriority configures the corresponding interrupt vector preemption priority
NVIC_IRQChannelSubPriority configures the response priority of the corresponding interrupt vector
Preemption > Response, first determine the preemption and then determine the response.
To configure these priority groups, you can use the library function NVIC_PriorityGroupConfig(), which can be entered as
The input parameters are NVIC_PriorityGroup_0 ~ NVIC_PriorityGroup_4, and there are 5 allocation groups.
The relation is:
Group 0: 16 types of tackles
Group 1: 2 steals, 8 responses
Group 2: 4 steals, 4 responses
Group 3: 8 tackles, 2 responses
Group 4: 16 responses, no steals
The smaller the number, the higher the priority. This priority group should be set only when many interrupts are to be used. Otherwise, it does not need to be set.
2. EXIT
STM32 has a total of 16 interrupt lines, numbered 0 to 15. The 0th pin of GPIOA to GPIOG belongs to interrupt line 0, all 1st pins belong to interrupt line 1, and so on. However, each interrupt line can only respond to the interrupt of one pin at a time, but it can be time-divided and multiplexed to set different trigger modes.
void EXTI_Init(EXTI_InitTypeDef* EXTI_InitStruct); //initialization structure function
typedef struct
{
uint32_t EXTI_Line; //Interrupt line number EXTI_LineX;
EXTIMode_TypeDef EXTI_Mode; //Mode selection interrupt or event
EXTITrigger_TypeDef EXTI_Trigger; //Trigger mode
FunctionalState EXTI_LineCmd; //Enable command
} EXIT_InitTypeDef;
After filling in these two structures and initializing them, you can use external interrupts. But we also need an interrupt function
Remember to enable the pin's multiplexing function AFIO
The interrupt function has a fixed function name and cannot be changed. We can see the interrupt function from the startup file.
The general format of the external key interrupt function is:
void EXTI2_IRQHandler(void)
{
if( EXTI_GetITStatus(EXTI_Line2 ) != RESET) //Judge whether an interrupt occurs on a certain line
{
Interrupt logic...
EXTI_ClearITPendingBit( EXTI_Line2 ); // Clear the interrupt flag on LINE
}
}
IWDG
The function of the watchdog is to prevent the program from running away or crashing. When IWDG_KR is not written to 0XAAAA regularly, a forced reset signal will be generated to restart the chip. However, IWDG uses an internal RC clock with an unstable frequency, so the watchdog should be fed in advance to prevent an unexpected reset.
void IWDG_WriteAccessCmd(uint16_t IWDG_WriteAccess);
Turn write protection on and off for IWDG
void IWDG_SetPrescaler(uint8_t IWDG_Prescaler);
Frequency division ratio 2^n (n= 2 ~ 16) Maximum 256
void IWDG_SetReload(uint16_t Reload);
Set the maximum reload value to 4095
void IWDG_ReloadCounter(void);
Reload the number of IWDG_RLR register
void IWDG_Enable(void);
Enabling IWDG
FlagStatus IWDG_GetFlagStatus(uint16_t IWDG_FLAG);
Check whether pre-scaling or reloading is in progress
The time is calculated as: Tout=((4×2^prer) ×rlr) /40.
Part of the code:
void IWDG_Init()
{
IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);
IWDG_SetPrescaler(4);
IWDG_SetReload(625);
IWDG_ReloadCounter();
IWDG_Enable();
}
void EXITX_Init()
{
EXIT_InitTypeDef EXIT_InitStruct;
NVIC_InitTypeDef NVIC_InitStruct;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOE,GPIO_PinSource2);
EXIT_InitStruct.EXTI_Line = EXTI_Line2;
EXIT_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;
EXIT_InitStruct.EXTI_Trigger = EXTI_Trigger_Falling;
EXIT_InitStruct.EXTI_LineCmd = ENABLE;
NVIC_InitStruct.NVIC_IRQChannel = EXTI2_IRQn;
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 2;
NVIC_InitStruct.NVIC_IRQChannelSubPriority = 2;
NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
EXIT_Init(&EXIT_InitStruct);
NVIC_Init(&NVIC_InitStruct);
}
void EXTI2_IRQHandler()
{
delay_ms(10);
if(KEY2 == 0)
{
IWDG_ReloadCounter();
}
EXTI_ClearITPendingBit(EXTI_Line2);
}
Previous article:STM32 IWDG usage
Next article:stm32 independent watchdog IWDG
Recommended ReadingLatest update time:2024-11-15 15:16
- Popular Resources
- Popular amplifiers
- Learn ARM development(14)
- Learn ARM development(15)
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
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
- 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
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Weekly review information is here~ Multiple development boards are online, waiting for you to apply
- EEWORLD University Hall----Intel Packaging Co-EMIB
- How to use bidirectional DC/DC converters in elevator emergency rescue devices to improve efficiency and reduce costs
- 50 ways to use TI CC6678 digital signal processor (DSP)
- EEWORLD University Hall----Live Replay: Introduction to ST MEMS Sensor Development Kit, Understanding Sensors with Embedded "Finite State Machine and Machine Learning Core"
- How does Radio Frequency Identification (RFID) work?
- Mobile station update development board, welcome to borrow~~
- Putty released version 0.71
- Physical Explanation of Matched Filters
- [Evaluation of SGP40] 4. zynq + SVM40