Software ESP32 restart ( ESP.restart()) doesn't seems to fully reset the hardware
Posted: Sun Mar 11, 2018 1:58 pm
With the following script I am using the Hardware Serial interfaces.
Practically the simplified script shown below, uses a Nextion LCD display that connects via the Hardware interface 2.
The script ((see below) writes and reads a Nextion HMI variable, through the hardware interface 2 (pin 16=RX, pin 17=TX baud rate 9600).
In a more elaborate script I am using the ESP.restart() call to reset the ESP32 (WEMOS LOLIN32) after reconfiguration, however I need to physically restart the ESP to let the hardware interface work again,
the software restart seems to leave the hardware interface in a unknown state.
The simplified script below writes and reads 5 times back the data stored by the Nextion MCU.
The result shows that everything is fine until the "software restart" occurs, only a physical restart or firmware reloads solves the problem
- !!!!! 1. Loading the script
⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮ets Jun 8 2016 00:22:57
rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:812
load:0x40078000,len:0
load:0x40078000,len:11392
entry 0x40078a9c
recvRetCommandFinished ok <-- Nextion Init is OK
recvRetCommandFinished ok
Doing Nextion Communication test <-- Communication test 1 is OK
Now updating COMMV1 value
recvRetCommandFinished ok
recvRetNumber :319
Nextion test is OK
Doing Nextion Communication test <-- Communication test 2 is OK
Now updating COMMV1 value
recvRetCommandFinished ok
recvRetNumber :267
Nextion test is OK
Doing Nextion Communication test <-- Communication test 3 is OK
Now updating COMMV1 value
recvRetCommandFinished ok
recvRetNumber :697
Nextion test is OK
Doing Nextion Communication test <-- Communication test 4 is OK
Now updating COMMV1 value
recvRetCommandFinished ok
recvRetNumber :779
Nextion test is OK
Doing Nextion Communication test <-- Communication test 5 is OK
Now updating COMMV1 value
recvRetCommandFinished ok
recvRetNumber :29
Nextion test is OK
!!!! 2. ESP.restart()
ets Jun 8 2016 00:22:57
rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:812
load:0x40078000,len:0
load:0x40078000,len:11392
entry 0x40078a9c
recvRetCommandFinished err <-- Nextion Init is NOK
recvRetCommandFinished err
Doing Nextion Communication test <-- Communication test 1 is NOK
Now updating COMMV1 value
recvRetCommandFinished err
recvRetNumber err
Nextion test FAILED
653
0
Doing Nextion Communication test <-- Communication test 2 is NOK
Now updating COMMV1 value
recvRetCommandFinished err
recvRetNumber err
Nextion test FAILED
352
1073488868
Doing Nextion Communication test <-- Communication test 3 is NOK
Now updating COMMV1 value
recvRetCommandFinished err
recvRetNumber err
Nextion test FAILED
200
1073488868
Doing Nextion Communication test <-- Communication test 4 is NOK
Now updating COMMV1 value
recvRetCommandFinished err
recvRetNumber err
Nextion test FAILED
58
1073488868
Doing Nextion Communication test <-- Communication test 5 is NOK
Now updating COMMV1 value
recvRetCommandFinished err
recvRetNumber err
Nextion test FAILED
739
1073488868
!!! 3. Hardware reset
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
ets Jun 8 2016 00:22:57
rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:812
load:0x40078000,len:0
load:0x40078000,len:11392
entry 0x40078a9c
recvRetCommandFinished err
recvRetCommandFinished ok <-- Nextion Init is OK
Doing Nextion Communication test <-- Communication test 1 is OK
Now updating COMMV1 value
Now updating COMMV1 value
recvRetCommandFinished ok
recvRetNumber :976
Nextion test is OK
Doing Nextion Communication test <-- Communication test 2 is OK
Now updating COMMV1 value
Now updating COMMV1 value
recvRetCommandFinished ok
recvRetNumber :114
Nextion test is OK
Doing Nextion Communication test <-- Communication test 3 is OK
Now updating COMMV1 value
Now updating COMMV1 value
recvRetCommandFinished ok
recvRetNumber :761
Nextion test is OK
Doing Nextion Communication test <-- Communication test 4 is OK
Now updating COMMV1 value
Now updating COMMV1 value
recvRetCommandFinished ok
recvRetNumber :855
Nextion test is OK
.....
Code: Select all
#include "Nextion.h" // Include Nextion library
HardwareSerial Serial2(2); // Default pins for Wemos Lolin32 are pin 16=RX, pin 17=TX baud rate 9600
long int nexPollTime; // USed to collected itermediate time
NexVariable COMMV1 = NexVariable (0,23,"COMMV1"); // Nextion Communication watchdog variable
#define DEBUGGING
void setup() {
nexInit (); // Init the nextion communication (typically Serial 2 interface @9600 bps)
delay (100); // Settle down delay
}
void loop() {
// Call 5 times the Nextion befor restart
for (int i = 0; i <5; i++)
{
nexCommCheck (0); // Check the Nextion connection immediately
delay (1000); // Wait 1 second
}
ESP.restart(); // Then restart the WeMos
}
void nexCommCheck (int long pollRate)
{
if (millis()>nexPollTime+pollRate)
{
#ifdef DEBUGGING
Serial.println ("\nDoing Nextion Communication test") ;
#endif
nexPollTime = millis();
uint32_t setvalue = random (1000);
uint32_t getvalue;
#ifdef DEBUGGING
Serial.println ("Now updating COMMV1 value");
#endif
COMMV1.setValue (setvalue);
COMMV1.getValue (&getvalue);
if (getvalue == setvalue) // Nextion Write check
{
#ifdef DEBUGGING
Serial.println ("Nextion test is OK");
#endif
}
else
{
#ifdef DEBUGGING
Serial.println ("Nextion test FAILED");
Serial.println (setvalue);
Serial.println (getvalue);
#endif
}
}
}