Skip to main content
Visitor II
April 28, 2022
Solved

Read GPIO Analog

  • April 28, 2022
  • 7 replies
  • 8421 views

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.
    Best answer by TDK

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

    7 replies

    Graduate
    April 28, 2022

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

    NASIAuthor
    Visitor II
    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?

    Super User
    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.

    NASIAuthor
    Visitor II
    April 28, 2022

    Thank you TDK

    there is no ADC mode for PB10

    0693W00000LzLjNQAV.pngso I have to use GPIO_input mode?

    TDKAnswer
    Super User
    April 28, 2022

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

    Explorer
    January 10, 2024

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

    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

     

    NASIAuthor
    Visitor II
    April 28, 2022

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

    Super User
    April 28, 2022
    You can only read analog values from pins connected to the ADC. PB10 isn’t one of those.
    NASIAuthor
    Visitor II
    April 28, 2022

    Thank you @TDK​