externe Interrupts
…
//---------------------------------------------------------------------- // Titel : einfaches Beispiel für die INT-Programmierung des STM32F4 //---------------------------------------------------------------------- // Funktion : der blaue UserButton schaltet die rote LED per extINT um // Schaltung : UserButton an PA0, Blaue LED PD15 //---------------------------------------------------------------------- // Hardware : STM32F4 Discovery // MCU : STM32F407VGT6 // Takt : 168 MHz // Sprache : ARM C // Datum : 21.01.2013 // Version : 1 // Autor : Alexander Huwaldt //---------------------------------------------------------------------- #include <stddef.h> #include <stdlib.h> #include "hardware.h" #define BUTTON_USER (1<<0) #define LED_BLUE (1<<15) GPIO_InitTypeDef GPIO_InitStructure; EXTI_InitTypeDef EXTI_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; volatile bool mustToggle; void initApplication() { SysTick_Config(SystemCoreClock/100); // weitere Initialisierungen durchführen mustToggle=false; /* Enable the BUTTON Clock */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); /* Configure Button pin as input */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Pin = BUTTON_USER; GPIO_Init(GPIOA, &GPIO_InitStructure); /* Enable SYSCFG clock */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE); /* Connect EXTI0 Line to PA0 pin */ SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource0); EXTI_InitStructure.EXTI_Line = EXTI_Line0; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); /* Enable and set Button EXTI Interrupt to the lowest priority */ NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* Enable the LED Clock */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE); /* Configure red LED in output pushpull mode */ GPIO_StructInit(&GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = LED_BLUE; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOD, &GPIO_InitStructure); } int main(void) { SystemInit(); initApplication(); do { if (mustToggle) { GPIO_SetBits(GPIOD,LED_BLUE); waitMs(100); GPIO_ResetBits(GPIOD,LED_BLUE); waitMs(100); } else GPIO_ResetBits(GPIOD,LED_BLUE); } while (true); return 0; } extern "C" void SysTick_Handler(void) { // Application SysTick } extern "C" void EXTI0_IRQHandler() { if (mustToggle) mustToggle=false; else mustToggle=true; EXTI_ClearITPendingBit(EXTI_Line0); }