cancel
Showing results for 
Search instead for 
Did you mean: 

How to switch a pin between open drain and ground

ECiot.1
Associate II

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?

1 ACCEPTED SOLUTION

Accepted Solutions
SofLit
ST Employee

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 on "Accept as Solution" on the reply which solved your issue or answered your question.

View solution in original post

4 REPLIES 4

"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

SofLit
ST Employee

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 on "Accept as Solution" on the reply which solved your issue or answered your question.

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?

Yes, that's correct.

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