From a1c48091051bfc7f3366cac6fc23212c4e4fb4a3 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 16 Dec 2013 11:06:34 +0100 Subject: [PATCH] [sam] Fixed regression in analogRead() (fails to read multiple channels) Fixes #1740 --- build/shared/revisions.txt | 1 + hardware/arduino/sam/cores/arduino/wiring_analog.c | 9 ++++----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/build/shared/revisions.txt b/build/shared/revisions.txt index e0fdfc972..28022ccbc 100644 --- a/build/shared/revisions.txt +++ b/build/shared/revisions.txt @@ -10,6 +10,7 @@ ARDUINO 1.5.6 BETA [core] * sam: Fixed wrap-around bug in delay() (Mark Tillotson) +* sam: Fixed regression in analogRead() (fails to read multiple channels) ARDUINO 1.5.5 BETA 2013.11.28 diff --git a/hardware/arduino/sam/cores/arduino/wiring_analog.c b/hardware/arduino/sam/cores/arduino/wiring_analog.c index efb5e6f46..184220f9e 100644 --- a/hardware/arduino/sam/cores/arduino/wiring_analog.c +++ b/hardware/arduino/sam/cores/arduino/wiring_analog.c @@ -149,8 +149,10 @@ uint32_t analogRead(uint32_t ulPin) // Enable the corresponding channel if (ulChannel != latestSelectedChannel) { - adc_enable_channel( ADC, ulChannel ); - latestSelectedChannel = ulChannel; + if ( latestSelectedChannel != -1 ) + adc_disable_channel( ADC, latestSelectedChannel ); + adc_enable_channel( ADC, ulChannel ); + latestSelectedChannel = ulChannel; } // Start the ADC @@ -164,9 +166,6 @@ uint32_t analogRead(uint32_t ulPin) ulValue = adc_get_latest_value(ADC); ulValue = mapResolution(ulValue, ADC_RESOLUTION, _readResolution); - // Disable the corresponding channel - //adc_disable_channel(ADC, ulChannel); - break; // Compiler could yell because we don't handle DAC pins