Stm32f303vc discovery tim3 is not working

1

I would like to configure tim3 ch1 ch2 as encoder mode, I have the same code on tim2( it's also general purpose timer) and it's working good. Maybe there's another bits should I set but I cant find them.

I was trying to configure this timer to work without any outputs, just generate interrupt after set period of time but it's not working as well.

    //TIM2 CH1 PA0 CH2 PA1 AF1
    //TIM3 CH1 PE2 CH2 PE3 AF2

    RCC->APB1ENR |= RCC_APB1ENR_TIM2EN | RCC_APB1ENR_TIM3EN ;
    RCC->AHBENR |= RCC_AHBENR_GPIOAEN | RCC_AHBENR_GPIOEEN;

    GPIOA->MODER |= GPIO_MODER_MODER0_1 |  GPIO_MODER_MODER1_1;
    GPIOE->MODER |= GPIO_MODER_MODER2_1 |  GPIO_MODER_MODER3_1;

    GPIOA->AFR[0] |= 0X00000011;
    GPIOE->AFR[0] |= 0X00002200;


    TIM2->SMCR = TIM_SMCR_SMS_0;
    TIM2->CCMR1 = TIM_CCMR1_CC1S_0|TIM_CCMR1_CC2S_0;
    TIM2->ARR = 24;
    TIM2->DIER = TIM_DIER_UIE;
    TIM2->CR1= TIM_CR1_CEN;

    TIM3->SMCR = TIM_SMCR_SMS_0 ;
    TIM3->CCMR1 = TIM_CCMR1_CC1S_0 | TIM_CCMR1_CC2S_0;
    TIM3->ARR = 24;
    TIM3->DIER = TIM_DIER_UIE;
    TIM3->CR1= TIM_CR1_CEN ;

enter image description here

c
timer
stm32
keil
asked on Stack Overflow Aug 27, 2019 by Nes87 • edited Aug 27, 2019 by Nes87

2 Answers

1

Set SMCR to 0

Your code sets both timers to encoder mode 1, see the description of the SMCR register in the reference manual.

0001: Encoder mode 1 - Counter counts up/down on TI1FP1 edge depending on TI2FP2 level.

In this mode, the timer counter is incremented or decremented by the signals on then CH1 and CH2 input, instead of the internal clock. There must be some other component on the board, or line noise when they are unconnected, that managed to trigger TIM2 a few times.

PE2 is connected to an output of another IC

Check the schematics in the board user manual. PE2 is connected to the DRDY output of the onboard accelerometer.

You can use the CubeMX tool to find available pins for TIM3. Select your board in the Board Selector screen, it will show that PE2 and PE3 are already connected to something.

Set TIM3 combined channels to encoder mode, it will assign some free pins to the timer. You can then hold down CTRL and click on the pin to see alternatives (they will blink in blue), and you can drag the pin assignments with the mouse.

answered on Stack Overflow Aug 28, 2019 by followed Monica to Codidact • edited Aug 28, 2019 by followed Monica to Codidact
0

Ok, I find a solution :) If I assign TIM3 CH1 to PB4 and CH2 to PB5 it's work good, but I don't understand why, can someone explain it ?

answered on Stack Overflow Aug 28, 2019 by Nes87

User contributions licensed under CC BY-SA 3.0