Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loop in loop() causing Soft WDT reset #2866

Closed
ludekvodicka opened this issue Jan 15, 2017 · 11 comments
Closed

Loop in loop() causing Soft WDT reset #2866

ludekvodicka opened this issue Jan 15, 2017 · 11 comments

Comments

@ludekvodicka
Copy link

Basic Infos

Hardware

Hardware: WemosD1 mini v 2.1.0

Description

I'm getting "Soft WDT reset" in simple loop.

Soft WDT reset

ctx: cont 
sp: 3ffef1d0 end: 3ffef3d0 offset: 01b0

Stack (I'm not able to decode it. i don't have such option in my arduino app)

>>>stack>>>
3ffef380:  3ffe8430 feefeffe 3ffef360 3ffef390  
3ffef390:  40106af0 00000338 00000000 3ffee39c  
3ffef3a0:  3fffdad0 00000000 00000338 40201c55  
3ffef3b0:  feefeffe feefeffe 3ffee394 40202138  
3ffef3c0:  feefeffe feefeffe 3ffee3b0 40100114  
<<<stack<<<

This is sample code, It's very simplifed version of my app only to present the bug. App crash always when counter is 824.

void setup()
{
  Serial.begin(9600);
  Serial.println("Start");
  pinMode(D1, OUTPUT);
}

void loop()
{
  for ( long nBlinkLong=0; nBlinkLong < 20 * 1000; nBlinkLong++ )
  {
    Serial.printf("%d,", nBlinkLong);
    digitalWrite(D1, LOW);
    delayMicroseconds(1000);
  }
}

Settings in IDE

Module: Generic ESP8266 Module
Flash Size: 4MB
CPU Frequency: 80Mhz

@ludekvodicka
Copy link
Author

Ok, it seems that it's caused by watchdog timer. I didn't know about this before.

#34 (comment)

@JamesGKent
Copy link

could you try changing your code to use delay instead of delayMicroseconds? using delay allows some of the background tasks to happen during the delay which may prevent the watchdog reset (not tested this) where delayMicroseconds does not.

@ludekvodicka
Copy link
Author

Hi James, sorry for late reply. I tried to use delay but with same results. The second problem was that I needed delayMicroseconds because of simulating PWM. But I solved it without delay/delayMicrosends with getTickCount measurement.

@JamesGKent
Copy link

glad you solved your problem, can i suggest that you post a stripped down example of your fixed code (in case someone else has a similar issue) and then close this issue?

@ludekvodicka
Copy link
Author

Sure, it's something like this

unsigned long timeLastCheck = 0;
unsigned long intervalCheck = 500;

void loop() {
  unsigned long timeNow = millis();
  if ( timeLastCheck == 0 || timeNow-timeLastCheck > intervalCheck )
  { 
    ...
  }
}

@hemangjoshi37a
Copy link

can you paste the whole code please?? I want to see where exactly the code goes and how to use it.
Thax.

@regimantas
Copy link

Same problem with HX711 library on esp8266. delay(0); in loop fix problem :) Library use yield(); but it not work :(

@Ginger-Stone
Copy link

Ginger-Stone commented May 18, 2018

@regimantas did you manage to fix your problem with the hx711? I am having the same problem with my hx711 and node mcu on arduino ide

@doublejosh
Copy link

I found this was necessary even in a particularly long running for loop, rather than just longer running while statements. Using delay(0) worked perfectly. Thanks!

@Deepakg1105
Copy link

I found this was necessary even in a particularly long running for loop, rather than just longer running while statements. Using delay(0) worked perfectly. Thanks!

But delay() has some issues like blocking other connected devices for specified time and non-accurate delays as code takes its own time to run.

@dungcnttimd
Copy link

dungcnttimd commented Nov 19, 2021

I made this mistake. Sorry can anyone help me?

Soft WDT reset

stack>>>

ctx: cont
sp: 3ffffdd0 end: 3fffffc0 offset: 01a0
3fffff70: 5301a8c0 00ffffff 0101a8c0 40201bfc
3fffff80: 3ffe85cc 3ffee508 3ffee5b8 4020105c
3fffff90: 40204dfc 5301a8c0 feefeffe feefeffe
3fffffa0: 3fffdad0 00000000 3ffee5b8 402022d4
3fffffb0: feefeffe feefeffe 3ffe85e0 40100c01
<<<stack<<<

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

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

load 0x4010f000, len 3460, room 16
tail 4
chksum 0xcc
load 0x3fff20b8, len 40, room 4
tail 4
chksum 0xc9
csum 0xc9
v00042d10
~ld

My code

/---------KẾT NỐI---------/
#include <ESP8266WiFi.h>
#include <WiFiClient.h>

#define BLYNKLED 2 //D4 - Led debug
#define TouchSensor 0 //D3 - đọc cảm biến chạm
#define Buzzer 16 //D0 - điều khiển buzzer ON - low | OFF - high
#define ASC712 A0 //Đọc cảm biến dòng
#define Relay 13 //D7 - Điều khiển relay ON - high | OFF - low

//----- Kết nối wifi
const char* ssid = "###";
const char* password = "###";

void setup() {
Serial.begin(115200); // set tần số hoạt động của chip mcu

pinMode(TouchSensor, INPUT);
pinMode(ASC712, INPUT);

pinMode(BLYNKLED, OUTPUT);
pinMode(Buzzer, OUTPUT);
pinMode(Relay, OUTPUT);

digitalWrite(BLYNKLED, LOW);
digitalWrite(Buzzer, HIGH);
digitalWrite(Relay, HIGH);
debugHardware();

//Kết nối wifi
Serial.printf("Connecting to %s \n", ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED){
delay(500);
Serial.print(".");
}
Serial.println();
Serial.println(WiFi.localIP());
}

void loop() {
bool touch = touchRead();
Serial.print(String(touch));
delay(100);
}

bool touchRead(){
int touch = digitalRead(TouchSensor);
bool touchVal = 0;

while(touch != 0){
touchVal = 1;
touch = digitalRead(TouchSensor);
}
return touchVal;
}
void debugHardware(){
for(int i = 0; i<10; i++){
digitalWrite(BLYNKLED, HIGH);
delay(150);
digitalWrite(BLYNKLED, LOW);
delay(150);
}
digitalWrite(BLYNKLED, LOW);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants