Skip to content

Commit 89d42ba

Browse files
committed
Use DIR register for pin direction checking
Replace DIRSET with DIR register when checking if a pin is configured as output in digitalWrite(). DIR is the designated register for reading current pin direction state. According to the SAMD21 datasheet, DIRSET is designed as a write-only register without guaranteed read behavior, while DIR explicitly represents the current direction state. Fixes arduino#727
1 parent 993398c commit 89d42ba

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

cores/arduino/wiring_digital.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ void digitalWrite( pin_size_t ulPin, PinStatus ulVal )
8383
uint32_t pin = g_APinDescription[ulPin].ulPin;
8484
uint32_t pinMask = (1ul << pin);
8585

86-
if ( (PORT->Group[port].DIRSET.reg & pinMask) == 0 ) {
86+
if ( (PORT->Group[port].DIR.reg & pinMask) == 0 ) {
8787
// the pin is not an output, disable pull-up if val is LOW, otherwise enable pull-up
8888
PORT->Group[port].PINCFG[pin].bit.PULLEN = ((ulVal == LOW) ? 0 : 1) ;
8989
}

0 commit comments

Comments
 (0)