Skip to main content
NASI
Associate III
April 28, 2022
Solved

Read GPIO Analog

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.

This topic has been closed for replies.
TDK
TDKBest answer
April 28, 2022

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""."

10 replies

gbm
Super User
April 28, 2022

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
NASIAuthor
Associate III
April 28, 2022

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
April 28, 2022

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
NASIAuthor
Associate III
April 28, 2022

Thank you TDK

there is no ADC mode for PB10

0693W00000LzLjNQAV.pngso I have to use GPIO_input mode?

TDK
TDKBest answer
April 28, 2022

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""."
ENGIN TANRIKULU
Associate III
January 10, 2024

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

AScha.3
Super User
January 10, 2024

The GPIO analogue option is not to be confused with an ADC input, but in principle has two functions:

  • Disconnecting the external pin from the digital function. This is useful, for example, to disconnect the Schmitt trigger present at the digital input from a floating input, because this can lead to high-frequency switching of this trigger with associated current consumption.
  • Connecting any analogue peripherals (e.g. opamp, comparator, ADC) that may be present, but do not necessarily have to be in the respective case.

from

https://community.st.com/t5/stm32-mcus-products/use-gpio-analog-for-adc-read-value-on-stm32h735/td-p/75324

 

If you feel a post has answered your question, please click on " Best Answer ".
NASI
NASIAuthor
Associate III
April 28, 2022

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

TDK
April 28, 2022
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
NASIAuthor
Associate III
April 28, 2022

Thank you @TDK​