cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L431 TIM2 Rotary Encoder

Elena-Acwa
Associate

Hi,

 

I am having issues using the STM32L431RBI6 to read a rotary encoder.

The encoder has a 0-5V output on its 2 channels, and is working with my other STM32 setup (on a STM32L451CCU6).

On the STM32L431RBI6, I am using TIM2 configured in Encoder mode, with TIM2_CH1 & TIM2_CH2 mapped respectively on PA15 and PB3 (5V tolerant). The associated code was generated using STM32CubeMX included in STM32CubeIDE 1.14.1.

 

When running the code, the TIM2->CNT value does not get updated when I manually move the motor. After tracing the signals on a logic analyser, I noticed that the signal on PB3 was working fine (oscillating between 0 and 5V as expected). However, on PA15, the signal has the correct shape but is only oscillating between 0 and 0.8V.

 

On the board I am using, there are no intermediate components between the encoder output and each STM32 pin (only the PCB track). Both tracks are routed close to each other.

I am linking my GPIO & TIM2 configuration.

 

Do you have any input as to what may be causing this issue and how I could resolve it ?

 

Thank you for your help,

Elena

1 ACCEPTED SOLUTION

Accepted Solutions

>GPIOA

> MODER volatile uint32_t 0x6bb5a9af (Hex)

This shows, that for PA15, MODER is set to 0b01, ie. GPIO Output, and not GPIO Alternate Function as is should be.

Check/post code which sets up PA15.

JW

View solution in original post

2 REPLIES 2

>GPIOA

> MODER volatile uint32_t 0x6bb5a9af (Hex)

This shows, that for PA15, MODER is set to 0b01, ie. GPIO Output, and not GPIO Alternate Function as is should be.

Check/post code which sets up PA15.

JW

I just checked the PA15 configuration, turns out CubeMX was configuring it as I wanted, but I had another bit of code from my historic project which was reconfiguring PA15 as Output later on in the execution...

Removing my piece of code it solved the issue.

Thank you for your help!!

Elena