Skip to content

Commit 21c3660

Browse files
committed
This commit fixes the issue arduino#2198:
If an analog input is used and during the sketch modified in a digitalOutput the pinMode(AX, OUTPUT) isn't sensed because of this line of codes: wiring_analog.c line 135 // Enable the corresponding channel if (ulChannel != latestSelectedChannel) { adc_enable_channel( ADC, ulChannel ); if ( latestSelectedChannel != (uint32_t)-1 ) adc_disable_channel( ADC, latestSelectedChannel ); latestSelectedChannel = ulChannel; The channel is infact enabled only if different from the previous one because of speed problems. With my patch: when pinMode(PIN, OUTPUT) is declared a control about if the pin is an analog one is done and if so the ADC is released when pinMode(PIN, INPUT) is declared a control is as well done in order to enable the ADC.
1 parent 6c4f7dc commit 21c3660

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

hardware/arduino/sam/cores/arduino/wiring_digital.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ extern void pinMode( uint32_t ulPin, uint32_t ulMode )
3232
switch ( ulMode )
3333
{
3434
case INPUT:
35+
#if defined __SAM3X8E__ || defined __SAM3X8H__
36+
37+
if(g_APinDescription[ulPin].ulPinType != NO_ADC)
38+
adc_enable_channel( ADC, g_APinDescription[ulPin].ulADCChannelNumber);
39+
#endif
40+
3541
/* Enable peripheral for clocking input */
3642
pmc_enable_periph_clk( g_APinDescription[ulPin].ulPeripheralId ) ;
3743
PIO_Configure(
@@ -52,6 +58,12 @@ extern void pinMode( uint32_t ulPin, uint32_t ulMode )
5258
break ;
5359

5460
case OUTPUT:
61+
#if defined __SAM3X8E__ || defined __SAM3X8H__
62+
63+
if(g_APinDescription[ulPin].ulPinType != NO_ADC)
64+
adc_disable_channel( ADC, g_APinDescription[ulPin].ulADCChannelNumber);
65+
#endif
66+
5567
PIO_Configure(
5668
g_APinDescription[ulPin].pPort,
5769
PIO_OUTPUT_1,

0 commit comments

Comments
 (0)