RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE) NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0x00 NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 0x00 NVIC_InitStruct.NVIC_IRQChannel = EXTI0_IRQn * PD0 is connected to EXTI_Line0, which has EXTI0_IRQn vector */ * Triggers on rising and falling edge */ĮXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Rising_Falling SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOD, EXTI_PinSource0) ĮXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt * Tell system that you will use PD0 for EXTI_Line0 */ GPIO_InitStruct.GPIO_Speed = GPIO_Speed_100MHz GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP GPIO_InitStruct.GPIO_OType = GPIO_OType_PP GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE) RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE) *Ğxternal interrupts Tilen Keil uVision 5 Code below should be well documented to understand how it works. In this example, we will set pin PD0 and PB12 to be a GPIO interrupts. Yes, lines 5-9 have the same interrupt handler and this is also for lines 10 to 15.Īfter you set settings for EXTI, you have to add them into NVIC. You have probably also figured, that only lines 0 to 4 have own IRQ handler. This table show you which IRQ you have to set for NVIC (first column) and function names to handle your interrupts (second column). Handler for pins connected to line 10 to 15 Handler for pins connected to line 5 to 9 STM32F4 has 7 interrupt handlers for GPIO pins. But you have to handle interrupt somehow. OK, now you have selected your pin you want to use.
#Stm32 hal gpio how to
I will show now how to configure GPIO pin to be an interrupt and how to handle it in your code with CMSIS function. October 1, 2014: Added external interrupts library. First interrupt section is for external pins (P0 to P15) on each port, and other section is for other events, like RTC interrupt, Ethernet interrupt, USB interrupt and so on. Affiliate programs and affiliations include, but are not limited to, the eBay Partner Network (EPN) and STM32F4 device has 23 external interrupt or event sources. Logic Analyzer (on ) ( on eBay)Īffiliate Disclosure: When you click on links in this section and make a purchase, this can result in this site earning a commission.FeelTech DDS Function Generator: KKMoon FY6900 (on ) ( on eBay).My Digital Storage Oscilloscope (DSO): Siglent SDS1104 (on ) ( on eBay).Some Extremely Useful Test Equipment For Troubleshooting:
#Stm32 hal gpio full
★ Check The Full Course Complete Kit List ST-Link v2 Debugger or ( eBay) QTY Component Name ? ? 2 BreadBoard Amazon eBay 1 LEDs Kit Amazon Amazon eBay 1 Resistors Kit Amazon Amazon eBay 1 Capacitors Kit Amazon Amazon eBay & eBay 2 Jumper Wires Pack Amazon Amazon eBay & eBay 1 9v Battery or DC Power Supply Amazon Amazon Amazon eBay 1 Micro USB Cable Amazon eBay 1 Push Buttons Amazon Amazon eBay.Blue Pill STM32-F103 (ARM Cortex-M3 72MHz) or ( eBay).Nucleo32-L432KC (ARM Cortex-M4 80MHz) or ( eBay).All the example code/LABs/projects in the course are going to be done using those boards below.