ESP32 Always Reseting with simple code

Hello,
I have a ESP32- WROOM-32D (30pin) with CH340.

My problem is that even with simple code it is making a continue reset. I have another ESP32 unit and it's giving the same problem.

I tried a complex code and gave me the problem, then I tried this simple code:

void setup() {
  Serial.begin(9600);
  Serial1.begin(9600);
}

void loop() {
  if (Serial1.available()) {
    String input = Serial1.readStringUntil('\n');
    Serial.println(input);
  }

  // Feed the watchdog
  delay(1);
}

and still the same continues error:

rst:0x8 (TG1WDT_SYS_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:0x3fff0030,len:1344
load:0x40078000,len:13964
load:0x40080400,len:3600
entry 0x400805f0

At this point, I don't have ANY pins connected, just USB connected.

Tested with several different cables.
Tested with different USB ports

Always same issue.

Any clues??

Regards!

The reason is that by default, UART 1 uses the same pins as the ESP32 flash memory

watch

1 Like

Perfect J-M-L. Just change to serial2 !!

Thank you very much for your help

you can change the Serial1 pin mapping, e.g.

#define RXD1 16
#define TXD1 17

void setup() {
  // initialize both serial ports:
  Serial.begin(115200);
  Serial1.begin(115200, SERIAL_8N1, RXD1, TXD1);

glad it helped

Thank you Horace

The above is useless. Simply returning rom loop() "feeds" the watchdog.

@gpfvb

I hope, I have something to add to bring a vsual picture of what has been discussed in the above.

1. In Fig-1 below, there are no marked signals as U1_TXD/U1_RXD for UART1 like UO_TXD/RXD and U2_TXD/RXD. The UART0 is connected with Serial Monitor and UART2 is free with which you could connect your 2nd UART device.


Figure-1:

2. Then from where have you got the inspiration of connecting your second UART device using Serial1 (UART1)? Have your really connected your 2nd UART device with your ESP32 Dev Board? If yes, then which digital pins of ESP32 Board have you used?

3. Ok! There are UART0 and UART2 ports; so, there must be a UART1 (Serial1) port. Let us see where it is hiding.

(1) The data sheet (Fig-2) shows that the ESP32 Core has a UART1 Port whose outputs (U1TXD/U1RXD) are available at PPin (Physical Pin) - 10 and 9 respectively. It has been told in the video referred by @J-M-L in post #2.


Figure-2:

(2) The following diagram (Fig-3 taken from Schematic Diagram of ESP2 MCU Module) shows that the PPin (Physical Pin)-10 and 9 are permannetly connected with the off-chip Flash Memory of the ESP32 MCU. This is the reason that ESP32 Dev Board has not explicity shown the UART1 Port in Fig-1.

In fact UART1 is not useable; because, if we want to use with the arrangement of Fig-4 to operate UART1, the Flash will be disconnected disconnected; as a result, the MCU will immediately crash as the Flash Memory contains the the application program which is no longer available to the MCU for execution.

ESP32Flash
Figure-3:

4. Just for test purpose, we may try to operate UART1 (Fig-4) and see that the MCU indeed crashes! UART1's output are directed to the free DIO pins 4 and 5) of ESP32 Dev Board.


Figure-4:

Sketch:

void setup()
{
    Serial.begin(9600);
    Serial1.begin(9600, SERIAL_8N1, 4, 5);  //RX1 = DPin-4, TX1 = Dpin-5
}

void loop()
{
    Serial.println("UAR1 is available.");
    delay(1000);
}
1 Like

Hi GolamMostafa, thank you for your explanation, perhaps you can help me with a similar issue on a ESP32-CAM, I saw a sketch in ESP32 CAM / Data sheets | Modélisme ferroviaire par NitraThor, I can see only a U2RXD pin, but no U2TXD. How should I proceed in my case, to avoid the reboot problem? Thanks in advance

1. In the ESP32-CAM Board, there is U2RXD (16)-pin. You want U2TXD pin of the internal Serial2 to be available at a suitable DPin (IO pin) of the CAM Module.

2. Let us assime that DPin-15 (IO15) is free in your CAM Module, Now, we can include the following code in the sketch to establish U2RXD at DPin-16 and U2TXD at DPin-15.

#define U2RXD 16
#define U2TXD 15
Serial2.begin(9600, SERIAL_8N1, U2RXD, U2TXD);

3. Test Sketch (tested)
(1) Upload the following sketch into ESP32-CAM Module using ESP32-CAM-MB Adapter.

#define LED1 33  //onboard LED of ESP32-CAM  
#define U2RXD 16
#define U2TXD 15

void setup()
{
  Serial.begin(9600);
  pinMode(LED1, OUTPUT);
  Serial2.begin(9600, SERIAL_8N1, U2RXD, U2TXD);
}

void loop()
{
  byte n = Serial2.available();
  if ( n != 0)
  {
    byte m = Serial2.read();
    for (int i = 0; i < m; i++)
    {
      //--------------------------------
      digitalWrite(LED1, HIGH);
      delay(1000);
      digitalWrite(LED1, LOW);
      delay(1000);
      //--------------
    }
  }
  Serial2.println("Hello");
  digitalWrite(LED1, HIGH);
  delay(3000);
  digitalWrite(LED1, LOW);
  delay(3000);   
}

(2) Disconnect MB board from CAM board.
(3) Connect CAM board and Arduino UNO as per Fig-1 using level shifter.


Figure-1:

(4) Upload the following sketch in ARduino UNO.

#include<SoftwareSerial.h>
SoftwareSerial SUART(10, 11);   //SRX, STX
#define LED1 13

void setup()
{
  Serial.begin(9600);
  SUART.begin(9600);
  pinMode(LED1, OUTPUT);
}

void loop()
{
  while(SUART.available()> 0)
  {
    Serial.print((char)SUART.read());
  }
  SUART.write(0x03);
  delay(5000);
}

(5) Press RESET Buttons of both CAM and UNO.
(6) Check that onboard LED of CAM makes three consecutive blinks indicating that it has recieved 3 from UNO. After that the onboard LED of CAM makes one blink with 3-sec on/off period.

(7) Open Serial Monitor of UNO and check that Hello is prinited in evevry 8-sec interval. It indicates thet UNO has received the message Hello from CAM.

Thank you for your answer GolamMostafa, but I don't have a ESP32-CAM-MB card, I was working with a USB to serial adapter. Is there a way to redefine the serial pins for the next boot in order to work with your code? Thanks again

As I could never manage to upload sketch into my CAM using USB/RS232TTL, I found MB adapter good enough to solve my upload issue.

My sketch should always work regardless of uploading method.

Hi GolamMostafa, I got your sketch working with the usb serial adapter, I check the Flash mode = DIO (no QIO, because it didn't work). Besides that, Board AI Thinker ESP32-CAM, CPU Frequency 240 MHz, Flash Frequency 80 MHz, Partition Scheme Huge APP( 3MB no OTA / 1MB SPIFFS ).
But I can't get working the example CameraWebServer. It still is rebooting all the time.

DIO solved my problem. Thanks