Measure battery on nRF52832

Hi,

First of all, a big thank you to all Mbed OS developers for making this excellent platform! It’s so convenient that I use it for all ARM-based microcontrollers I have (STM32, nRF52 so far).

Now my question. I know that on nRF5 microcontrollers one of the ADC mux inputs is wired to the VDD, so that it is possible to measure the battery voltage without adding any external circuitry. I know that it would require some specific reference voltage and prescaler configuration. Is it possible to use AnalogIn or some other high-level API for this task, or should I call nRF SDK methods directly? If anyone has a piece of example code, that would be perfect.

Thanks in advance,
Arthur

I used the nrf51822. I was looking to do the same thing. I did manage to do it and put it in the advertising data. I would however recommend using a different platform for this. As I started with the example codes and moved on with countless hours of tweaks and reading through the docs, I hit a road block… I was never able to get the battery consumption to what the specs read it can do. It lasts maybe 2 weeks. Even with the supplied example and nothing changed , it never would do any better. So before you commit a lot of time I would recommend another platform, this one has been good for some projects, but the nRF BLE was not for me…I ended up using Keil5 , and with low battery consumption. I posted on here hoping for some guidance or suggestion, but got close to nothing…lol. I wish someone would have let me know this, so I am passing on my experience to you.
But it is absolutely possible to use the ADC and advertising it with the nrf, although I used the nrf51822, i am sure it would work on the nrf 512832.
I dont have it in front of me…but from memory:
I used NRF_ADC->CONFIG from the nrf sdk, I think it was noted in the nrf51_bitfields.h file. after some conversions to get the volts . I divided it by 3. and advertised the battery percentage. I used the manufacturing data field (FF).

Thanks for sharing! I can understand your frustration. For some reason I am not able to get a nrf51822 to work with Mbed OS at all, but that is another topic. I think it has to do with clock configuration or something. However, the nrf52832 works for me, and it is very convenient to write code for Mbed platform as a C++ developer. For my current tasks I’m not much bothered with power consumption, so unfortunately I don’t have any useful tips for you. I used to work with nRF51822 beacons using Nordic SDK directly, which was a major pain for me because of different silicon revisions and totally incompatible SDK and softdevice versions.

As for this current question, I guess the answer tends to be ‘No’. I’ve found a couple pieces of code using SDK calls that I’ll try.

it works using the adc. we are unable to share code that we worked on for clients projects so I cannot post it. But if you have questions I can help you with those.