From c59d05fc501792a5bf9c32855cd32a52afc00c71 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Mon, 1 Mar 2021 14:47:50 +0100 Subject: [PATCH] saadc: Clear events_calibratedone before calibration Without this, if you initialize SAADC for a second time, the events_calibratedone is still set from before, so the while loop doesn't wait for calibration to be done. This causes garbage readings if you read immediately after, because calibration is still running. --- nrf-hal-common/src/saadc.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/nrf-hal-common/src/saadc.rs b/nrf-hal-common/src/saadc.rs index 505fa7e7..cdf048a7 100644 --- a/nrf-hal-common/src/saadc.rs +++ b/nrf-hal-common/src/saadc.rs @@ -87,6 +87,7 @@ impl Saadc { saadc.ch[0].pseln.write(|w| w.pseln().nc()); // Calibrate + saadc.events_calibratedone.reset(); saadc.tasks_calibrateoffset.write(|w| unsafe { w.bits(1) }); while saadc.events_calibratedone.read().bits() == 0 {}