2020-03-23 06:36 AM
F(clock) = 16000000 Hz
Led is in TIM2 channel 1 , output compare mode , toggle on match
My code is :
void timer_set()
{
// Enable TIM2 clock
RCC->APB1ENR |= RCC_APB1ENR_TIM2EN;
// delay for RCC
__asm("dsb");
TIM2->CNT=0;
TIM2->PSC = 15999;
TIM2->ARR = 99;
TIM2->CCR1 = 20;
TIM2->CCMR1 = TIM_CCMR1_OC1M_0 | TIM_CCMR1_OC1M_1;
TIM2->CCER = TIM_CCER_CC1E; // Enable compare output 1
TIM2->CR1 = TIM_CR1_CEN;
}
but channel 1 / led can't toggle - what's wrong ??
2020-03-23 06:55 AM
Did you initialize the pin in AF mode?
2020-03-23 07:26 AM
I can't initialize this ( AF ) any example ?
2020-03-23 07:28 AM
2020-03-24 12:28 AM
Refer to the GPIO chapter in the reference manual.
E.g. to map TIM2_CH1 to PA0:
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN;
RCC->AHB1ENR; // short delay might be necessary
GPIOA->MODER = (GPIOA->MODER & ~GPIOA_MODER_MODE0) | GPIOA_MODER_MODE0_1;
GPIOA->AFR[0] = (GPIOA->AFR[0] & ~GPIO_AFRL_AFSEL0) | (1u << GPIO_AFRL_AFSEL0_Pos);