# Help with Port Manipulation on Arduino Due

**URL:** <https://forum.arduino.cc/t/help-with-port-manipulation-on-arduino-due/1290238>\
**Category:** Programming\
**Created:** [August 9, 2024, 5:31pm UTC](https://forum.arduino.cc/t/help-with-port-manipulation-on-arduino-due/1290238 "2024-08-09T17:31:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![GioTornado](https://avatars.discourse-cdn.com/v4/letter/g/c67d28/32.png) [@GioTornado](https://forum.arduino.cc/u/GioTornado)\
**Post date:** [August 9, 2024, 5:31pm UTC](https://forum.arduino.cc/t/help-with-port-manipulation-on-arduino-due/1290238/1 "2024-08-09T17:31:52Z")

</div>

I'm trying to understand port manipulation, and I am able to read ports perfectly fine, but when it comes to registering their mode, I get nothing. I have a wire in 43 and one in GND. When they connect, it should print "LOW"; anytime they are not connected it should print "HIGH". What is wrong with the setup in the second code block?  
This code worked fine

```arduino
#define port PIOA
#define pin PIO_PA20

void setup() {
  Serial.begin(9600);
  pinMode(43, INPUT_PULLUP);
}

void loop() {
  if (port->PIO_PDSR & pin) {
    Serial.println("HIGH");
  } 
  else {
    Serial.println("LOW");
  }
  delay(10);
}

```

but this code doesn't work and seems to not register the pin

```arduino
#define port PIOA
#define pin PIO_PA20

void setup() {
  Serial.begin(9600);
  
  port->PIO_PER = pin;
  port->PIO_ODR = pin;
  port->PIO_PUER = pin;
}

void loop() {
  if (port->PIO_PDSR & pin) {
    Serial.println("HIGH");
  } else {
    Serial.println("LOW");
  }
  delay(10);
}

```

---

<div class="post-metadata">

**Author:** ![westfw](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/westfw/32/213443_2.png) [@westfw](https://forum.arduino.cc/u/westfw)\
**Post date:** [August 10, 2024, 6:26am UTC](https://forum.arduino.cc/t/help-with-port-manipulation-on-arduino-due/1290238/2 "2024-08-10T06:26:29Z")

</div>

Did you enabled the peripheral clock for PIOA?

I'd think that would have already happened, but pinMode() does do it explicitly (using libsam functions, rather than "bare metal")

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [February 6, 2025, 6:27am UTC](https://forum.arduino.cc/t/help-with-port-manipulation-on-arduino-due/1290238/3 "2025-02-06T06:27:05Z")

</div>

Closed on February 6, 2025, 6:27am UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
