I am struggling with the exact same problem, and have posted a question on how to keep GPIOs high during (any) sleep.
I write to the registers as named in the document "ESP8266_Pin_List_0" from Espressif web.
(If these adresses are correct, GPIO0 would be defined the same way with #define gpio0Register 0x60000840 )
My code as follows is executed:
#define gpio4Register 0x6000083C
#define gpio5Register 0x60000840
#define sleepHighPullUp 0x8B // value to to pull the pin high during sleep.
char* gpio4 = (char*)gpio4Register;
char* gpio5 = (char*)gpio5Register;
char gpio4Byte;
char gpio5Byte;
void setup() {
gpio4Byte = gpio4[0];
gpio5Byte = gpio5[0];
sprintf((char*)registerContent, "Content of gpio4Register %p is %2X", gpio4, gpio4Byte);
Serial.println((char*)registerContent);
sprintf((char*)registerContent, "Content of gpio5Register %p is %2X", gpio5, gpio5Byte);
Serial.println((char*)registerContent);
if ((gpio4Byte & sleepHighPullUp) == 0x0) {
uint32_t volatile * const gpio4_reg = (uint32_t *) gpio4Register;
*gpio4_reg = (gpio4[0] | sleepHighPullUp);
// write in a new value with sleepHighPullUp active
Serial.print("We have updated gpio4Register to ");
Serial.println(gpio4[0] | sleepHighPullUp);
}
if ((gpio5Byte & sleepHighPullUp) == 0x0) {
int volatile * const gpio5_reg = (int *) gpio5Register;
*gpio5_reg = (gpio5[0] | sleepHighPullUp);
// write in a new value with sleepHighPullUp active
Serial.print("We have updated gpio5Register to ");
Serial.println(gpio5[0] | sleepHighPullUp);
// write in a new value with sleepHighPullUp active
}
gpio4Byte = gpio4[0];
gpio5Byte = gpio5[0];
sprintf((char*)registerContent, "Content of gpio4Register %p is %2X", gpio4, gpio4Byte);
Serial.println((char*)registerContent);
sprintf((char*)registerContent, "Content of gpio5Register %p is %2X", gpio5, gpio5Byte);
Serial.println((char*)registerContent);
void loop() {
Serial.println("Go to sleep. Good night...");
ESP.deepSleep(delayTime * 1000); // delayTime is ms
}
The output is:
Content of gpio4Register 0x6000083c is 0
Content of gpio5Register 0x60000840 is 0
We have updated gpio4Register to 139
We have updated gpio5Register to 139
Content of gpio4Register 0x6000083c is 8B
Content of gpio5Register 0x60000840 is 8B
sta config unchangedscandone
?STUB: dhcp_stop
Go to sleep. Good night...
Content of gpio4Register 0x6000083c is 0
Content of gpio5Register 0x60000840 is 0
We have updated gpio4Register to 139
We have updated gpio5Register to 139
Content of gpio4Register 0x6000083c is 8B
Content of gpio5Register 0x60000840 is 8B
sta config unchangedscandone
?STUB: dhcp_stop
.. and so on
On my oscilloscope, deeep sleep is low current (there are some circuits in addition to the Wemos d1 mini on my board, and I read 5 mA). But, GPIOs still go to 0 during sleep.
Best regards
Per