Wemos D1 PORTD Equivalent

Gentlemen,
I am using an Arduino UNO to produce an 8-bit digital signal using PORTD with the following code:

//Arduino UNO @ 3.97MHz!
//8bit output, pins D0 to D7

void setup() {
  DDRD=255;
}

void loop() {
  while(true){
    PORTD=255;
    PORTD=0;
  }
}

I am trying to do the same thing with a WEMOS D1 R2, but my knowledge of electronics is too limited to understand its documentation. I know that the digital pins are handled differently, and there is no defined PORTD to access. And I haven't found a forum post with working code and a clear explanation. This is where I'm at currently:

//THIS IS A FAILED ATTEMPT TO WRITE 8 PINS SIMULTANEOUSLY ON WEMOS-D1-R2

#include <ESP8266WiFi.h>
#include <user_interface.h>
#include <Arduino.h>

//Wemos pin labels
#define D0 16
#define D1 5
#define D2 4
#define D3 0
#define D4 2
#define D5 14
#define D6 12
#define D7 13
#define D8 15

void setup() {
  WiFi.forceSleepBegin();                                            
  system_update_cpu_freq(160);

  //There is probably a better way to do this:
  pinMode(D0,OUTPUT);
  pinMode(D1,OUTPUT);
  pinMode(D2,OUTPUT);
  pinMode(D3,OUTPUT);
  pinMode(D4,OUTPUT);
  pinMode(D5,OUTPUT);
  pinMode(D6,OUTPUT);
  pinMode(D7,OUTPUT);
  pinMode(D8,OUTPUT);
}

void loop() {
  while(true){
    WRITE_PERI_REG(PERIPHS_GPIO_BASEADDR,255);
    WRITE_PERI_REG(PERIPHS_GPIO_BASEADDR,0);
  };
}

If I use the while() loop to speed things up, I am only getting signal on pin D3 (but @ 26MHz.)
If I comment out the while() loop, I get signal on pins D1, D2, D3, and D4 @ 338kHz.
At least, that's what the auto-ranging o-scope is telling me.

Since I only have a vague idea of what these write commands are doing, I'm not surprised this isn't working. With that said, what needs to change to write 8 bits of data to 8 pins at once?

First of all, D0 - D8 is 9 bits you’re trying to change, not 8.

Next, don’t do this:

#define D0 16
#define D1 5
#define D2 4
#define D3 0
#define D4 2
#define D5 14
#define D6 12
#define D7 13
#define D8 15

because it changes constants that are already defined in the core files.

Next, look in ‘core_esp8266_wiring_digital.c’ to see how the digital_write() function works and in ‘esp8266_peri.h’ to see the register definitions. You’ll see that Pin 16 is in a different register than the others. So, you can’t change it at the same time.

So, the following may work. I only specified 8 bits, not your original 9. The code compiles but is untested.

#include "Arduino.h"

const uint8_t bit1 = 5;
const uint8_t bit2 = 4;
const uint8_t bit3 = 0;
const uint8_t bit4 = 2;
const uint8_t bit5 = 14;
const uint8_t bit6 = 12;
const uint8_t bit7 = 13;
const uint8_t bit8 = 15;

const uint32_t pinBits = (1 << bit1) | (1 << bit2) | (1 << bit3) | (1 << bit4)
		| (1 << bit5) | (1 << bit6) | (1 << bit7) | (1 << bit8);

void setup() {
	  pinMode(bit1,OUTPUT);
	  pinMode(bit2,OUTPUT);
	  pinMode(bit3,OUTPUT);
	  pinMode(bit4,OUTPUT);
	  pinMode(bit5,OUTPUT);
	  pinMode(bit6,OUTPUT);
	  pinMode(bit7,OUTPUT);
	  pinMode(bit8,OUTPUT);
}

void loop() {
	GPO = GPO | pinBits;
	GPO = GPO & ~pinBits;
}

This might work also, again untested.

#include "Arduino.h"

const uint8_t bit1 = 5;
const uint8_t bit2 = 4;
const uint8_t bit3 = 0;
const uint8_t bit4 = 2;
const uint8_t bit5 = 14;
const uint8_t bit6 = 12;
const uint8_t bit7 = 13;
const uint8_t bit8 = 15;

const uint32_t pinBits = (1 << bit1) | (1 << bit2) | (1 << bit3) | (1 << bit4)
		| (1 << bit5) | (1 << bit6) | (1 << bit7) | (1 << bit8);

void setup() {
	pinMode(bit1, OUTPUT);
	pinMode(bit2, OUTPUT);
	pinMode(bit3, OUTPUT);
	pinMode(bit4, OUTPUT);
	pinMode(bit5, OUTPUT);
	pinMode(bit6, OUTPUT);
	pinMode(bit7, OUTPUT);
	pinMode(bit8, OUTPUT);
}

void loop() {
	GPOS = pinBits;
	GPOC = pinBits;
}

Thank you, your code appears to work perfectly. I don't understand it yet, but I'll review the libraries you mentioned to get a better idea of what is going on.

I do only need 8 pins; I set up 9 because those were the only ones labeled on my board and I wasn't sure where the output would go.