From cd1b23ff38ee3117268ded59ed5b6f1575786911 Mon Sep 17 00:00:00 2001 From: Zhitao He Date: Wed, 9 Jan 2019 14:02:01 +0100 Subject: [PATCH 1/2] fix temperature sensor reading in nrf52dk platform, which was stuck at zero --- arch/platform/nrf52dk/dev/temperature-sensor.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/arch/platform/nrf52dk/dev/temperature-sensor.c b/arch/platform/nrf52dk/dev/temperature-sensor.c index 5aac8b3ef..3af30c4af 100644 --- a/arch/platform/nrf52dk/dev/temperature-sensor.c +++ b/arch/platform/nrf52dk/dev/temperature-sensor.c @@ -64,7 +64,15 @@ static int value(int type) { #ifndef SOFTDEVICE_PRESENT - return nrf_temp_read(); + int32_t volatile temp; + + NRF_TEMP->TASKS_START = 1; + while(NRF_TEMP->EVENTS_DATARDY == 0); + NRF_TEMP->EVENTS_DATARDY = 0; + temp = nrf_temp_read(); + NRF_TEMP->TASKS_STOP = 1; + + return temp; #else int32_t temp; sd_temp_get(&temp); From d0a0a2a568eff152ed1f3b964d53f8b3eee12434 Mon Sep 17 00:00:00 2001 From: Zhitao He Date: Thu, 10 Jan 2019 18:56:27 +0100 Subject: [PATCH 2/2] busy wait maximum 72 us (typically 36 us) for taking a measurement from the on-chip temperature sensor --- arch/platform/nrf52dk/dev/temperature-sensor.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/platform/nrf52dk/dev/temperature-sensor.c b/arch/platform/nrf52dk/dev/temperature-sensor.c index 3af30c4af..f42fd3fe3 100644 --- a/arch/platform/nrf52dk/dev/temperature-sensor.c +++ b/arch/platform/nrf52dk/dev/temperature-sensor.c @@ -67,7 +67,8 @@ value(int type) int32_t volatile temp; NRF_TEMP->TASKS_START = 1; - while(NRF_TEMP->EVENTS_DATARDY == 0); + /* nRF52832 datasheet: one temperature measurement takes typically 36 us */ + RTIMER_BUSYWAIT_UNTIL(NRF_TEMP->EVENTS_DATARDY, RTIMER_SECOND * 72 / 1000000); NRF_TEMP->EVENTS_DATARDY = 0; temp = nrf_temp_read(); NRF_TEMP->TASKS_STOP = 1;