Yesterday I tried to read PORTD port register on an Arduino Mega2560. I found some docs saying that this port is mapped from the pin 38 to 45. I wrote the following program to read this port, but if I change any value in those pins, no value is changed at PORTB port register. Any advices?
/
//read_rom.ino
void setup() {
DDRD = 0x00; // All pins in PORTD are inputs
PORTD = 0xFF; // Pull-ups enabled in all pins at PORTD
Serial.begin(115200);
}
void loop() {
Serial.println();
Serial.println(PIND, HEX);
delay(30);
}
PB0:7 are processor pins 19-26 and PD0:7 are processor pins 43-50.
but if I change any value in those pins, no value is changed at PORTB port register
You also need to understand the relationship between the physical pins on the processor and the pins on the Arduino board. Are you changing the PORTX pin values as outputs in your code? If so, reading PORTX should reflect the changes, but that is a pretty useless exercise. It sounds as if you may be trying to read the state of the pins as inputs in which case the syntax is PINX. The physical pins on the board which map to that register are not the same as the chip pins.
You also need to understand the relationship between the physical pins on the processor and the pins on the Arduino board. Are you changing the PORTX pin values as outputs in your code? If so, reading PORTX should reflect the changes, but that is a pretty useless exercise. It sounds as if you may be trying to read the state of the pins as inputs in which case the syntax is PINX. The physical pins on the board which map to that register are not the same as the chip pins.
I know the relationship between physical pins and the pins on the board. The PORTD is used as input with pull-ups enabled. That's not an exercise, I need that to read an output from an EPROM with 8 outputs ports.
I just need to know the pins on the board, not the physical pins on the MCU.