Skip to content

Commit a1c4809

Browse files
committed
[sam] Fixed regression in analogRead() (fails to read multiple channels)
Fixes #1740
1 parent 2e7b645 commit a1c4809

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

build/shared/revisions.txt

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ ARDUINO 1.5.6 BETA
1010

1111
[core]
1212
* sam: Fixed wrap-around bug in delay() (Mark Tillotson)
13+
* sam: Fixed regression in analogRead() (fails to read multiple channels)
1314

1415
ARDUINO 1.5.5 BETA 2013.11.28
1516

hardware/arduino/sam/cores/arduino/wiring_analog.c

+4-5
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,10 @@ uint32_t analogRead(uint32_t ulPin)
149149

150150
// Enable the corresponding channel
151151
if (ulChannel != latestSelectedChannel) {
152-
adc_enable_channel( ADC, ulChannel );
153-
latestSelectedChannel = ulChannel;
152+
if ( latestSelectedChannel != -1 )
153+
adc_disable_channel( ADC, latestSelectedChannel );
154+
adc_enable_channel( ADC, ulChannel );
155+
latestSelectedChannel = ulChannel;
154156
}
155157

156158
// Start the ADC
@@ -164,9 +166,6 @@ uint32_t analogRead(uint32_t ulPin)
164166
ulValue = adc_get_latest_value(ADC);
165167
ulValue = mapResolution(ulValue, ADC_RESOLUTION, _readResolution);
166168

167-
// Disable the corresponding channel
168-
//adc_disable_channel(ADC, ulChannel);
169-
170169
break;
171170

172171
// Compiler could yell because we don't handle DAC pins

0 commit comments

Comments
 (0)