ESP32 automatically resets after using fclose in Matlab

Hello everybody,

I am currently facing a problem using an ESP32 and Matlab.
Everything works just fine except after Matlab closes the serial connection using fclose, the ESP32 resets. There are two ways to get out of this state, so the ESP32 works normally:

  1. Open the serial monitor in the Arduino IDE. The monitor shows some cryptic stuff. But that doesn't matter. The ESP32 works after it until fclose happens again.
  2. Use fopen in Matlab, wait a little bit and the ESP32 works again fine.

Both ways are won't work for my project. The ESP32 needs to be always online since it's used as an access point.

Here is the a simple code example to simulate the problem:

void setup()
pinMode(32, OUTPUT);
digitalWrite(32, LOW);

void loop()



s = serial('COM20');
set(s,'BaudRate',230400, 'timeout', 0.5);

Does anyone has any Idea?
I already used goodle and looked in a bunch of diffent forums but I couldn't find the correct solution to avoid this problem. I don't really understand the problem since it's just opening and closing a serial port.

Thanks in advance!