STM32F407 TIM5 external Clock/ ChibiOS

OP #4309695
Rate this post
useful
not useful
Hello,

i want to configure the Timer 5 with an external Clock (Button).

This is my code, but it doesn't work correct:

  GPIOA->MODER |= GPIO_MODER_MODER0_1;   // Enable AF mode for A0
  GPIOA->AFRL = (GPIOA->AFRL & 0xFFFFFFF0) | 0b0010;  // Select AF2 for 
A0 TIM3/4/5)
  RCC->APB1ENR |= RCC_APB1ENR_TIM5EN;           // Enable TIM5 clock
  TIM5->CCMR1 |= TIM_CCMR1_CC1S_0;        // Input mode, map TI1 to IC1
  TIM5->CCER &= ~(TIM_CCER_CC1P | TIM_CCER_CC1NP); // CC1P and CC1NP = 0 
for rising edge
  //TIM5->SMCR |= TIM_SMCR_SMS;                // External clock mode 1
  TIM5->SMCR |= TIM_SMCR_ECE;
  TIM5->SMCR |= TIM5->SMCR;         // Trigger selection: TI1
  TIM5->PSC = 0;
  TIM5->ARR = 2;
  TIM5->DIER |= TIM_DIER_UIE;
  TIM5->CR1 |= TIM_CR1_CEN;                  // Enable TIM5 counter


Do you have an idea what's wrong?

Kind regards

Reply

Please log in before posting.

or

Log in with Google account

Registration is free and takes only a minute.

Register now