We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
i want to setup timer in STM32F401RE and i already have this code:
int main(void) { TIM1_init(); while (1) {}}/// initialize TIM1/// timer TIM1 channel 2 is configed to generate PWM at 1kHz. the output of thevoid TIM1_init(void) { RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN; // enable GPIOA GPIOA->MODER |= (1 << 19); // PA9 to alternate function GPIOA->AFR[1] |= (1 << 4); // timer output mode RCC->APB2ENR |= RCC_APB2ENR_TIM1EN; // enable tim2 TIM1->CCMR1 |= (1 << 11); // enable preload TIM1->CCMR1 |= (1 << 6) | (1 << 5); // PWM mode 1 TIM1->CCER |= (1 << 4); // Capture/Compare 2 output enable. TIM1->PSC |= 160 - 1; TIM1->ARR |= 100 - 1; TIM1->CNT |= 0; TIM1->CCR2 = 50 - 1; TIM1->CR1 |= 1;}
currently the timer wont work:is there any problem in my code?