cancel
Showing results for 
Search instead for 
Did you mean: 

Read GPIO Analog

NASI
Senior

Hello,

I set one of GPIO to Analog mode and I want to read its value, by using HAL library.

Should I just use HAL_GPIO_ReadPin to read the value?

Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

Yes, so it can only read a digital value (0 or 1) rather than an analog value.

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

10 REPLIES 10
gbm
Lead III

In analog mode, the digital input circuit is turned off and the input value reads as 0 regardless of the voltage.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice
NASI
Senior

Thank you gbm

I am using STM32F105, and I connect an analog signal to PB10. In this case I want to monitor analog value. So base on you answer, I get 0 all time?

TDK
Guru

HAL_GPIO_ReadPin reads IDR which is disconnected in analog mode. You need to set the pin to input mode, or use the ADC to read the value.

If you feel a post has answered your question, please click "Accept as Solution".
NASI
Senior

Thank you TDK

there is no ADC mode for PB10

0693W00000LzLjNQAV.pngso I have to use GPIO_input mode?

TDK
Guru

Yes, so it can only read a digital value (0 or 1) rather than an analog value.

If you feel a post has answered your question, please click "Accept as Solution".
NASI
Senior

Just want to be sure that there is no way to read analog value (not digital value) from PB10 ?

You can only read analog values from pins connected to the ADC. PB10 isn’t one of those.
If you feel a post has answered your question, please click "Accept as Solution".
NASI
Senior

Thank you @TDK​ 

This pin does not allow ADC reading, but why is there an option called GPIO Analog?