Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Nächste ÜberarbeitungBeide Seiten der Revision
light_arm_interrupts_in_c [2019/12/12 09:46] – angelegt huwilight_arm_interrupts_in_c [2019/12/12 09:50] huwi
Zeile 1: Zeile 1:
-====== Interrupts in C für das mySTM32 Board Light ======+====== Timer-INT in C für das mySTM32 Board Light ======
  
 ><code> ><code>
 //--------------------------------------------------------------------------- //---------------------------------------------------------------------------
-// Title     : simple extern INT Solution, ARM C application in SiSy+// Title     : simple Timer-INT Solution, ARM C application in SiSy
 //--------------------------------------------------------------------------- //---------------------------------------------------------------------------
 // Function  : ... // Function  : ...
Zeile 19: Zeile 19:
 #include "hardware.h" #include "hardware.h"
  
-GPIO_InitTypeDef GPIO_InitStructure; 
-EXTI_InitTypeDef    EXTI_InitStructure; 
-NVIC_InitTypeDef    NVIC_InitStructure; 
-volatile bool mustToggle; 
-  
 void initApplication() void initApplication()
 { {
 + 
  SysTick_Config(SystemCoreClock/100);  SysTick_Config(SystemCoreClock/100);
  // weitere Initialisierungen durchführen  // weitere Initialisierungen durchführen
    
- mustToggle=false;+ // GPIOD Takt einschalten  
 + RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
    
- /* Enable the BUTTON Clock */ + // Konfiguriere PD15  
- RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); + GPIO_InitTypeDef  GPIO_InitStructure;
- /* 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_InitStructure);+ GPIO_Init(GPIOB, &GPIO_InitStructure);
    
-  /* 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, EXTI_PinSource0)+ TIM_TimeBaseInitTypeDef TIM_TimeBase_InitStructure
- EXTI_InitStructure.EXTI_Line EXTI_Line0+ TIM_TimeBase_InitStructure.TIM_ClockDivision TIM_CKD_DIV1
- EXTI_InitStructure.EXTI_Mode EXTI_Mode_Interrupt+ TIM_TimeBase_InitStructure.TIM_CounterMode TIM_CounterMode_Up
- EXTI_InitStructure.EXTI_Trigger EXTI_Trigger_Falling  + TIM_TimeBase_InitStructure.TIM_Period 4800
- EXTI_InitStructure.EXTI_LineCmd ENABLE+ TIM_TimeBase_InitStructure.TIM_Prescaler 10000
- EXTI_Init(&EXTI_InitStructure);+ TIM_TimeBaseInit(TIM16, &TIM_TimeBase_InitStructure); 
 + TIM_ITConfig(TIM16, TIM_IT_Update, ENABLE);
    
- /* Enable and set Button EXTI Interrupt to the lowest priority *+ // Timer einschalten 
- NVIC_InitStructure.NVIC_IRQChannel = EXTI0_1_IRQn+  TIM_Cmd(TIM16, ENABLE); 
- NVIC_InitStructure.NVIC_IRQChannelPriority 0x03;+  
 + // Interruptcontroller konfigurieren 
 + NVIC_InitTypeDef NVIC_InitStructure; 
 + NVIC_InitStructure.NVIC_IRQChannel TIM16_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure); + NVIC_InitStructure.NVIC_IRQChannelPriority = 0x03; 
 + NVIC_Init(&NVIC_InitStructure);
    
- /* Enable the LED Clock */ +}
- RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);+
    
- /* Configure red LED in output pushpull mode */ 
- GPIO_StructInit(&GPIO_InitStructure);  
- 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, &GPIO_InitStructure);  
-  
-} 
 int main(void) int main(void)
 { {
  SystemInit();  SystemInit();
  initApplication();  initApplication();
- do+ while(true)
  {  {
-  + //leer
- if (mustToggle) +
-+
- GPIO_SetBits(GPIOB,GPIO_Pin_0); +
- waitMs(100); +
- GPIO_ResetBits(GPIOB,GPIO_Pin_0); +
- waitMs(100); +
-+
- else +
- GPIO_ResetBits(GPIOB,GPIO_Pin_0); +
- +
  }  }
- while (true); 
- return 0; 
 } }
    
 extern "C" void SysTick_Handler(void) extern "C" void SysTick_Handler(void)
 { {
- // Application SysTick+ //leer
 } }
    
-extern "C" void EXTI0_1_IRQHandler() +extern "C" void TIM16_IRQHandler() 
-+  
- GPIO_SetBits(GPIOB,GPIO_Pin_0); + GPIO_ToggleBits(GPIOB,GPIO_Pin_0);  
-  + TIM_ClearITPendingBit(TIM16, TIM_IT_Update);
- if (mustToggle) +
- mustToggle=false; +
- else +
- mustToggle=true; +
-  +
- EXTI_ClearITPendingBit(EXTI_Line0);+
 } }
 //------------------------------------------------------------------------------ //------------------------------------------------------------------------------