| Electronics > Projects, Designs, and Technical Stuff |
| ESP32 Serial Won't Start After Serial.end() |
| << < (2/2) |
| petersanch:
Do you mean this code? --- Code: ---#include <HardwareSerial.h> uint8_t a= 10; HardwareSerial MySerial(1); void setup() { pinMode(10, OUTPUT); } void loop() { //MySerial.begin(250000, SERIAL_8N1, 9, 10); //MySerial.write(a); //MySerial.flush(); //delay(1); //MySerial.end(); //MAKE PIN 10 GENERAL IO AND DO SOMETHING WITH digitalWrite(10,LOW) or digitalWrite(10,HIGH) HERE pinMode(10, OUTPUT); digitalWrite(10, LOW); delay(1); digitalWrite(10, HIGH); delay(1); digitalWrite(10, LOW); delay(1); digitalWrite(10, HIGH); delay(1); delay(100); } --- End code --- Yes this code toggles pin 10 with 1 ms pulses on the oscilloscope. |
| cv007:
Now I'm just wild guessing, but it could be the pin init code for the uart ends up setting the io mux function to the uart, but when detaching only sets the matrix back to gpio but does not set the io mux function to gpio, so after the first use the gpio has no path to the pad/pin. I'm not sure if this would work (I could be misunderstanding the datasheet and the code), but try it for the tx pin after done with the uart- gpio_pad_select_gpio( 10 ); It could also be that the pinMode code should be doing this, but I didn't take the time to figure out what its doing. |
| petersanch:
I tried gpio_pad_select_gpio( 10 ); before and after pinMode but same results as before. I tried using PWM instead of general IO in case its to do with pinMode. Sadly is the same as before. --- Code: ---#include <HardwareSerial.h> uint8_t a= 10; HardwareSerial MySerial(1); void startPWM() { ledcSetup(0, 5000, 8); ledcAttachPin(10, 0); } void setup() { pinMode(10, OUTPUT); startPWM(); } void loop() { MySerial.begin(250000, SERIAL_8N1, 9, 10); MySerial.write(a); MySerial.flush(); delay(1); MySerial.end(); startPWM(); ledcWrite(0, 50); delay(100); } --- End code --- |
| hamster_nz:
--- Quote from: petersanch on March 25, 2019, 01:42:05 am ---I tried gpio_pad_select_gpio( 10 ); before and after pinMode but same results as before. I tried using PWM instead of general IO in case its to do with pinMode. Sadly is the same as before. --- Code: ---#include <HardwareSerial.h> uint8_t a= 10; HardwareSerial MySerial(1); void startPWM() { ledcSetup(0, 5000, 8); ledcAttachPin(10, 0); } void setup() { pinMode(10, OUTPUT); startPWM(); } void loop() { MySerial.begin(250000, SERIAL_8N1, 9, 10); MySerial.write(a); MySerial.flush(); delay(1); MySerial.end(); startPWM(); ledcWrite(0, 50); delay(100); } --- End code --- --- End quote --- Had a brief look at the GitHub repo for the uart and ledc modules: https://github.com/espressif/arduino-esp32/blob/master/cores/esp32/esp32-hal-uart.c https://github.com/espressif/arduino-esp32/blob/master/cores/esp32/esp32-hal-ledc.c Nothing in them looks like a one-way door through which you can't get back from... Do you call "void ledcDetachPin(uint8_t pin)" to release the GPIO pin before you try to start up the Serial port again? |
| cv007:
It looks to me like pinMode is setting the pin function to gpio mode (FUNCTION_3) when OUTPUT or INPUT are used, so my previous guess was indeed a wild one. |
| Navigation |
| Message Index |
| Previous page |