mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-20 12:29:03 +00:00
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.
This commit is contained in:
committed by
Ron Evans
parent
70b3ece6ec
commit
a68f7e4ce3
@@ -372,3 +372,14 @@ func GetRNG() (ret uint32, err error) {
|
|||||||
|
|
||||||
return ret, nil
|
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
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user