XIAO ESP32C3 resets when serial connection is disconnected


I have a problem with the XIAO ESP32C3. When I open the serial monitor or establish a serial connction via python, everything is working fine, but when I close the serial monitor/connection the chip resets, the millis starting with 0 again.
For keeping track of time that’s not so helpful.
I could not observe this behavior with the XIAO SAMD21 nor with the XIAO BLE n52.

That’s the code for testing, but the code does not matter. It’s more a general behavior:
#include <Wire.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
int counter;
void setup() {
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F(“SSD1306 allocation failed”));
void loop() {
display.setTextColor(SSD1306_WHITE, SSD1306_BLACK);
display.setCursor(0, 20);

How can I prevent the chip from resetting.

Hello Svake,

I had the same behavior.
I changed the serial connection settings. I’m referring to the parameters related to the “control”:

  1. none
  2. RTS/CTS
  3. DTR/DSR

With “none” it didn’t connect correctly.

With “RTS/CTS” it was reset each time (as your case).

With “DTR/DSR” its behavior was as expected (as you want, I think).

Check if it can help you in your case.

1 Like

Hi Picchio,

thanks a lot for your help, but unfortunately it did not solve the problem. I checked the flow control settings in the device manager, but there is no RTS/CTS and no DTR/DSR. Only Xon/Xoff and Hardware, but changing these did not change anything.

Which OS and which tool do you use to connect? The ESP32C3 board supports the espressif logic for reset and boot mode, which is controlled by DTR and RTS. If the PC switches these off on disconnect, the board resets. So you have to configure the PC to keep not to reset the connection to the board.

1 Like

Right question. Let us know. If you use something like Termite (my version is 3.2) for RS232 (www.compuphase.com), you will find different flow control.

Thanks. I use Windows 10 and Arduino or PlatformIO via VSCODE. With both it’s the same, and if I connect via python, what I want to read data from the XIAO, after disconnecting the serial connection it’s the same. Out of despair I installed the ESP-IDE, but even though it’s possible to transfer a program to the chip I cannot establish a serial connection or at least I got no output.
When the mcu runs on battery and I just cut the wire to the PC it continues, but much slower then before, even with a Serial.setTimeout (0). I have just millis running on a little screen, and after disconnection it updates not smoothly anymore.

Could you clean your code removing all not essential parts, leaving only a loop (for example 1Hz) for serial print and try Termite software with flow control DTR/DSR.

You should see no reset in your ESP32C3.

1 Like

Thanks a lot, that works, that helped. The chip won’t reset, but it will slow down significantly. This I can solve with Serial.setTxTimeoutMs(1);