Serial output stops working but input is OK, why?

I am having trouble debugging my sketch via serial output...

See this thread about switching debug serial on/off.

I have used advice on that thread to fix a way to control debug output via the serial port.
And I got that to work as expected.

Today when I rebuilt the sketch and uploaded it to an ESP-07 device in order to check a detail in the operations the serial debug output stopped appearing on the serial port...

Now several hours later and after having backed off all special code to switch debug output on/off it is still not sending the expected output!

I have no idea now where to look for this problem - it looks like a framework version problem, so I need some advice.

The sketch uploads just fine using the serial transfer, indicating to me that the serial system cannot really be broken...

When I start the sketch after successful upload my terminal application shows this:

...junk data ...
Debug serial non-invert mode active! Database device set to: 2
Serial port is ready to receive.
  ?      ?     ?      ?

The code that executes here is the serial port config function called in setup():

  void StartSerialPort()
{
    Serial.begin(115200, SERIAL_8N1, SERIAL_FULL);
    Serial.println("");

    //Check jumper on pin GPIO5 if inversion of the Rx pin is needed
    //HIGH = no jumper == invert
    //LOW  = jumper in place == no invert
    const int jumperPin = 5;
    pinMode(jumperPin, INPUT);
    int jumperstate = digitalRead(jumperPin);
    if (jumperstate == HIGH) //Invert
    {
        Serial.println("Swapping UART0 RX to inverted");
        Serial.flush();
        USC0(UART0) = USC0(UART0) | BIT(UCRXI);
    }
    else
    {
        strlcpy(MQTT_ROOT_TOPIC, "aspo/sensors/power/testmeter", sizeof(MQTT_ROOT_TOPIC));
        DBDEVICENO = 2; //Send database entries as device 2 whan jumper is active
        Serial.println("Debug serial non-invert mode active! Database device set to: " + String(DBDEVICENO));
        Serial.flush();
    }
    
    Serial.println("Serial port is ready to recieve.");
    Serial.flush();
}

So at this point the serial port operates and sends out data at the expected baudrate etc.
Then follow a few calls to setup functions that do not use Serial at all.
But the next function to use the debug Serial does this:

void GetMqttConfig()
{
    // * Get MQTT Server settings
    String settings_available = read_eeprom(134, 1);

    if (settings_available == "1") //There are live config items in the EEPROM store
    {
        Serial.println();
        Serial.println("MQTT data found, read from EEPROM!");
        ....
     }
     else
     {
        Serial.println("No MQTT params found, using defaults instead!");
        ...
     }

This message stating weather config could be read or not is not output over the Serial port (at least not at the correct baudrate).

The interesting thing is that while the debug serial output towards my terminal application does not work, my input via the serial connection to the sketch works just fine and I can push data into it that causes normal operation towards the MQTT broker...

So the problem is that for some reason the serial data sent by the sketch to my terminal application stops working at the time the serial port config function has finished while the serial port input continues to work just fine.

As a last resort I backed the framework used to an older version:
platform = espressif8266@2.5.2
With this the serial debug output reappears in my terminal!

How can this have happened and what can I do to fix it?
Do I have to stay on version 2.5.2?????
I really want to be up-to-date on my libraries and framework....

So I searched a lot and found out that the Serial.begin() has an overloaded version reading like so:

void HardwareSerial::begin(unsigned long baud, SerialConfig config, SerialMode mode, uint8_t tx_pin, bool invert)

So it seems like I could do something like this instead of what was shown above:

Serial.begin(BAUD_RATE, SERIAL_8N1, SERIAL_FULL, tx_pin, jumperstate == HIGH);

But I found no reference to what I could set tx_pin to in order to work in the serial port using pin #16 on the ESP-07 device. I.e. the first serial port one uses...
Is there a comprehensive list of the alternatives here somewhere?
And maybe this use will invert BOTH Rx and Tx?
I only want Rx to be inverted....

EDIT:
Well, it turns out that this command does not work, it seems to invert both directions whereas I only want the incoming to be inverted since the electricity meter output it is reading is inverted by an opto-coupler.
So it looks like the only way just now is to stick to the old espressif platform version 2.5.2. :frowning:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.