Skip to content

Commit a68f7e4

Browse files
aykevldeadprogram
authored andcommitted
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.
1 parent 70b3ece commit a68f7e4

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/machine/machine_nrf.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,3 +372,14 @@ func GetRNG() (ret uint32, err error) {
372372

373373
return ret, nil
374374
}
375+
376+
// ReadTemperature reads the silicon die temperature of the chip. The return
377+
// value is in milli-celsius.
378+
func ReadTemperature() int32 {
379+
nrf.TEMP.TASKS_START.Set(1)
380+
for nrf.TEMP.EVENTS_DATARDY.Get() == 0 {
381+
}
382+
temp := int32(nrf.TEMP.TEMP.Get()) * 250 // the returned value is in units of 0.25°C
383+
nrf.TEMP.EVENTS_DATARDY.Set(0)
384+
return temp
385+
}

0 commit comments

Comments
 (0)