Advertisement
Guest User

Untitled

a guest
Oct 16th, 2014
891
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.08 KB | None | 0 0
  1. /* Configuration function */
  2. void timer_config(void)
  3. {
  4.     TIM_TimeBaseInitTypeDef tim;
  5.     NVIC_InitTypeDef nvic;
  6.  
  7.     RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM9, ENABLE);
  8.  
  9. #ifdef 1
  10.     /* Results in a period of 10.33 ms */
  11.     tim.TIM_Prescaler = 59999;
  12.     tim.TIM_Period = 28;
  13. #else
  14.     /* Results in a period of 10.007 ms */
  15.     tim.TIM_Prescaler = 1249;
  16.     tim.TIM_Period = 1344;
  17. #endif
  18.     tim.TIM_CounterMode = TIM_CounterMode_Up;
  19.     tim.TIM_ClockDivision = TIM_CKD_DIV1;
  20.     TIM_TimeBaseInit(TIM9, &tim);
  21.  
  22.     nvic.NVIC_IRQChannel =                      TIM1_BRK_TIM9_IRQn;
  23.     nvic.NVIC_IRQChannelPreemptionPriority =    0;
  24.     nvic.NVIC_IRQChannelSubPriority =           0;
  25.     nvic.NVIC_IRQChannelCmd =                   ENABLE;
  26.     NVIC_Init(&nvic);
  27.  
  28.     TIM_ITConfig(TIM9, TIM_IT_Update, ENABLE);
  29.     TIM_Cmd(TIM9, ENABLE);
  30. }
  31.  
  32. /* TIM9 ISR */
  33. void TIM1_BRK_TIM9_IRQHandler(void)
  34. {
  35.         GPIOC->ODR |= GPIO_Pin_0;
  36.  
  37.         TIM9->SR &= ~TIM_IT_Update;
  38.  
  39.     /* Minor ISR operations. Only array access and subtractions */
  40.  
  41.         GPIOC->ODR &= ~GPIO_Pin_0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement