Interrupts and Wifi not possible??
Posted: Mon Dec 21, 2020 12:12 am
I would like to use a Wemos D1 Mini to monitor an SPI connection and send the data over WiFi.
Unfortunately, I can't seem to keep the ESP connected to WiFi if there's an interrupt firing.
I've cut my code down as much as I can and at the moment I'm just putting a 6.7kHz signal into the D1 pin of the D1 and just trying to get it to count the pulses and output the number to serial.
It works for about 10 seconds and then crashes.
Here's my code:
And the output:
I can't see how I can make this code any simpler.
What am I doing wrong, or is it just not possible for an ESP8266 to stay connected to WiFi if an interrupt is firing many times per second?
Unfortunately, I can't seem to keep the ESP connected to WiFi if there's an interrupt firing.
I've cut my code down as much as I can and at the moment I'm just putting a 6.7kHz signal into the D1 pin of the D1 and just trying to get it to count the pulses and output the number to serial.
It works for about 10 seconds and then crashes.
Here's my code:
Code: Select all
#include <ESP8266WiFi.h>
const char* ssid = "SSID";
const char* password = "PASSWORD";
long nextPrint = 1000; // when to print the next message to serial
const int CLKPin = 5; // Pin connected to CLK
volatile long ClkCount = 0; // number of times clock interrupt has fired
void setup() {
Serial.begin(115200);
long startTime = millis();
WiFi.begin(ssid, password); // Connect to the network
Serial.print("Connecting to ");
Serial.print(ssid); Serial.println(" ...");
while (WiFi.status() != WL_CONNECTED) { // Wait for the Wi-Fi to connect
delay(500);
Serial.print(".");
}
Serial.println("Connected to wifi");
//Setting up interrupt ISR on D2 (INT0), trigger function "CLK_ISR()" when INT0 (CLK)is rising
attachInterrupt(digitalPinToInterrupt(CLKPin), CLK_ISR, RISING);
//Set the CLK-pin to input
pinMode(CLKPin, INPUT);
}
void loop() {
if (millis() > nextPrint) {
String msg = "Freq is: ";
Serial.print("Freq is: ");
Serial.println(ClkCount);
ClkCount = 0;
nextPrint += 1000;
}
yield();
}
void CLK_ISR() {
ClkCount++;
}
And the output:
Code: Select all
Connecting to SSID ...
.Connected to wifi
Freq is: 1
Freq is: 1
Freq is: 0
Freq is: 0
Freq is: 1
Freq is: 0
Freq is: 2313
Freq is: 6667
Freq is: 6666
Freq is: 6667
Freq is: 6667
Freq is: 6667
Freq is: 6667
Freq is: 6667
Freq is: 6667
Freq is: 6667
Exception (0):
epc1=0x40202034 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000
ctx: sys
sp: 3ffffc40 end: 3fffffb0 offset: 01a0
>>>stack>>>
3ffffde0: 401067da 00000026 00000000 00000001
3ffffdf0: c0017025 3ffe8d04 3ffee188 00000001
3ffffe00: 00000003 00000008 3ffee99c 00000022
3ffffe10: 3fffc200 401067a0 3fffc258 4000050c
3ffffe20: 40004384 00000030 00000012 ffffffff
3ffffe30: 60000200 00000006 30043003 80000000
3ffffe40: 20000000 3fff0c38 80000000 203fc120
3ffffe50: 00000000 3fffc6fc 00000001 3fff0c3c
3ffffe60: 00000154 003fc120 60000600 00000030
3ffffe70: 40106845 00000080 00000022 3fffc200
3ffffe80: c0017025 3fffc258 4000050c 00000022
3ffffe90: 3fffc200 401067a0 3fffc258 00000022
3ffffea0: 3fffc200 401067a0 3fffc258 4000050c
3ffffeb0: 40202b20 00000030 00000012 ffffffff
3ffffec0: 40000f49 3ffee9e8 00000000 3fffd9d0
3ffffed0: 00000000 00000000 00000000 fffffffe
3ffffee0: ffffffff 3fffc6fc 00000001 3fffdab0
3ffffef0: 00000000 3fffdad0 3ffee9e8 00000030
3fffff00: 3ffee99c 0000000a 3ffe8bc8 402094cc
3fffff10: 00000000 400042db 3ffeff84 40104580
3fffff20: 40004b31 3fff0b84 000001f4 003fc080
3fffff30: 40105aac 000001f4 3ffed190 401004f4
3fffff40: 40106e4d 3fff0b84 00000000 00f8676f
3fffff50: 3ffe8bc8 3ffe8d04 3ffed190 40224d02
3fffff60: 40223d49 40223d52 3ffed004 3ffee1b0
3fffff70: 40228445 3ffed004 3ffee1b0 00f857fe
3fffff80: 4022848a 3fffdab0 00000000 3fffdcb0
3fffff90: 3ffee1c8 3fffdad0 3ffee9e8 40202b43
3fffffa0: 40000f49 40000f49 3fffdab0 40000f49
<<<stack<<<
ets Jan 8 2013,rst cause:2, boot mode:(1,6)
ets Jan 8 2013,rst cause:4, boot mode:(1,6)
wdt reset
I can't see how I can make this code any simpler.
What am I doing wrong, or is it just not possible for an ESP8266 to stay connected to WiFi if an interrupt is firing many times per second?