From 4ee26fd54bc1a247e975d193ceb895d0e59eb83f Mon Sep 17 00:00:00 2001 From: Ron Evans Date: Fri, 6 Sep 2019 12:44:28 +0200 Subject: [PATCH] machine/atsamd21: correct issue with invalid first reading coming from ADC Signed-off-by: Ron Evans --- src/machine/machine_atsamd21.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/machine/machine_atsamd21.go b/src/machine/machine_atsamd21.go index d0b26e5e..efd21e22 100644 --- a/src/machine/machine_atsamd21.go +++ b/src/machine/machine_atsamd21.go @@ -192,6 +192,11 @@ func (a ADC) Get() uint16 { sam.ADC.SWTRIG.SetBits(sam.ADC_SWTRIG_START) waitADCSync() + // wait for first conversion to finish to fix same issue as + // https://github.com/arduino/ArduinoCore-samd/issues/446 + for !sam.ADC.INTFLAG.HasBits(sam.ADC_INTFLAG_RESRDY) { + } + // Clear the Data Ready flag sam.ADC.INTFLAG.SetBits(sam.ADC_INTFLAG_RESRDY) waitADCSync()