Skip to main content
Explorer
October 23, 2024
Question

is it possible to use 2 pins on same EXTI?

  • October 23, 2024
  • 4 replies
  • 1262 views

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?

    This topic has been closed for replies.

    4 replies

    Graduate II
    October 23, 2024

    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.

     

     

    Graduate II
    October 23, 2024

    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. 

    Graduate II
    October 24, 2024

    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

    Graduate II
    October 24, 2024

    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.