Skip to main content
ECiot.1
Associate II
November 22, 2023
Solved

How to switch a pin between open drain and ground

Hi, I have a pin labeled "DISABLE_HV" that I want switch between open drain and ground (and vice versa) to switch-off and switch-on a DC-DC converter. How can I implement this functionality in the code using HAL library?

This topic has been closed for replies.
mƎALLEm
mƎALLEmBest answer
ST Technical Moderator
November 22, 2023

Hello @ECiot.1 ,

When you said "open drain" do you mean floating?

I that case to switch from floating to ground you need to configure the pin in output open-drain.

So when you set the pin to 1 in ODR it goes to floating. When you set the pin to 0 in ODR it switches to ground.

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.

4 replies

waclawek.jan
Super User
November 22, 2023

"Open drain" is a setting of the GPIO output structure, which simply disables the upper transistor of the output structure. It means, if you set a pin to GPIO Output in GPIO_MODER and Open drain in GPIO_OTYPER, if you write 1 to respective bit in GPIO_ODR (directly or through GPIO_BSRR), the pin is floating; if you write 0 to that ODR bit, the pin is switched to ground.

JW

mƎALLEm
mƎALLEmBest answer
ST Technical Moderator
November 22, 2023

Hello @ECiot.1 ,

When you said "open drain" do you mean floating?

I that case to switch from floating to ground you need to configure the pin in output open-drain.

So when you set the pin to 1 in ODR it goes to floating. When you set the pin to 0 in ODR it switches to ground.

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
ECiot.1
ECiot.1Author
Associate II
November 22, 2023

Yes I want to switch between floating and ground. Then if I write HAL_GPIO_WritePin(DISABLE_HV_GPIO_Port, DISABLE_HV_Pin, GPIO_PIN_SET) I obtained the pin floating and if I write HAL_GPIO_WritePin(DISABLE_HV_GPIO_Port, DISABLE_HV_Pin, GPIO_PIN_RESET) I obtained the pin to ground, is it correct?

mƎALLEm
ST Technical Moderator
November 22, 2023

Yes, that's correct.

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.