Merge pull request #683 from ajs123/master
Add SAADC offset calibration and reading of CPU temperature
This commit is contained in:
4 files changed
+57
No files matched your search
@@ -143,3 +143,27 @@ void systemOff(uint32_t pin, uint8_t wake_logic)
|
||||
NRF_POWER->SYSTEMOFF = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
float readCPUTemperature( void )
|
||||
{
|
||||
uint8_t en;
|
||||
int32_t temp;
|
||||
(void) sd_softdevice_is_enabled(&en);
|
||||
if (en)
|
||||
{
|
||||
sd_temp_get(&temp);
|
||||
}
|
||||
else
|
||||
{
|
||||
NRF_TEMP->EVENTS_DATARDY = 0x00; // Only needed in case another function is also looking at this event flag
|
||||
NRF_TEMP->TASKS_START = 0x01;
|
||||
|
||||
while (!NRF_TEMP->EVENTS_DATARDY);
|
||||
temp = NRF_TEMP->TEMP; // Per anomaly 29 (unclear whether still applicable), TASKS_STOP will clear the TEMP register.
|
||||
|
||||
NRF_TEMP->TASKS_STOP = 0x01; // Per anomaly 30 (unclear whether still applicable), the temp peripheral needs to be shut down
|
||||
NRF_TEMP->EVENTS_DATARDY = 0x00;
|
||||
}
|
||||
return temp / 4.0F;
|
||||
}
|
||||
@@ -42,6 +42,12 @@ static inline bool isInISR(void)
|
||||
return (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk) != 0 ;
|
||||
}
|
||||
|
||||
/*
|
||||
* \brief Reads the on-chip temperature sensor, returning the temperature in degrees C
|
||||
* with a resolution of 0.25 degrees.
|
||||
*/
|
||||
float readCPUTemperature( void );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -116,6 +116,14 @@ extern void analogWriteResolution(uint8_t res);
|
||||
*/
|
||||
extern void analogSampleTime(uint8_t sTime);
|
||||
|
||||
/*
|
||||
* \brief Calibrate the ADC offset. This is recommended occasionally, or any time the
|
||||
* chip temperature changes by more than 10 C. See the SAADC section of the Nordic
|
||||
* nrf52 product pecification.
|
||||
*
|
||||
*/
|
||||
extern void analogCalibrateOffset( void );
|
||||
|
||||
extern void analogOutputInit( void ) ;
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -284,6 +284,25 @@ uint32_t analogReadVDD( void )
|
||||
return analogRead_internal(SAADC_CH_PSELP_PSELP_VDD);
|
||||
}
|
||||
|
||||
void analogCalibrateOffset( void )
|
||||
{
|
||||
// Enable the SAADC
|
||||
NRF_SAADC->ENABLE = 0x01;
|
||||
|
||||
// Be sure the done flag is cleared, then trigger offset calibration
|
||||
NRF_SAADC->EVENTS_CALIBRATEDONE = 0x00;
|
||||
NRF_SAADC->TASKS_CALIBRATEOFFSET = 0x01;
|
||||
|
||||
// Wait for completion
|
||||
while (!NRF_SAADC->EVENTS_CALIBRATEDONE);
|
||||
|
||||
// Clear the done flag (really shouldn't have to do this both times)
|
||||
NRF_SAADC->EVENTS_CALIBRATEDONE = 0x00;
|
||||
|
||||
// Disable the SAADC
|
||||
NRF_SAADC->ENABLE = 0x00;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in new issue
Block a user