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

Hi there.
I got this error. can’t find its problem. can you help me please?

#include <SoftwareSerial.h>
//#include <avr/wdt.h>
#define BAUD_RATE 115200
SoftwareSerial swSer(1, 3);
byte buffer[10];

void setup() {
swSer.begin(BAUD_RATE);
pinMode(16, OUTPUT);

//wdt_reset();//watchdog timer
}

void loop() {

uint16_t vari0 = 0;
uint16_t vari1 = 0;
uint16_t vari2 = 0;
uint16_t vari3 = 0;
uint16_t vari4 = 0;
uint16_t vari5 = 0;

while (swSer.available() <=6); {

vari0 = buffer[0];
vari1 = buffer[1];
vari2 = buffer[2];
vari3 = buffer[3];
vari4 = buffer[4];
vari5 = buffer[5];

}

Serial.begin(115200);
Serial.println(" ");
Serial.print("vari0 : “);
Serial.print(vari0,DEC);
Serial.println(” ");
Serial.print("vari1 : “);
Serial.print(vari1,DEC);
Serial.println(” ");
Serial.print("vari2 : “);
Serial.print(vari2,DEC);
Serial.println(” ");
Serial.print("vari3 : “);
Serial.print(vari3,DEC);
Serial.println(” ");
Serial.print("vari4 : “);
Serial.print(vari4,DEC);
Serial.println(” ");
Serial.print("vari5 : ");
Serial.print(vari5,DEC);

}

The ESP8266 has a watchdog timer that will reset the microcontroller if loop() is blocked too long. You have this loop:

while (swSer.available() <=6); {

Unless you constantly have data coming in on software serial, that will likely result in blocking your loop() long enough to cause a watchdog reset.

By the way, you might think the while loop is running everything inside the following braces, but you’d be wrong. This is because of the semicolon you added.

More information:

Thank you for your answer. I put that semicolon deliberately. it is a part of my code. I need it to buffering 6 bytes. my code works with that semicolon perfectly but the problem is that error in each loop cycle. yet need help.

THE ERROR IS:

ctx: cont
sp: 3ffffdc0 end: 3fffffc0 offset: 01b0
3fffff70: feefeffe 3ffee284 3ffee49c 4020107a
3fffff80: 000000bb 000000aa 00000001 00000039
3fffff90: 00000000 00000000 00000001 3ffee4cc
3fffffa0: 3fffdad0 00000000 3ffee49c 4020231c
3fffffb0: feefeffe feefeffe 3ffe8504 40100bcd
<<<stack<<<

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

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

fatemeh_tabrizi:
I put that semicolon deliberately. it is a part of my code.

Then what is the point of the following braces?

fatemeh_tabrizi:
I need it to buffering 6 bytes.

The while loop doesn’t do that. Your “buffering 6 bytes code” runs every single loop. I also suspect it’s not doing what you think it’s doing. What that code does is define vari0, etc. to 0 (because the global variable buffer is zero-initialized). Your code contains nothing that will ever change the value of buffer.

fatemeh_tabrizi:
my code works with that semicolon perfectly but the problem is that error in each loop cycle.

We must have a much different idea of what working perfectly means. I do not consider code that causes the microcontroller to reset unintentionally to be working perfectly.

fatemeh_tabrizi:
the problem is that error in each loop cycle.

Call yield() from the while loop, as explained in the link I provided above.

fatemeh_tabrizi:
yet need help.

Why? I thought your code was working perfectly.

By the way, the formatting of your code is horrible. If you have such low standards when you’re working on your own code, so be it. But when you post code for other people to read you need to be considerate enough to clean it up first:

Please remove unnecessary blank lines from your code before posting to the forum. One or two to separate code into logical sections is fine but large spaces for no reason or random blank lines just make for more scrolling when we’re trying to read your code.

Please always do an Auto Format (Tools > Auto Format in the Arduino IDE or Ctrl + B in the Arduino Web Editor) on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read.

Please use code tags when you post code or warning/error messages. To do this, click the </> button on the forum toolbar, then paste the text you want to be in the code tags. Finally, move the cursor out of the code tags before adding any additional text you don’t want to be in the code tags. If your browser doesn’t show the posting toolbar, then you can manually add the code tags like this:

[code]

[color=blue]// your code is here[/color]

[/code]

The reason for doing this is that, without code tags, the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier for us to read your code and to copy it to the IDE or editor.

Using code tags and other important information is explained in the “How to use this forum” post. Please read it.

I just gave it a try on my ESP8266 board and I can't reproduce your error. However, I do find that calling Serial.begin() over and over in loop() corrupts the Serial output. You should move that to setup(). There is no need to call Serial.begin() over and over.

Thank you for your long answer. sound like you are angry ;) Thank you for your advice too I will try my best. I am beginner.

my problem is exist yet. I couldn't buffer 6 bytes without that semicolon.

fatemeh_tabrizi: sound like you are angry ;)

Angry, certainly not, but I am very perplexed by your strange code and the statements you are making about it.

fatemeh_tabrizi: I couldn't buffer 6 bytes without that semicolon.

A while loop only repeats the first statement that follows it. A semicolon is a statement. So that semicolon causes the code in the braces to not be repeated by the while loop. Maybe you just want to cause the loop to pause until there are at least 7 bytes available on swSer, but if so the braces around your following code are completely unnecessary and the position of the opening brace on the same line as the while statement is very misleading.

You are right. those brackets are not necessary. Ignore them please. I want to collect 6 bytes and put them in buffer[6].

fatemeh_tabrizi: I want to collect 6 bytes and put them in buffer[6].

Your approach is flawed. See @Robin2's Serial Input Tutorial for a much better way of doing things.

My answer wasn't in that post. can anyone help me, I want to collect 6 bytes and then put them in buffer.

Take a look at Robin2’s excellent introduction to handling serial input.

fatemeh_tabrizi:
can anyone help me, I want to collect 6 bytes and then put them in buffer.

Please, answer to the following questions to get good help:

1. Which Arduino are you using (UNO, MEGA, NANO), Arduino DUE?

2. What is the type of the other device that you have connected with Arduino using software UART Port? Is it another Arduino or a sensor or a UART device?

3. Confirm that the following are your codes that you have posted in your original post.

#include <SoftwareSerial.h>
//#include <avr/wdt.h>
#define BAUD_RATE 115200
SoftwareSerial swSer(1, 3);
byte buffer[10];

void setup() 
{
  swSer.begin(BAUD_RATE);
  pinMode(16, OUTPUT);

  //wdt_reset();//watchdog timer
}

void loop() 
{
  uint16_t vari0 = 0;
  uint16_t vari1 = 0;
  uint16_t vari2 = 0;
  uint16_t vari3 = 0;
  uint16_t vari4 = 0;
  uint16_t vari5 = 0;

  while (swSer.available() <= 6)
    ; 
  {
    vari0 = buffer[0];
    vari1 = buffer[1];
    vari2 = buffer[2];
    vari3 = buffer[3];
    vari4 = buffer[4];
    vari5 = buffer[5];
  }

  Serial.begin(115200);
  Serial.println(" ");
  Serial.print("vari0 : ");
  Serial.print(vari0, DEC);
  Serial.println(" ");
  Serial.print("vari1 : ");
  Serial.print(vari1, DEC);
  Serial.println(" ");
  Serial.print("vari2 : ");
  Serial.print(vari2, DEC);
  Serial.println(" ");
  Serial.print("vari3 : ");
  Serial.print(vari3, DEC);
  Serial.println(" ");
  Serial.print("vari4 : ");
  Serial.print(vari4, DEC);
  Serial.println(" ");
  Serial.print("vari5 : ");
  Serial.print(vari5, DEC);
}

GolamMostafa:
Please, answer to the following questions to get good help:

1. Which Arduino are you using (UNO, MEGA, NANO), Arduino DUE?

You’ve not been paying attention, have you?

TheMemberFormerlyKnownAsAWOL: You've not been paying attention, have you?

I have paid attention to all the posts of the OP; I couldn't figure out the Arduino or Non-Arduino (ESP) that he is using. It is @pert who has tested the codes in his ESP.

I would like to know the Kit that the OP is using in order to prepare a short tutorial. The OP has problem in basic understanding of the UART communication concepts an the related Arduino commands.

It is true that I only assumed it's an ESP8266, based on the way the crash log looked. I haven't seen that elsewhere, though I suppose an ESP32 might look the same.

If the error message of Post#3 of OP relates to ESP8266, then I am sorry to say that I have not experienced these kind of errors with my ESP8266 Kit. Experience level differs person to person depending on the diversity of their working fields.

OK! I also accept that the OP is using an ESP8266 Kit.

GolamMostafa: I am sorry to say that I have not experienced these kind of errors with my ESP8266 Kit.

Do you mean not this exact crash log, or no crash logs at all? If the latter, then lucky you! I've seen plenty. They are printed at 115200 so you won't see it if you have Serial Monitor set to a different baud rate.

I use NodeMCU and I connected a sensor with tx rx pin to it. Sorry for my weak English.

@OP

I don't know about your sensor; I am going to use UNO to play the role of your sensor which will send regularly the following 6-byte data to NodeMCU (ESP8266) at 1-sec interval at 9600 baud rate. The ESP will grasp the data and will store them in a buffer.

0x12, 0x23, 0x34, 0x45, 0x56, 0x67

1. Let us make the following setup between NodeMCU and UNO using software UART Ports for both Kits. For NodeMCU, you are not recommended to use GPIO-1, 3 as these pins are usually connected with Serial Monitor (SM1) for debugging and uploading sketch.
espMega2x.png
Figure-1: Software UART Port connection between NodeMCU and UNO

2. Letus upload the following codes into NodeMCU and UNO. Please note that the software UART Port's (swSer and SUART Port) baud rates are set at 9600 as these ports do not work well at higher Bd.
NodeMCU Codes:

#include <SoftwareSerial.h>
//#include <avr/wdt.h>
#define BAUD_RATE 9600
SoftwareSerial swSer(4, 5);//SRX=GPIO-4/D2, STX=GPI-5/D1
byte myBuffer[10];
int i = 0;                //array index

void setup()
{
  Serial.begin(115200);
  swSer.begin(BAUD_RATE);
  pinMode(16, OUTPUT);

  //wdt_reset();//watchdog timer
}

void loop()
{
  byte n = swSer.available(); //check if data has arrived;
  if (n != 0)  //at least 1-byte has arrived
  {
    byte x = swSer.read();   //read the data byte from FIFO buffer
    myBuffer[i] = x;         //save in user declared myBuffer
    i++;
    if (i == 6)             //6-byte alreday saved in myBuffer
    {
      for (int j = 0; j < 6; j++) //show received bytes on Serial Monitor
      {
        Serial.print(myBuffer[j], HEX);
        Serial.print(' ');
      }
      i = 0;              //reset index of myBuffer
      Serial.println();   //line feed
    }
  }
}

UNO Codes:

#include<SoftwareSerial.h>
SoftwareSerial SUART(10, 11);  //SRX = DPin-10, STX = DPin-11

byte myData[] = {0x12, 0x23, 0x34, 0x45, 0x56, 0x67};
                

void setup()
{
  Serial.begin(9600);
  SUART.begin(9600);
}

void loop()
{
  SUART.write(myData, sizeof(myData));
  delay(1000);
}

Screenshot of NodeMCU:
sm-123.png

3. Notes for OP
(1) @pert has said that the ESP8266/NodeMCU will enter into reset cycle due to WDT Timer if the loop() function is hold locked for a long time. This situation can be avoided either by disabling the WDT Interrupt or construct UART codes in such a way so that the loop() function remains active. I have followed the later scheme in my UART codes for the NodeMCU.

(2) You know the Bd (baud rate) of your UART sensor, and you set the Bd of your swSer Port of NodeMCU at that speed.

(3) Do not use GPIO-1, 3 of NodeMCU to connect your sensor as these two pins are engaged with the IDE and Serial Monitor for uploading and debugging sketch. Instead, use the pins that I have shown in Fig-1.

(4) The software UART ports do not work well at higher baud rates (Bd); so, I would recommend to use lower Bd which is the Bd of your UART sensor (check the Technical Manual of your sensor).

espMega2x.png

sm-123.png