I am using an stm32f411re nucleo board. I am trying to configure the Tim2_ch1 module in output compare mode.
I have written the code by referring to the reference manual:
code:
//PA5:TIM2_CH1
// clock frequency:16Mhz
#include "stm32f4xx.h" // Device header
// toggle led at 1hz using TIM2 output COMPARE MODE
int main(void)
{
RCC->AHB1ENR |=1;
GPIOA->MODER |=0X800; //PA_5 is configured in alternate function mode
GPIOA->AFR[0] |=0X00100000; // Tim2_ch1 is assigned to PA_5
//TIM2 OUTPUT COMPARE CONFIG
RCC->APB1ENR |=1;
TIM2->PSC |=1600-1;
TIM2->ARR |=10000-1; //clock frequency is divided by prescalar and auto reload
TIM2->CCMR1 |=0X30;
TIM2->CCR1 |=0;
TIM2->CCER |=1;
TIM2->CNT |=0;
TIM2->CR1 |=1;
while(1)
{}
}
This code is not working. Is there any issue with the code?
|=(OR-equals) operator for every register assignment? That seems wrong for TIM2->PSC, TIM2->ARR, and probably others but I stopped checking. \$\endgroup\$