Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By andre_teprom
#71300 Ugh...at a glance, this hit me !!!

Code: Select allfor(int y=1; y<=6;y++) {
delay(10000);
Serial.print(y*10); Serial.flush();
Serial.print("-"); Serial.flush();
}


You are adding a delay of 10 seconds 6 times within the loop() routine. Keep in mind that the ESP8266 Arduino Wifi libraries has its own watchdog management, so that even after few seconds in a closed loop without refreshing timer wtd count there, this would crash the run of your program.
User avatar
By Pablo2048
#71305 Actually delay(xxxx) handles wifi stack internally and feeds software wdt. Program will definitely not crash with software wdt triggered if you use delay, but I've prefer to eliminate delay on every possible place...
User avatar
By rudy
#71306
andre_teprom wrote:Ugh...at a glance, this hit me !!!

Code: Select allfor(int y=1; y<=6;y++) {
delay(10000);
Serial.print(y*10); Serial.flush();
Serial.print("-"); Serial.flush();
}


You are adding a delay of 10 seconds 6 times within the loop() routine. Keep in mind that the ESP8266 Arduino Wifi libraries has its own watchdog management, so that even after few seconds in a closed loop without refreshing timer wtd count there, this would crash the run of your program.


The WiFi routines are being serviced when delay() is called. This is not the problem.
User avatar
By rudy
#71311 I tried the post of the code and it did work for me. I was using a switch to generate the interrupts. Some switch bounce produced multiple interrupts. And it worked for 30 minutes. No crashing.

Then I read the post again and noticed the OP used a signal generator to provide more/faster pulses. And I don't have a signal generator at home. What to do?

I used a USB-serial converter to provide the input. I had a long string of 55555555555.... to create my pulses. I used a baud rate of 1200. And I finally got a crash.

I then did the following.


2ni wrote:I could solve my crash issues with interrupts by setting the interrupt function to RAM.
see https://github.com/esp8266/Arduino/issu ... -263108001:
Code: Select allvoid ICACHE_RAM_ATTR interrupt_function()
{
...
}


And after this it has worked without problem.

I should note that I didn't like the long delay in loop so I shortened it by a factor of 10. Instead of delay(10000) I changed it to delay(1000). And since WiFi is to be a part of all this I included a UDP reception/echo function.

The serial string that I used I adjusted so that it would give me 500 pulses on a send. That way it was easier to see if anything got lost. For the UDP I used the packetsender program to send a string. The ESP would add a couple of characters to that and send it back to the computer. The packetsender program would see the returned string (with the two new added characters) and would send another string that the ESP would then reply to again.

And this is all working without problems. No crash. Maybe the quality of the coding isn't great but it works for me.

Oh yeah, I bumped up the baud rate for the serial string to 2400 and it all worked. No missing counts. I then tried 4800 baud and again no problem. at 9600 baud it worked as well.

I used GPIO4 rather than 5 as it was easier on my test board.

Code: Select all/* Test of interrupt handler */

#include <ESP8266WiFi.h>
#include <WiFiUdp.h>

volatile unsigned int hwCount = 0;
volatile unsigned int lastHwCount = 0;
volatile unsigned int loopCounter = 0;

const char* ssid = "xxxxxxx";
const char* password = "xxxxxx";
const int pulseInput = 4;
 
WiFiUDP Udp;
unsigned int localPort = 8888;
// buffers for receiving and sending data
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,

//==========================================
void ICACHE_RAM_ATTR flowCounterCb() {
hwCount++;
}
//==========================================
void setup() {
Serial.begin(115200);
delay(10);

Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}

Serial.println("");
Serial.print("WiFi connected - ");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());

pinMode(pulseInput, INPUT_PULLUP);
attachInterrupt(pulseInput, flowCounterCb, RISING);

Udp.begin(localPort);
}

//==========================================
void loop() {

Serial.print("Loop counter: ");
Serial.println(loopCounter);

Serial.print("Interrupt counter: ");
lastHwCount = hwCount;
Serial.println(lastHwCount);

Serial.print("IP address: ");
Serial.print(WiFi.localIP());
Serial.print(" Connection status: ");
Serial.println(WiFi.status());
loopCounter++;

for(int y=1; y<=6;y++) {
udpRxTx();
delay(1000);
Serial.print(y*10);
Serial.print("-");
}
Serial.println("");

Serial.print("heap ");
Serial.println(ESP.getFreeHeap());
Serial.println("------------------");

}

//================================================= 
void udpRxTx()
{
    // if there's data available, read a packet
    int packetSize = Udp.parsePacket();
    if (packetSize)
    {   
        // read the packet into packetBufffer
        Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);
       
        // send a reply, to the IP address and port that sent us the packet we received
        Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
        Udp.write("=> ");
        Udp.write(packetBuffer);
        Udp.endPacket();
    }
}


Oh yeah. I put the UDP routine call in the delay loop in loop(). I wanted to get faster responses.

9600 baud
555555555555555555555555555555555555555555555555555555555555555555555555555555575555555555555555555055555555555055055555555555


Code: Select all10-20-30-40-50-60-
heap 36920
------------------
Loop counter: 1
Interrupt counter: 1
IP address: 192.168.100.101 Connection status: 3
10-20-30-40-50-60-
heap 36160
------------------
Loop counter: 2
Interrupt counter: 501
IP address: 192.168.100.101 Connection status: 3
10-20-30-40-50-60-
heap 36160
------------------
Loop counter: 3
Interrupt counter: 715
IP address: 192.168.100.101 Connection status: 3
10-20-30-40-50-60-
heap 36160
------------------
Loop counter: 4
Interrupt counter: 1501
IP address: 192.168.100.101 Connection status: 3
10-20-30-40-50-60-
heap 36160
------------------
Loop counter: 5
Interrupt counter: 2001
IP address: 192.168.100.101 Connection status: 3
10-20-30-40-50-60-
heap 36160
------------------
Loop counter: 6
Interrupt counter: 2001
IP address: 192.168.100.101 Connection status: 3
10-20-30-40-50-60-
heap 36160
------------------


Code: Select all------------------
Loop counter: 404
Interrupt counter: 20559
IP address: 192.168.100.101 Connection status: 3
10-20-30-40-50-60-
heap 36160
------------------
Loop counter: 405
Interrupt counter: 21059
IP address: 192.168.100.101 Connection status: 3
10-20-30-40-50-60-
heap 36160
------------------
Loop counter: 406
Interrupt counter: 21559
IP address: 192.168.100.101 Connection status: 3
10-20-30-40-50-60-
heap 36160
------------------