Getting Battery Voltage with nRF52840

I want to get the value of battery voltage using pin number with battery voltage monitoring function in nRF52840.
What I tried was to use the function "nrf_gpio_pin_read()" and put the pin number as an argument. The result was that the value of "1" kept coming up.
I'm looking for a function that outputs the voltage value itself using the pin number, but I can't seem to find it.
If you know of such a function, could you please let me know? Since I am a complete beginner in nRF, I may have said something unclear due to my lack of prior knowledge, so I would appreciate it if you could point it out to me.
Thank you very much.

Translated with www.DeepL.com/Translator (free version)

Parents
  • you cannot read battery voltage by just reading the gpio. You need to use SAADC to get the input levels which in turn uses a GPIO to which you have power source connected. Please read this blog to understand more how to read a battery level from power_source->GPIO->SAADC->Application.

    nrf_gpio_pin_read will only gpio pin state which is either digital 0 or a 1

  • Susheel Nuguru, thank you very much for answering my question.
    I immediately tried coding using the site you gave me, which resulted in some errors, but I made some corrections myself. In addition, I couldn't figure out how to fix the error you describe below, so I asked again.
    Also, I did not understand the meaning of "m_bas", "adc_buf", and "m_battery_timer_id", so I would appreciate it if you could tell me what they mean.
    Thank you very much for your time and patience.

    ・Error Description

    1. 'm_bas' undeclared (first use in this function)
    2. 'adc_buf' undeclared (first use in this function)
    3. 'm_battery_timer_id' undeclared (first use in this function)
    4. 'm_battery_timer_is_running' undeclared (first use in this function)
    5. 'm_battery_timer_id' undeclared (first use in this function)

    LemonCake

Reply
  • Susheel Nuguru, thank you very much for answering my question.
    I immediately tried coding using the site you gave me, which resulted in some errors, but I made some corrections myself. In addition, I couldn't figure out how to fix the error you describe below, so I asked again.
    Also, I did not understand the meaning of "m_bas", "adc_buf", and "m_battery_timer_id", so I would appreciate it if you could tell me what they mean.
    Thank you very much for your time and patience.

    ・Error Description

    1. 'm_bas' undeclared (first use in this function)
    2. 'adc_buf' undeclared (first use in this function)
    3. 'm_battery_timer_id' undeclared (first use in this function)
    4. 'm_battery_timer_is_running' undeclared (first use in this function)
    5. 'm_battery_timer_id' undeclared (first use in this function)

    LemonCake

Children
Related