espressif / arduino-esp32

Arduino core for the ESP32
GNU Lesser General Public License v2.1
13.75k stars 7.43k forks source link

Serial.begin(115200); does not reinitiate after Serial.end(); which also disables BLE and PWM functionality #5032

Closed Ryap741135 closed 3 years ago

Ryap741135 commented 3 years ago

Hardware: |Board|ESP32 Dev Module (ESP32-WROOM-32D)| |Version/Date|1.0.5 and 1.0.6| |IDE name|Arduino IDE 1.8.13| |Flash Frequency|80Mhz| |PSRAM enabled|no| |Upload Speed|115200| |Computer OS|Windows 10|

Description:

I am new at submitting an issue but I believe this is a critical issue where the Serial.begin(115200); no longer reinitiates after Serial.end(); Serial.end() also disables my RGB LED that use PWM and disables BLE functionality. This was not occurring and working (with compilation, upload successfully and tested with hardware) in ESP32 Board Manager version 1.0.4 but the problem was apparent in versions 1.0.5 and 1.0.6. Below is a snippet of my code (is very big and need hardware to interface with to get it working) that controls the ESP32 dev board. When an USB is plugged in it should set the CPU frequency to 240MHz, enable Serial output and when the USB is removed it should set it to 80MHz, disable Serial output. This is to conserve the unit's battery power. I have tested with an RGB LED as an indicator to see if the code flows properly since I do not have Serial Monitor when the USB is removed or connected. I have also tried to establish a BLE connection after Serial.end(); no avail with board manager 1.0.5 and 1.0.6. The Serial output works just after uploading but once I disconnect the USB and reconnect it, it does not show Serial output in the Serial Monitor (this was working in 1.0.4).

Thanks for your help!

Sketch: (leave the backquotes for code formatting)


byte sensors() {
  hdc1080();
  plantower();
  serial_debugger();
  //Serial.println(getCpuFrequencyMhz());
  boolean USB = digitalRead(V_USB);
  if (USB == HIGH && USBflag == true) {
    USBflag = false;
    setCpuFrequencyMhz(240);
    Serial.begin(115200);
    Serial.setTimeout(250);
    //blue(); //Comment out the top two lines to test the blue LED with USB detect
  }
  if (USB == LOW && USBflag == false) {
    USBflag = true;
    setCpuFrequencyMhz(80);
    //red();
    Serial.end();
    //red(); //Comment out the top one line to test the red LED with USB detect
  }
  /*else{
    USBflag = true;
    green();
    }*/
  return 1;
}

Debug Messages:

Enable Core debug level: Debug on tools menu of Arduino IDE, then put the serial output here 
stale[bot] commented 3 years ago

[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

stale[bot] commented 3 years ago

[STALE_DEL] This stale issue has been automatically closed. Thank you for your contributions.