ioannk

Timer 3 init

May 15th, 2021 (edited)
251
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     RCC->APB1ENR |= RCC_APB1ENR_TIM3EN; //Enable tim3 clock
  2.        
  3.     GPIOA->CRL  |= GPIO_CRL_MODE6_1; // 01: Output mode, max speed 10 MHz.
  4.     GPIOA->CRL  &= ~GPIO_CRL_CNF6_0; // Default 0x01, clear first bit
  5.     GPIOA->CRL  |= GPIO_CRL_CNF6_1;  // 10: Alternate function output Push-pull
  6.     TIM3->CCMR1 |= TIM_CCMR1_OC1CE; // OC1PE: Output compare 1 preload enable
  7.     TIM3->CCMR1 |= (TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1M_2); // 110: PWM mode 1 - In upcounting, channel 1 is active
  8.     TIM3->CCER  |= TIM_CCER_CC1E; // Capture/Compare 1 output to pin enable
  9.     TIM3->CCER  |= TIM_CCER_CC1P; // Capture/Compare 1 output polarity
  10.     TIM3->PSC    = 0x2; // Prescaler value
  11.     TIM3->ARR    = 0xFFFF; // ARR is the value to be loaded in the actual auto-reload register.
  12.     TIM3->CCR1   = 0xfff; // Capture/Compare 1 value
  13.     TIM3->CR1   |= TIM_CR1_CEN; // Counter enable
RAW Paste Data