strange problems with espSoftwareSerial

This small code compiles ok, but only give me:

ets Jan 8 2013,rst cause:4, boot mode:(1,6)
wdt reset

But when i comment out the last Serial.print () it runs ok.

Can anybody explain for me what is going on??

#include <SoftwareSerial.h>

SoftwareSerial sdmSer = SoftwareSerial (12, 13, false, 32);

void setup ()
	Serial.begin (115200);  //initialize serial

	Serial.println ("A");

	sdmSer.begin (4800);
	Serial.println ("B");

void loop ()
	Serial.println ("C");
	delay (500);
	Serial.println ("D");	// If i comment this out it runs OK


how are things wired? are you running this code straight to an ESP flashed for Arduino environment? what ESP do you have?

It is an esp12e and using arduino-1.8.1
I also have' in my preferences in board manager url.

I think it is very strange that the board crash it is depending on a Serial.print without any more information for debugging.


how is the ESP wired back to your computer?

Since it a LoLin (NODEMCU copy) it has a serial to usb chip connected to hardware uart 0. So i have to use a software serial for connecting a power meter via rs485.


The I/O pins of ESP8266 communicate or input/output max 3.3V only. i.e. the pins are NOT 5V tolerant inputs. what's connected to your sdmSer pins?

I know that all ESP8266 is only 3.3V tolerant, so i use a 75HVD12 as RS485 driver

And i plan later to use DERE pins in the correct way. But now i just want to know why mu LoLin only gives me watchdog reset without executing any Print statement.


and if you comment out the

SoftwareSerial sdmSer = SoftwareSerial (12, 13, false, 32); and sdmSer.begin (4800); do you still get the same issue?

have you tried just with a FTDI and connecting your ESP to your PC on the serial port to see if things would work?

All works ok then.

1384, room 16
tail 8
chksum øA

And so on..

But with SoftwareSerial enabled i only see this on my PC

1384, room 16
tail 8
ets Jan 8 2013,rst cause:4, boot mode:(1,6)

wdt reset

So no debugging info at all unless boot mode and watchdog timeout. Not even a stack trace to follow up.

and if nothing is physically to pins 12, 13?

Hmm. :o I have my RS485 ic connected there, More Hmmm. I have swapped rx and tx. My mistake. Now when it is correct wired it boots and starts and runs ok.

But why is the ESP8266 behaving so strange? Not even executes the line Serial.println ("A"); before sdmSer.begin


Tx is set a output so low impedance - can provide a substantial amount of current to other circuits - but not sure how it reacts to sinking current in that mode… never tried :slight_smile:

it probably crashed, due to wrong wiring.

The magical smoke is still inside my ESD8266 :slight_smile:

Now i checked with my oscilloscope and my first wiring was the right one.
if i disconnect ether GPIO12 OR GPIO13 during the boot seq. then all starts ok and i can reconnect the GPIO and then it continues to run.

Now i can see exact the same error when connecting GPIO12 to GPIO13 via a 2k2 resistor.


Some ESP-12 or 12E are well known for having the pins number wrong on the silk screen (4/5 swapped for example )

Are you using pins number as labeled for nodeMCU or as physically defined on the chip ? ESP8266 GPIO pins number Do not match - For example pin D6 and D7 are translated to 'real' GPIO pin 12 and 13

Cf this link

static const uint8_t LED_BUILTIN = 16;
static const uint8_t BUILTIN_LED = 16;

static const uint8_t D0   = 16;
static const uint8_t D1   = 5;
static const uint8_t D2   = 4;
static const uint8_t D3   = 0;
static const uint8_t D4   = 2;
static const uint8_t D5   = 14;
static const uint8_t D6   = 12;
static const uint8_t D7   = 13;
static const uint8_t D8   = 15;
static const uint8_t D9   = 3;
static const uint8_t D10  = 1;

I know of that, so i have them correct wired (D6 and D7).
Bus as i wrote before, this misbehavior is easy to obtain just by connecting GPIO12 to GPIO13 by a 2k2 resistor.

Not even executes the line Serial.println (“A”); before sdmSer.begin

But it DID execute the Serial.println() statement, transferring the ‘A’, the carriage return, and the line feed to the outgoing serial buffer. Then, the sdmSer.begin() statement was executed, causing the Arduino to crash, before the data was shifted out of the buffer.

Prove that to yourself, by putting Serial.flush() after the Serial.println() statement. The call to flush() blocks until all the data in the buffer has been shifted out. Then, when the Arduino crashes, you’ll have a better idea where in the code the problem is.

Yes of course i have forgot to flush. So i put in a Serial.flush() after every println. To my surprise i only get

 ets Jan  8 2013,rst cause:4, boot mode:(3,6)

wdt reset
load 0x4010f000, len 1384, room 16 
tail 8
chksum 0x2d
csum 0x2d

No flushing of the Serial.print buffer. It is almost that i want a JTAG connector so i can single step the boot and core.

I have some feeling that it has something with interrupt initialiazing.
I will dive into the SoftwareSerial code to se what i can find.

may be you want to spend $3 and get a different module that works...

It seems to be some sort of deadlock when the interrupt for receiver is turned on. So not even Serial.print functions before the line:

         attachInterrupt(m_rxPin, ISRList[m_rxPin], m_invert ? RISING : FALLING);

executes it hangs.

I have not yet tried to use alternate pins for rx and tx.

A for me quick and dirty fix that works for me was to enable the receive code before transmit code.


Ok. the problem seems to be in the interrupt handler in the core.

The interrupt handler is set before cleaning interrupts for the receive pin witch make the receive sensitive to transisions high to low or low to high.

So until this is solved (i maked an issue for this on Github.) i will use my patched core.