cancel
Showing results for 
Search instead for 
Did you mean: 

GPIO & EXTI: switching between input & output

LCE
Principal

Heyho,

I'm currently using a GPIO on a STM32L031 for a custom 1-wire interface, which means it's switching all the time between input and output mode (open drain).

So far I have learned that the EXTI interrupt only works with GPIOs in input mode.

My question:

Once I have enabled the EXTI for a certain GPIO in input mode, then change the GPIO mode to output, then back to input, do I have to re-enable the EXTI somehow, or is it still working as before?

Thanks in advance!

1 ACCEPTED SOLUTION

Accepted Solutions

> in non-input mode the GPIO simply doesn't trigger the EXTI

No. "EXTI is independent from GPIO" means, that no matter how the pin is set in GPIO (except for Analog, when the digital input is disconnected entirely), EXTI works out of the edges it sees at given pin.

In other words, if you set a pin to trigger EXTI, and you set that pin as Output in GPIO, then if you by that output generate an edge for which EXTI is set up, that edge *will* trigger EXTI.

JW

View solution in original post

5 REPLIES 5
LCE
Principal

I think I found the answer here, in Jan's reply (thanks!):
How to change GPIO pin mode efficiently - STMicroelectronics Community

EXTI and GPIO are completely independent, so in non-input mode the GPIO simply doesn't trigger the EXTI.

Then I have to look elsewhere for my precious bugs... ;)

> in non-input mode the GPIO simply doesn't trigger the EXTI

No. "EXTI is independent from GPIO" means, that no matter how the pin is set in GPIO (except for Analog, when the digital input is disconnected entirely), EXTI works out of the edges it sees at given pin.

In other words, if you set a pin to trigger EXTI, and you set that pin as Output in GPIO, then if you by that output generate an edge for which EXTI is set up, that edge *will* trigger EXTI.

JW

LCE
Principal

So far, not so good:

after a lot of testing I'm pretty sure that:

either the EXTI is triggered with the GPIO not only in input mode,

or there's kinda race condition, meaning that output is switched to output before EXTI knows GPIO is not in input mode anymore.

1) GPIO is in input mode + pull-up -> line is high (verified on the scope)

2) then GPIO is switched to low output / open drain, pulling the line low (verified on the scope)

3) EXTI is triggered: falling edge

That a known issue?

somehow the browser didn't refresh...

anyway, thanks for the clarification!

LCE
Principal

Then ST should change this in the Ref Manual (RM0377 for L0x1):

LCE_0-1741107550125.png

It's at least ambiguous.