Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Nächste ÜberarbeitungBeide Seiten der Revision | |||
light_arm_interrupts_in_c [2019/12/12 09:46] – angelegt huwi | light_arm_interrupts_in_c [2019/12/12 09:50] – huwi | ||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
- | ====== | + | ====== |
>< | >< | ||
// | // | ||
- | // Title : simple | + | // Title : simple |
// | // | ||
// Function | // Function | ||
Zeile 19: | Zeile 19: | ||
#include " | #include " | ||
- | GPIO_InitTypeDef GPIO_InitStructure; | ||
- | EXTI_InitTypeDef | ||
- | NVIC_InitTypeDef | ||
- | volatile bool mustToggle; | ||
- | |||
void initApplication() | void initApplication() | ||
{ | { | ||
+ | |||
SysTick_Config(SystemCoreClock/ | SysTick_Config(SystemCoreClock/ | ||
// weitere Initialisierungen durchführen | // weitere Initialisierungen durchführen | ||
- | mustToggle=false; | + | // GPIOD Takt einschalten |
+ | RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, | ||
- | /* Enable the BUTTON Clock */ | + | // Konfiguriere PD15 |
- | RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, | + | GPIO_InitTypeDef |
- | /* Configure Button pin as input */ | + | |
- | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; | + | |
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; | ||
+ | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; | ||
+ | GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; | ||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; | ||
- | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; | + | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; |
- | GPIO_Init(GPIOA, & | + | GPIO_Init(GPIOB, & |
- | /* Enable SYSCFG AF clock */ | + | // Takt für Timer einschalten |
- | RCC_APB2PeriphClockCmd(RCC_APB2ENR_SYSCFGEN, ENABLE); | + | RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM16, ENABLE); |
- | /* Connect EXTI0 Line to PA0 pin */ | + | // Timer konfigurieren |
- | SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, | + | TIM_TimeBaseInitTypeDef TIM_TimeBase_InitStructure; |
- | EXTI_InitStructure.EXTI_Line | + | TIM_TimeBase_InitStructure.TIM_ClockDivision |
- | EXTI_InitStructure.EXTI_Mode | + | TIM_TimeBase_InitStructure.TIM_CounterMode |
- | EXTI_InitStructure.EXTI_Trigger | + | TIM_TimeBase_InitStructure.TIM_Period |
- | EXTI_InitStructure.EXTI_LineCmd | + | TIM_TimeBase_InitStructure.TIM_Prescaler |
- | EXTI_Init(&EXTI_InitStructure); | + | TIM_TimeBaseInit(TIM16, |
+ | TIM_ITConfig(TIM16, | ||
- | /* Enable and set Button EXTI Interrupt to the lowest priority */ | + | // Timer einschalten |
- | NVIC_InitStructure.NVIC_IRQChannel = EXTI0_1_IRQn; | + | TIM_Cmd(TIM16, |
- | NVIC_InitStructure.NVIC_IRQChannelPriority | + | |
+ | // Interruptcontroller konfigurieren | ||
+ | NVIC_InitTypeDef | ||
+ | NVIC_InitStructure.NVIC_IRQChannel | ||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; | NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; | ||
- | NVIC_Init(& | + | NVIC_InitStructure.NVIC_IRQChannelPriority = 0x03; |
+ | NVIC_Init(& | ||
- | /* Enable the LED Clock */ | + | } |
- | RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, | + | |
- | /* Configure red LED in output pushpull mode */ | ||
- | GPIO_StructInit(& | ||
- | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; | ||
- | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; | ||
- | GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; | ||
- | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; | ||
- | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; | ||
- | GPIO_Init(GPIOB, | ||
- | |||
- | } | ||
int main(void) | int main(void) | ||
{ | { | ||
SystemInit(); | SystemInit(); | ||
initApplication(); | initApplication(); | ||
- | do | + | while(true) |
{ | { | ||
- | + | //leer | |
- | if (mustToggle) | + | |
- | { | + | |
- | GPIO_SetBits(GPIOB, | + | |
- | waitMs(100); | + | |
- | GPIO_ResetBits(GPIOB, | + | |
- | waitMs(100); | + | |
- | } | + | |
- | else | + | |
- | GPIO_ResetBits(GPIOB, | + | |
- | + | ||
} | } | ||
- | while (true); | ||
- | return 0; | ||
} | } | ||
extern " | extern " | ||
{ | { | ||
- | // Application SysTick | + | //leer |
} | } | ||
- | extern " | + | extern " |
- | { | + | { |
- | GPIO_SetBits(GPIOB, | + | GPIO_ToggleBits(GPIOB, |
- | + | TIM_ClearITPendingBit(TIM16, TIM_IT_Update); | |
- | if (mustToggle) | + | |
- | mustToggle=false; | + | |
- | else | + | |
- | mustToggle=true; | + | |
- | + | ||
- | EXTI_ClearITPendingBit(EXTI_Line0); | + | |
} | } | ||
// | // |