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
#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
#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);
}