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?
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.
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.