I am working on a project where an ESP32S2 is connected via USB directly to the PC. There is no UART and the port is behaving rather weirdly.
The port is set up in the program as follows:
Code: Select all
mySerial =(Stream*) &(UsbCdcSerial);
UsbCdcSerial.begin();
USB.begin();
then used for example like this:
mySerial->println("Some text");
Don’t ask why. I didn’t set it up that way. What happens is that when initially connected to Serial Monitor, it does not respond until RESET is pressed. After showing the connection lost and then re-established, the Serial Monitor then accepts and receives data as expected. The problem is that in any other application, the connection is dropped the moment that RESET is pressed.
In PlatformIO/pioarduino, I tried adding the following to the board profile:
-D ARDUINO_USB_CDC_ON_BOOT=1
-D ARDUINO_USB_MODE=1
which used different libraries and there is a bug in HardwareSerial.cpp in v2.0 of the Espressif Arduino core causing compilation to fail. Removing the second line reverts back to the Espressif CDC method but results in the same problem. When ARDUINO_USB_CDC_ON_BOOT is set to 0, then there will be not response at all, not even in the Serial Monitor, so that line is essential. I also tried commenting out the offending line in HardwareSerial.cpp that referred to ‘Serial’ (ESP32 has Serial1 and Serial2) but it didn’t make any difference to the result unfortunately.
I also tried disabling the DSR/DTR signals:
monitor_rts = 0
monitor_dtr = 0
which actually causes the Serial Monitor to quit on startup.
Is there anything else that needs to be added to force the serial port to open? I have tried this with both Arduino core 2 and 3 I am working on a project where an ESP32S2 is connected via USB directly to the PC. There is no UART and the port is behaving rather weirdly.
The port is set up in the program as follows:
Code: Select all
mySerial =(Stream*) &(UsbCdcSerial);
UsbCdcSerial.begin();
USB.begin();
then used for exaple:
mySerial.println(“Some text”);
Don’t ask why. I didn’t set it up that way. What happens is that when initially connected to Serial Monitor, it does not respond but only after RESET is pressed. After showing the connection lost and then re-established, the Serial Monitor then accepts and receives data as expected. The problem is that in any other application, the connection is dropped the moment that RESET is pressed.
In PlatformIO/pioarduino, I tried adding the following has been added to the board profile:
-D ARDUINO_USB_CDC_ON_BOOT=1
-D ARDUINO_USB_MODE=1
I also tried disabling the DSR/DTR signals:
monitor_rts = 0
monitor_dtr = 0
which actually causes the Serial Monitor to quit almost immediately.
Is there anything else that needs to be added to force the serial connection to open? I have tried this with both Arduino core 2 and Arduino core 3 with the same result.
When I compile the Arduino IDE version of the project, via conditional directives it uses standard Arduino serial port methods (Serial.begin()) to initialise the port and that seems to work normally. Therefore it doesn’t appear to be a problem with hardware as such, but maybe the way that serial is handled using CDC methods in the Espressif core or PaltformIO/pioarduino? Is there something I am missing in addition to the above that I need to add to make the Serial port work when using CDC serial?with replacing the serial headers and files with the ones from Arduino core 3 with the same result.
When I compile the Arduino IDE version of the project, via conditional directives it uses standard Arduino serial port methods (Serial.begin()) to initialise the port and that seems to work normally. Therefore it doesn’t appear to be a problem with hardware as such, but maybe the way that serial is handled using CDC methods in the Espressif core or PaltformIO/pioarduino? Is there something I am missing in addition to the above that I need to add to make the Serial port work when using CDC serial?