Advertisement
Guest User

Interrupts

a guest
Oct 28th, 2017
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.29 KB | None | 0 0
  1. void TIM_InitMaster()
  2. {
  3.     RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
  4.     RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
  5.  
  6.     TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
  7.     NVIC_InitTypeDef NVIC_InitStructure;
  8.  
  9.     TIM_TimeBaseStructInit(&TIM_TimeBaseInitStructure);
  10.     TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_CenterAligned3;
  11.     TIM_TimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
  12.     TIM_TimeBaseInitStructure.TIM_Prescaler = 50000;
  13.     TIM_TimeBaseInitStructure.TIM_Period = 20;
  14.     TIM_TimeBaseInitStructure.TIM_RepetitionCounter = 0;
  15.     TIM_TimeBaseInit(TIM2, &TIM_TimeBaseInitStructure);
  16.  
  17.     TIM_ARRPreloadConfig(TIM2, ENABLE);
  18.  
  19.     TIM_SelectMasterSlaveMode(TIM2, TIM_MasterSlaveMode_Enable);
  20.     TIM_SelectOutputTrigger(TIM2, TIM_TRGOSource_Enable);
  21.  
  22.     TIM_Cmd(TIM2, ENABLE);
  23.  
  24.     TIM_UpdateDisableConfig(TIM2, ENABLE);
  25.  
  26.     TIM_UpdateRequestConfig(TIM2, TIM_UpdateSource_Global);
  27.  
  28.     NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
  29.  
  30.     NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
  31.     NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  32.     NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  33.     NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  34.     NVIC_Init(&NVIC_InitStructure);
  35.  
  36.     TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
  37.  
  38.     TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement