Port manipulation UNO: Issue

Hi all,

I am using an Arduino UNO WIFI Rev2 (Atmel Mega 4809) for my project to alter the output state of a pin via port manipulation. I have a multimeter connected to Pin 8, monitoring the state of the pin. After executing this code, as given below, I expected the voltage to toggle between 5 and 0 v every 1 s. Unfortunately, it was not happening! Something is wrong with my code, since it is working properly if I use the digital write command. Just a note: this code complied properly. Any help to fix it will be useful.

-Ac

void setup() {
   pinMode(8, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {

  VPORTB.OUT = VPORTB.IN & B1111110;
  delay(1000); 
  VPORTB.OUT = VPORTB.IN | B00000001;
  delay(1000);                     
}

Did it happen with the LED on the pin?

VPORT ?
Something new ?
Does the UNO WIFI use the UNO PORT arrangement ?

You don't need to read the input.

void loop() {
  VPORTB.OUT &= B11111110;
  delay(1000); 
  VPORTB.OUT |= B00000001;
  delay(1000);
}

HTH

a7

Please be accurate; there is a difference between an Arduino Uno WiFi (which is 328P based) and an Arduino Uno WiFi Rev2 (which is 4809 based). Your code indicates the latter.

1 Like

Assuming UNO WIFI Rev2, pinMode(8, OUTPUT); sets PE3 as output.
You’re toggling PB0. It’s not the same pin.

Thanks @stitech!
Updated code is attached for the rest of community who may face similar trouble.

@stitech
I found port maps for Atmega168 and Atmega8
I could not find maps for Atmega4809. Suggestions?

void setup() {
   pinMode(8, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  VPORTE.OUT &= B11110111;
  delay(1000); 
  VPORTE.OUT |= B00001000;
  delay(1000);                    // wait for a second
}

And and UNO-R4 WiFi which has a Renesas chip.

Try: https://ww1.microchip.com/downloads/aemDocuments/documents/MCU08/ProductDocuments/DataSheets/ATmega4808-09-DataSheet-DS40002173C.pdf
It doesn't contain a map, but it contains everything you need.

The schematic is your friend :wink: Relevant part

1 Like

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