From a68f7e4ce3b24720f35e4a9cf125d91185645c57 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Sun, 18 Sep 2022 23:13:15 +0200 Subject: [PATCH] nrf: add ReadTemperature method Similar to the rp2040, the nrf has an on-board temperature sensor. The main reason why I added this function was to show how this new API is more general and can be used on multiple chips. --- src/machine/machine_nrf.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/machine/machine_nrf.go b/src/machine/machine_nrf.go index 2d533db97..2f8360679 100644 --- a/src/machine/machine_nrf.go +++ b/src/machine/machine_nrf.go @@ -372,3 +372,14 @@ func GetRNG() (ret uint32, err error) { return ret, nil } + +// ReadTemperature reads the silicon die temperature of the chip. The return +// value is in milli-celsius. +func ReadTemperature() int32 { + nrf.TEMP.TASKS_START.Set(1) + for nrf.TEMP.EVENTS_DATARDY.Get() == 0 { + } + temp := int32(nrf.TEMP.TEMP.Get()) * 250 // the returned value is in units of 0.25°C + nrf.TEMP.EVENTS_DATARDY.Set(0) + return temp +}