Skip to content

Commit 0f3f80a

Browse files
committed
Only update pull-up value in digitalWrite if pin direction is not output
1 parent ba0488d commit 0f3f80a

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

cores/arduino/wiring_digital.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,10 @@ void digitalWrite( uint32_t ulPin, uint32_t ulVal )
8282
return ;
8383
}
8484

85-
// Enable pull-up resistor
86-
PORT->Group[g_APinDescription[ulPin].ulPort].PINCFG[g_APinDescription[ulPin].ulPin].reg=(uint8_t)(PORT_PINCFG_PULLEN) ;
85+
if ( (PORT->Group[g_APinDescription[ulPin].ulPort].DIRSET.reg & (1ul << g_APinDescription[ulPin].ulPin)) == 0 ) {
86+
// the pin is not an output, disable pull-up if val is LOW, otherwise enable pull-up
87+
PORT->Group[g_APinDescription[ulPin].ulPort].PINCFG[g_APinDescription[ulPin].ulPin].bit.PULLEN = (ulVal != LOW) ;
88+
}
8789

8890
switch ( ulVal )
8991
{

0 commit comments

Comments
 (0)