cancel
Showing results for 
Search instead for 
Did you mean: 

is it possible to use 2 pins on same EXTI?

htrvvrth
Associate

Hey,

I want to read an EC11 encoder without disturbing the main loop, so I decided to use interrupts.

Can I connect both pin A and pin B of the encoder to PA1 and PB1, and use only EXTI1 to map the switching events to the same interrupt routine?

4 REPLIES 4

No

Interrupt on ONE, read the other for direction? If they work like standard Quadrature Encoders.

See if these go to usable TIM inputs? You can put a TIM in Input Capture, and get an interrupt from those events, on all four channels.

 

 

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Karl Yamashita
Lead III

If you are using the pins in EXTI, then yes. You'll need to interrupt on both edges and keep track of the last state of each pin. When you get an interrupt, you'll need to read both pins and compare the current state to the last state.

The pin that has a different state would be the pin that caused the interrupt. Then you'll need to keep track of the on/off state to determine the direction. It's going to be more work than needed when you can easily use the Timer in encoder mode instead. 

Tips and Tricks with TimerCallback https://www.youtube.com/@eebykarl
If you find my solution useful, please click the Accept as Solution so others see the solution.
PGump.1
Senior III

Hi,

There are a couple of EXTI's that share the same interrupt handler (eg EXTI5 & EXTI9, EXTI10 & EXTI15). If you can route the pins to them, that maybe helpful...

Kind regards
Pedro

AI = Artificial Intelligence, NI = No Intelligence, RI = Real Intelligence.
Karl Yamashita
Lead III

I was looking for a post that asked a similar question. I think the question was how would you know which pin caused the interrupt since HAL Driver would return the same pin status. I believe i answered that question which i explained in the above post.

 

But then I started to remember that architecturally the STM32 can only interrupt on 1 pin using the same bit of a different port. So I was wrong. Actually the last pin to be configured for interrupt would take priority and cancel out the previous pin set for interrupt. 

Tips and Tricks with TimerCallback https://www.youtube.com/@eebykarl
If you find my solution useful, please click the Accept as Solution so others see the solution.