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 Reply Children
  • 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

  • LemonCake said:
    'm_bas' undeclared (first use in this function)

    #include "ble_bas.h"
    BLE_BAS_DEF(m_bas);

    LemonCake said:
    'adc_buf' undeclared (first use in this function)

    Seems like you have not taken the template example correctly or removed all the initialization members for some reason?

    examples\ble_peripheral\ble_app_proximity\main.c you can see most of your missing declaration in this file.

    static nrf_saadc_value_t adc_buf[2];
     
    LemonCake said:
    'm_battery_timer_is_running' undeclared (first use in this function)

    Cannot see this declaration in SDK17, which SDK version are you using?

  • Thank you very much, Susheel Nuguru.
    The version of the SDK I am using is 16.0.0.

    LemonCake

Related