Arduino IDE 1.8.19.
Platform: Arduino Micro and Arduino UNO (replacing PORTF with PORTD as UNO doesn't have PORTF..).
This sketch should simply make one shot writes to the higher nibbles on PORTB and PORTF.
The first writes work... the second nope (..and so the 3rd, the 4th, ...).
void setup() {
Serial.begin(115200);
while (! Serial);
DDRB = DDRB | 0b11110000; // high nibble as OUT
DDRF = DDRF | 0b11110000; // high nibble as OUT
// print initial PORTs state
Serial.print(F("PORTB,PORTF = "));
Serial.print(PORTB,HEX);Serial.print(",");Serial.println(PORTF,HEX);
//set PORTs to the desired values
PORTB |= 0x30;
PORTF |= 0x50;
//verify: OK
Serial.print(F("PORTB,PORTF = "));
Serial.print(PORTB,HEX);Serial.print(",");Serial.println(PORTF,HEX);
//set PORTs again with new values
PORTB |= 0x40;
PORTF |= 0x60;
//verify: FAILS!!
Serial.print(F("PORTB,PORTF = "));
Serial.print(PORTB,HEX);Serial.print(",");Serial.println(PORTF,HEX);
}
void loop() {
return;
}
The output is:
PORTB,PORTF = 1,0
PORTB,PORTF = 31,50
PORTB,PORTF = 71,70
Nothing changes if the code is run in loop().
Thank you for your help!
Emanuele.