Skip to content

Commit

Permalink
Add support for VDDHDIV5
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mattallen37 committed Jun 14, 2024
1 parent 8c8bcf2 commit d487674
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cores/nRF5/wiring_analog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
7 changes: 7 additions & 0 deletions cores/nRF5/wiring_analog_nRF52.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d487674

Please sign in to comment.