Skip to content

Commit a38e764

Browse files
committed
[sam] Fixed regression in analogRead() (fails to read multiple channels)
Fixes arduino#1740
1 parent 9be7c15 commit a38e764

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

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)