It is also a half-baked thing with simple interrupt processing.
Software environment: mdk470a
Hardware environment: STM32F4-Discovery. Press the key B1 to connect to the F4 Chip's pa0 pin. When a key is pressed, the pin level is pulled to the bottom.
Function Description: an external interrupt is triggered when the B1 button is pressed. After entering the interrupt processing function, send messages through the serial port.
Steps:
1. Enable the PA clock and set the pa0 pin as the 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;
Gpio_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. Enable the System Configuration controller clock.
rcc_apb2periphclockcmd (rcc_apb2periph_syscfg, enable);
the system control register (syscfg) function is added to the F4. Functions:
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 used to access the code area, select the Ethernet interface, and manage the connection from external disconnection to gpio.
set external interrupt and the External Interrupt configuration register of syscfg.
3. Configure the working mode of the External Interrupt exti.
map to pa0, that is, line 0, and trigger with the drop edge of the interrupt mode.
the operation mode of setting 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_interrupt;
Exti_initstructure.exti_trigger = exti_trigger_falling;
Exti_init (& exti_initstructure );
}
4. Write the interrupt processing function to print information to the serial port.
Fixed function name: void exti0_irqhandler (void ).
After entering the interrupt processing function, first check whether the interrupt is zero. If yes, the interrupt mark is cleared. Then you can send the message.
After the message is sent, clear the external interruption that occurs during the process of external interruption. 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 );
}
}
Technorati flag: 127f4, exti