diff --git a/module/cores/arduino/port_sam/core_digital.c b/module/cores/arduino/port_sam/core_digital.c index 0b931ee..771e618 100644 --- a/module/cores/arduino/port_sam/core_digital.c +++ b/module/cores/arduino/port_sam/core_digital.c @@ -32,9 +32,9 @@ void pinMode( uint32_t ulPin, PinMode ulMode ) if ( (ulMode == INPUT) || (ulMode == INPUT_PULLUP) || (ulMode == INPUT_PULLDOWN) ) { - /* if all pins are OUTPUT, enable PIO Controller clocking */ - if ( Ports[g_aPinMap[ulPin].iPort].pGPIO->PIO_OSR == 0xffffffff ) - { + /* check if PIO is already clocked */ + if (!(PMC->PMC_PCSR0 & (1 << Ports[g_aPinMap[ulPin].iPort].ulId))) + { // if (Ports[g_aPinMap[ulPin].iPort].ulId < 32) { PMC->PMC_PCER0 = 1 << Ports[g_aPinMap[ulPin].iPort].ulId;