The following simple sketch will blink the following:
Compiles and runs on: Uno (R1 I think), Leonardo, and Mega 1280
void setup() {
// put your setup code here, to run once:
pinMode(13, OUTPUT);
}
uint8_t counter = 0;
void loop() {
// put your main code here, to run repeatedly:
counter++;
uint8_t portb_val = PINB;
if (counter & 1) portb_val |= (1 << 5);
else portb_val &= ~(1 << 5);
PORTB = portb_val;
delay(250);
}
And on the original UNO it blinks the LED.
But it fails to compile on the UNO R4 boards.
C:\Users\kurte\AppData\Local\Temp\.arduinoIDE-unsaved2023622-68696-1r9b6fh.1q52\sketch_jul22a\sketch_jul22a.ino: In function 'void loop()':
C:\Users\kurte\AppData\Local\Temp\.arduinoIDE-unsaved2023622-68696-1r9b6fh.1q52\sketch_jul22a\sketch_jul22a.ino:10:23: error: 'PINB' was not declared in this scope
uint8_t portb_val = PINB;
^~~~
C:\Users\kurte\AppData\Local\Temp\.arduinoIDE-unsaved2023622-68696-1r9b6fh.1q52\sketch_jul22a\sketch_jul22a.ino:10:23: note: suggested alternative: 'PIN'
uint8_t portb_val = PINB;
^~~~
PIN
C:\Users\kurte\AppData\Local\Temp\.arduinoIDE-unsaved2023622-68696-1r9b6fh.1q52\sketch_jul22a\sketch_jul22a.ino:13:3: error: 'PORTB' was not declared in this scope
PORTB = portb_val;
^~~~~
exit status 1
Compilation error: 'PINB' was not declared in this scope
Yes I know that this is not an AVR board. But personally since the board is called an UNO, I would expect code that basic code that runs on one UNO should run on another...
Also note: This same sketch compiles and runs on a Teensy boards. I just ran it on a Micromod. The Teensy cores do this, by emulating some of these key AVR registers with c++ classes.
cores/teensy4/avr_emulation.h at master · PaulStoffregen/cores (github.com)
Where I have seen several libraries that manipulate the port registers are display libraries for parallel ports... like 8 pins for data maybe 4 pins for address.
Not sure the best place or way to ask questions like this?
@ptillisch and others hopefully you will have insight into this.
For example, should it be asked here on the forum? Or as github issues? Is there a centralized place, that these are discussed? Like when converting your code from earlier UNO boards to the R4, here are the following things, that are not supported and the suggest way to implement it on the new board?
Hope this makes sense.