2

I want to use the Serial Monitor for some debugging, but it prints something else.

Edit- This only happens if I use the attachInterrupt() function

I tried another program that does not use interrupts and there it works.

My code:-


/*
YF‐ S201 Water Flow Sensor
Water Flow Sensor output processed to read in litres/hour
Adaptation Courtesy: www.hobbytronics.co.uk
*/
volatile int flow_frequency; // Measures flow sensor pulses
unsigned int l_hour; // Calculated litres/hour
unsigned char flowsensor = 13; // Sensor Input
unsigned long currentTime;
unsigned long cloopTime;
void flow () // Interrupt function
{
   flow_frequency++;
}
void setup()
{
   pinMode(flowsensor, INPUT_PULLUP);
   Serial.begin(9600);
   attachInterrupt(0, flow, RISING); // Setup Interrupt
   sei(); // Enable interrupts
   currentTime = millis();
   cloopTime = currentTime;
}
void loop ()
{
   currentTime = millis();
   // Every second, calculate and print litres/hour
   if(currentTime >= (cloopTime + 1000))
   {
      cloopTime = currentTime; // Updates cloopTime
      // Pulse frequency (Hz) = 7.5Q, Q is flow rate in L/min.
      l_hour = (flow_frequency * 60 / 7.5); // (Pulse frequency x 60 min) / 7.5Q = flowrate in L/hour
      flow_frequency = 0; // Reset Counter
      Serial.print(l_hour, DEC); // Print litres/hour
      Serial.println(" Lhour");
   }
}

Data from Serial Monitor:-

--------------- CUT HERE FOR EXCEPTION DECODER ---------------
⸮⸮⸮⸮⸮⸮ISR not in IRAM!

User exception (panic/abort/assert) --------------- CUT HERE FOR EXCEPTION DECODER ---------------

Abort called

>>>stack>>>

ctx: cont sp: 3ffffef0 end: 3fffffc0 offset: 0000 3ffffef0: feefeffe feefeffe feefeffe 00000100
3fffff00: 000000fe 00000000 00000000 00000000
3fffff10: 00000000 00000000 00000000 00ff0000
3fffff20: 5ffffe00 5ffffe00 3ffef0a4 00000000
3fffff30: 00000001 00000000 3ffee34c 40201e72
3fffff40: 40100402 40202e51 ffffffff 40201e84
3fffff50: feefeffe 00000001 3ffee34c 40202399
3fffff60: 00000000 00000001 3ffee324 4020129c
3fffff70: 00000000 feefeffe feefeffe 3ffee38c
3fffff80: 3fffdad0 00000000 3ffee34c 40202448
3fffff90: 3fffdad0 00000000 3ffee34c 40201079
3fffffa0: feefeffe feefeffe feefeffe 40201a80
3fffffb0: feefeffe feefeffe 3ffe84e4 40100cfd
<<<stack<<<

Why is this happening?

Hardware-ESP8266 based NodeMCU

Coder9390
  • 512
  • 1
  • 7
  • 25

0 Answers0