mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-08-28 21:48:20 +00:00
@@ -280,16 +280,29 @@ void NRF52Board::sleep(uint32_t secs) {
|
||||
|
||||
// Temperature from NRF52 MCU
|
||||
float NRF52Board::getMCUTemperature() {
|
||||
NRF_TEMP->TASKS_START = 1; // Start temperature measurement
|
||||
|
||||
long startTime = millis();
|
||||
while (NRF_TEMP->EVENTS_DATARDY == 0) { // Wait for completion. Should complete in 50us
|
||||
if(millis() - startTime > 5) { // To wait 5ms just in case
|
||||
NRF_TEMP->TASKS_STOP = 1;
|
||||
uint8_t sd_enabled = 0;
|
||||
sd_softdevice_is_enabled(&sd_enabled);
|
||||
if (sd_enabled) {
|
||||
uint32_t err_code;
|
||||
int32_t temp;
|
||||
err_code = sd_temp_get(&temp);
|
||||
if (err_code == NRF_SUCCESS) {
|
||||
return (float)temp * 0.25f;
|
||||
} else {
|
||||
return NAN;
|
||||
}
|
||||
} else {
|
||||
NRF_TEMP->TASKS_START = 1; // Start temperature measurement
|
||||
|
||||
long startTime = millis();
|
||||
while (NRF_TEMP->EVENTS_DATARDY == 0) { // Wait for completion. Should complete in 50us
|
||||
if(millis() - startTime > 5) { // To wait 5ms just in case
|
||||
NRF_TEMP->TASKS_STOP = 1;
|
||||
return NAN;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
NRF_TEMP->EVENTS_DATARDY = 0; // Clear event flag
|
||||
|
||||
int32_t temp = NRF_TEMP->TEMP; // In 0.25 *C units
|
||||
|
||||
Reference in New Issue
Block a user