ESP32 automatically resets after using fclose in Matlab

robpo1111
Posts: 2
Joined: Mon Aug 19, 2019 11:25 am

ESP32 automatically resets after using fclose in Matlab

Postby robpo1111 » Mon Aug 19, 2019 11:31 am

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 again:
1. Open the serial monitor in the Arduino IDE. The monitor shows the information of the bootloader. 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 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:
ESP32:

Code: Select all

void setup()
{
  Serial.begin(230400);
  pinMode(32, OUTPUT);
  digitalWrite(32, LOW);
}

void loop()
{
 
  }
 

Matlab:

Code: Select all

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



Does anyone has any Idea?
I already used google 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!

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: ESP32 automatically resets after using fclose in Matlab

Postby ESP_Angus » Tue Aug 20, 2019 4:51 am

What ESP32 hardware do you have (development board model, etc)?

Most development boards use the RTS & DTR pins to reset into bootloader mode, specifically RTS pin will toggle the EN pin to reset the board. If Matlab fclose() is toggling RTS then it may be resetting the board, or keeping it in reset indefinitely.

robpo1111
Posts: 2
Joined: Mon Aug 19, 2019 11:25 am

Re: ESP32 automatically resets after using fclose in Matlab

Postby robpo1111 » Wed Aug 21, 2019 4:58 am

Thanks for your answer!
Yes I am currently using the development board ESP32 NodeMCU.
Do you have a suggestion to avoid the problem without changing the development board?

rob

Who is online

Users browsing this forum: No registered users and 73 guests