From d48767476defae4a5c6eed64c35305b31f182bff Mon Sep 17 00:00:00 2001 From: Matthew Richardson Date: Fri, 14 Jun 2024 10:48:34 -0400 Subject: [PATCH] Add support for VDDHDIV5 Allow reading the VDDHDIV5 ADC source on devices that support it, such as nRF52840. For designs where the VDDH pin is connected to a battery, this is a great way to measure battery voltage without any additional external components. --- cores/nRF5/wiring_analog.h | 8 ++++++++ cores/nRF5/wiring_analog_nRF52.c | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/cores/nRF5/wiring_analog.h b/cores/nRF5/wiring_analog.h index e4e3e3252..d3c82252d 100644 --- a/cores/nRF5/wiring_analog.h +++ b/cores/nRF5/wiring_analog.h @@ -92,6 +92,14 @@ extern uint32_t analogRead( uint32_t ulPin ) ; */ extern uint32_t analogReadVDD( void ) ; +#ifdef SAADC_CH_PSELP_PSELP_VDDHDIV5 +/* + * \brief Read the value from the vddh pin with div5. + * + * \return Read value from vddh pin with div5, if no error. + */ +extern uint32_t analogReadVDDHDIV5( void ) ; +#endif /* * \brief Set the resolution of analogRead return values. Default is 10 bits (range from 0 to 1023). diff --git a/cores/nRF5/wiring_analog_nRF52.c b/cores/nRF5/wiring_analog_nRF52.c index e7dde3f34..6eb578cd0 100644 --- a/cores/nRF5/wiring_analog_nRF52.c +++ b/cores/nRF5/wiring_analog_nRF52.c @@ -284,6 +284,13 @@ uint32_t analogReadVDD( void ) return analogRead_internal(SAADC_CH_PSELP_PSELP_VDD); } +#ifdef SAADC_CH_PSELP_PSELP_VDDHDIV5 +uint32_t analogReadVDDHDIV5( void ) +{ + return analogRead_internal(SAADC_CH_PSELP_PSELP_VDDHDIV5); +} +#endif + void analogCalibrateOffset( void ) { // Enable the SAADC