cancel
Showing results for 
Search instead for 
Did you mean: 

GPIO INPUT/OUTPUT

Ala
Senior

does any body know how to define a pin in CubeMX, so it would be GPIO_INPUT and GPIO_OUT at the same time?

I want to write to a pin and read it's state too

1 ACCEPTED SOLUTION

Accepted Solutions

Yes, exactly. Take a note that you can read both - ODR and IDR registers. Normally they will show the same values, but theoretically in case of some short circuit, IDR will show the actual physical level of the pin. If it will still function... 🙂

View solution in original post

5 REPLIES 5

You can always read the digital state of the pin, unless it's set as analog.

So, simply leave it as Out.

JW

So if I define it as GPIO_OUTPUT, I can both read this pin and write it as HIGH/LOW?

Yes, exactly. Take a note that you can read both - ODR and IDR registers. Normally they will show the same values, but theoretically in case of some short circuit, IDR will show the actual physical level of the pin. If it will still function... 🙂

> ODR and IDR registers. Normally they will show the same values

They may differ not only in pathological cases, but also if the given ouput pin is set as Open Drain.

JW

Indeed. Good point!