-->
Page 1 of 2

ESP8266-07 craches on interrupt handling (FIXED)

PostPosted: Sat Oct 14, 2017 5:00 pm
by Lars Bo Wassini
I have written a counter for my ESP8266-07 that uses interrupts, but sometimes it craches. The code is quite simple.
Sometimes it works for several "completions" - other times it craches when the counter is e.g. 600 or 900.
I have tried with two different ESP modules and its running stable if I disable the "attachInterrupt" code.

Any input is appreciated.

Code: Select allconst int pinFlowmeter = 13;

volatile unsigned int intCounter=0;


void setup() {
}

void loop() {
   if (intCounter >= 1000) {
      detachInterrupt(digitalPinToInterrupt(pinFlowmeter));
      Serial.println("Complete");
      intCounter = 0;
      buttonPressed = false;
   }

 // ... other stuff
}

void pressButton() {
   if (!buttonPressed) {  // prevent calling this several times
      attachInterrupt(digitalPinToInterrupt(pinFlowmeter), getcount, CHANGE);
      buttonPressed = true;
   }
}

void getcount() {
  intCounter++;
}


Re: ESP8266-07 craches on interrupt handling

PostPosted: Sat Oct 14, 2017 5:42 pm
by rudy
What is the pulse rate?

How about posting complete minimum sketch that you have tried. It doesn't have to be much more than you have. But it must compile and it must execute. I can add in the parts that you have missing but that will not be exactly what you have.

Re: ESP8266-07 craches on interrupt handling

PostPosted: Sat Oct 14, 2017 6:37 pm
by rudy
I get no crashing. But I needed to modify your sketch since it isn't complete.

Re: ESP8266-07 craches on interrupt handling

PostPosted: Sun Oct 15, 2017 2:28 am
by schufti
Hi,
most important thing for isr: has to be in IRAM!

void ICACHE_RAM_ATTR getcount(void)

in case it is not in IRAM there can be problem with caching (probably hw fault).