cancel
Showing results for 
Search instead for 
Did you mean: 

TIM2 (PA0/PA1) Can't Receive RS422 Encoder Signals via Differential Converter

baby361200
Associate II

Hi all,
I'm working on an STM32F429 project and trying to read quadrature signals from an RS422 encoder (SIKO MSK5000). I'm connecting the encoder to TIM2 pins (PA0/PA1) in encoder mode (using timer input capture), but I can't get any signal detected by the timer.

The RS422 output is connected through a differential-to-TTL converter (based on MAX485), and I'm using the STM32's built-in encoder interface. However, the counter stays at zero, and I see no changes at all.

  • MCU: STM32F429

  • Encoder: SIKO MSK5000 (RS422 differential A/B output)

  • Interface: TIM2 in encoder mode (PA0 = CH1, PA1 = CH2)

  • RS422 to TTL Converter: 2x QYB-998 modules (each handling one channel)

  • MSK5000 A+ / A− → QYB-998 #1 → output → STM32 PA0 (CH1)

  • MSK5000 B+ / B− → QYB-998 #2 → output → STM32 PA1 (CH2)

  • Both converters powered by 5V (shared with STM32)

  • All GNDs connected properly

  • TIM2 initialized in encoder mode (count on both edges)

Any advice, especially from those who’ve worked with encoder mode + RS422, would be greatly appreciated! I’m happy to provide schematics or scope captures if that helps.

Thanks in advance!

18 REPLIES 18
waclawek.jan
Super User

Have you tried the experiment with reading GPIOA_IDR?

JW

I’ve encountered a new issue while debugging using GPIO->IDR to directly read the encoder signals.

I’m using two separate RS422-to-TTL converter boards, and I connect their outputs to PA0 and PA1 respectively. However, I noticed that only the signal connected to PA0 responds correctly and follows the encoder changes.

The one connected to PA1 behaves abnormally — it either doesn’t respond correctly or gives unstable results.

Interestingly, when I connect the same signal (from the problematic converter) to PA0 instead of PA1, it works fine.

So it seems like the problem might be related specifically to PA1 not reacting properly.

Do you have any idea what could be causing this?

Thanks again!

Attached is a short video of my test setup and the issue I described earlier.

waclawek.jan
Super User

That encoder appears to have a huge resolution, and probably holding it by hand causes enough instability of the signals.

At any case, if you see PA0/PA1 changing in IDR, the timer in encoder mode should count, too. If it does not, read out and check/post content of timer and GPIOA registers.

JW

To verify whether the input signals are working correctly, I used the onboard GPIO LEDs to manually check the waveform behavior from each RS422-to-TTL output.

I've attached a video showing the test.

Based on the experiment, all signals behave as expected until I connect them to the TIM2 encoder input pin PA1. That’s when the abnormal behavior begins.

This suggests the issue may not be with the signal itself, but rather something related specifically to using PA1 as a TIM2 encoder input.

Let me know if you have any thoughts or further suggestions.
Thanks again!

messageImage_1751531836887.jpg

messageImage_1751534370559.jpg

  

Given what I observed in the previous tests and the video I shared, I’m starting to wonder if the issue might be related to my TIM encoder configuration.

Would you mind taking a look and letting me know if there’s anything possibly wrong with how I’ve set up the timer in encoder mode?

I’ve been using TIM2 with PA0 and PA1 as encoder inputs. The signal on PA1 only behaves abnormally when TIM2 is active in encoder mode, but looks fine otherwise when read via GPIO or displayed with the onboard LEDs.

Thanks again for your help!

I would like to confirm something regarding voltage compatibility:

Can STM32 GPIO pins safely accept 5V TTL input signals directly?
Or do I need to use a voltage divider or level shifter to bring the signal down to 3.3V?

Thanks in advance!

waclawek.jan
Super User

> Can STM32 GPIO pins safely accept 5V TTL input signals directly?

Only those pins which are marked as 5-volt tolerant (FT) in the Pin assignment and description table in datasheet.

If you look at that table in the STM32F429 or STM32F446 datasheet, you should see that they have all pins 5-volt tolerant (FT) except PA4 and PA5, but check yourself.

JW

So far, I've narrowed down the issue to the PA1 pin used for the TIM2 encoder input.

When I connect the encoder signal to PA0, everything behaves normally. But when I use PA1, the signal becomes unstable or doesn’t register properly.

I've verified that the input waveform is clean using an LED test, and the signal source is the same in both cases. This leads me to believe the problem is specifically related to PA1.

At this point, I’m honestly quite lost and exhausted after spending several days troubleshooting. I’m not sure what else could be wrong with this particular pin.

Could there be any other possible reasons that might cause this behavior with PA1 when used in encoder mode?

Any suggestions or guidance would be greatly appreciated.
Thanks again for your time and support.