Skip to content

Commit 46f243c

Browse files
authored
hwCPUTemperature for NRF5 implementation (#1423)
* Implement hwCPUTemperature for NRF5 chip Get temperature via NRF_TEMP->TEMP * Fix hwCPUTemperature Change Temperature type to int32_t * Implement address anomalies * Replace wait with delay
1 parent 347ca0a commit 46f243c

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

hal/architecture/NRF5/MyHwNRF5.cpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,34 @@ uint16_t hwCPUFrequency(void)
523523

524524
int8_t hwCPUTemperature(void)
525525
{
526-
return -127; // not implemented yet
526+
int32_t volatile Temperature = 0;
527+
528+
nrf_temp_init();
529+
530+
for (byte i = 0; i < 10; i++) {
531+
532+
NRF_TEMP->TASKS_START = 1; /** Start the temperature measurement. */
533+
534+
/* Busy wait while temperature measurement is not finished, you can skip waiting if you enable interrupt for DATARDY event and read the result in the interrupt. */
535+
/*lint -e{845} // A zero has been given as right argument to operator '|'" */
536+
while (NRF_TEMP->EVENTS_DATARDY == 0) {
537+
// Do nothing.
538+
}
539+
540+
NRF_TEMP->EVENTS_DATARDY = 0;
541+
542+
/**@note Workaround for PAN_028 rev2.0A anomaly 29 - TEMP: Stop task clears the TEMP register. */
543+
Temperature += nrf_temp_read();
544+
545+
/**@note Workaround for PAN_028 rev2.0A anomaly 30 - TEMP: Temp module analog front end does not power down when DATARDY event occurs. */
546+
NRF_TEMP->TASKS_STOP = 1; /** Stop the temperature measurement. */
547+
548+
delay(10);
549+
}
550+
551+
//10 values for average
552+
//Temperature in degC (0.25deg steps)
553+
return (int8_t)(Temperature / 40);
527554
}
528555

529556
uint16_t hwFreeMem(void)

0 commit comments

Comments
 (0)