It is also a half-baked thing, and a simple interrupt processing is performed.
Software environment: MDK470a
Hardware environment: STM32F4-Discovery. Button B1 is connected to the PA0 pin of the F4 chip. When the button is pressed, the pin level is pulled down.
Function description: When button B1 is pressed, an external interrupt is triggered. After entering the interrupt processing function, a message is sent through the serial port.
Implementation steps:
1. Turn on the PA clock and set the PA0 pin as input.
void EXTI_GPIO_Congig(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG,ENABLE);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Pin = GPIO_PinSource0;
GPIO_InitStructure.GPIO_Speed =GPIO_Speed_100MHz;
GPIO_Init(GPIOA ,&GPIO_InitStructure);
}
2. Turn on the system configuration controller clock.
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG,ENABLE);
The function of the system control register (SYSCFG) is newly added in the F4 series. The functions are as follows:
The system configuration controller is mainly used to remap the memory accessible in the code area, select the Ethernet PHY interface and manage the external interrupt line
connection to the GPIOs.
SYSCFG is mainly used to map the memory access to the CODE area, select the Ethernet interface, and manage the connection of the external interrupt line to the GPIO.
To set an external interrupt, you must also set the external interrupt configuration register of SYSCFG.
3. Configure the working mode of the external interrupt EXTI.
Map it to PA0, that is, line 0, and use the interrupt mode falling edge trigger.
Setting the working mode of the EXTI register is handed over to the library function.
void EXTI_Config(void)
{
EXTI_GPIO_Congig();
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG,ENABLE);
EXTI_InitStructure.EXTI_Line = EXTI_Line0; EXTI_InitStructure.EXTI_LineCmd
= ENABLE;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Inter rupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_Init(&EXTI_InitStructure);
}
4. Write an interrupt handling function to print information to the serial port.
Fixed function name: void EXTI0_IRQHandler(void).
After entering the interrupt handling function, first check whether it is an interrupt on line 0. If so, clear the interrupt flag. Then you can send a message.
After the message is sent, clear the external interrupt that arrived during the external interrupt processing. Use EXTI_ClearITPendingBit() to complete
void EXTI0_IRQHandler(void)
{
if(SET == EXTI_GetITStatus(EXTI_Line0))
{
EXTI_ClearFlag(EXTI_Line0);
printf("i am in exti irqhandler\r\n");
printf("and the extiflag is cleared\r\n" );
EXTI_ClearITPendingBit(EXTI_Line0);
}
}
Previous article:STM32F4 ADC1
Next article:STM32F4 MDK creates a new project using the library
- Popular Resources
- Popular amplifiers
- 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)
- Learn ARM development (4)
- Learn ARM development (6)
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
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Vietnam's chip packaging and testing business is growing, and supply-side fragmentation is splitting the market
- Vietnam's chip packaging and testing business is growing, and supply-side fragmentation is splitting the market
- Three steps to govern hybrid multicloud environments
- Three steps to govern hybrid multicloud environments
- Microchip Accelerates Real-Time Edge AI Deployment with NVIDIA Holoscan Platform
- Microchip Accelerates Real-Time Edge AI Deployment with NVIDIA Holoscan Platform
- Melexis launches ultra-low power automotive contactless micro-power switch chip
- Melexis launches ultra-low power automotive contactless micro-power switch chip
- BlueNRG-1/2 Flash operations require mutual exclusion with BLE events
- 1S2192 Parameters
- Does anyone have the BAP protocol in Volkswagen's CAN protocol?
- The Definitive Guide to Automotive Ethernet
- Bluetooth learning notes: analysis of example broadcast data
- Live Review: New Opportunities in UWB Market on June 23
- Questions about DDR3 VTT
- Learn to use WiFi module to remotely burn programs to STM32/GD32 MCU in two minutes
- CMSIS_RTOS_Tutorial self-translated Chinese version
- [Qinheng Trial] Run the ID reading routine