0

i am using esp8266 to calculate the rpm using hall 3144 sensor, and while doing so there is an issue arises in code.

void exti_callback()
{
Serial.println("working");
}
void setup() {

pinMode(D1,INPUT);
attachInterrupt(digitalPinToInterrupt(D1),exti_callback,FALLING);
Serial.begin(115200);
}

void loop() {
Serial.println("Not working");
}

upon further investigation i understand that this specific line

attachInterrupt(digitalPinToInterrupt(D1),exti_callback,FALLING);

of code is giving me error. Earlier i was using D2 pin and was still facing the same error so i thought i am using wrong pin to get the interrupt so i change that pin to pin D1 but same error still persists. How did i know that this line is giving me error because if i comment out this line, whole code works perfectly, and void loop () also starts to work fine then.

I have even tried using different baud rate, different upload rate but the issue persists. I have even change the USB cable, USB port and what not but still error came. This is the error.

load 0x4010f000, len 3424, room 16
tail 0
chksum 0x2e
load 0x3fff20b8, len 40, room 8 
tail 0
chksum 0x2b
csum 0x2b
v00041f10
~ld
⸮⸮⸮⸮o쒜p⸮⸮n|⸮l⸮⸮$`b⸮⸮|r⸮$⸮o⸮⸮o⸮
ets Jan  8 2013,rst cause:2, boot mode:(3,6)

this same error is keep getting generated again and again.

enter image description here

I have even tried using different baud rate, different upload rate but the issue persists. I have even change the USB cable, USB port and what not but still error came.


EDIT#1

I tried your Button code as said by @MartinR its giving same error. But i have made a progress

int flag = 0;
void ICACHE_RAM_ATTR hallInterrupt();
void setup() {
Serial.begin(115200);
pinMode(D5, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(D5), hallInterrupt, FALLING);
}

void loop() {
Serial.println(flag);
delay(500);

}
void hallInterrupt()
{
flag = 1;
delay(500);
}

this code at least run without giving the previous error but still this code unable to enter the interrupt function. I mean to say that this code is printing 0, but as soon i provide some interrupts to hall sensor using magnets it's giving me new kind of hex numberical error.

2
  • Please see How to Ask, then revise your title to ask a clear, specific question and not just state that you have an issue. We all have issues. Also take the tour. Commented Dec 20, 2023 at 16:23
  • 1) For ESP8266, ISR() function need to have ICACHE_RAM_ATTR attribute (meaning to run it from RAM). Read documentation on interrupt. 2) add volatile to the declaration of flag to avoid it from being over-optimized away by the compiler. Commented Dec 26, 2023 at 8:59

1 Answer 1

0

Try defining D1 as GPIO 5 which is the corresponding pin if im not wrong.

#define D1 5

If somehow D1 is reserved try calling it different (BUTTON for example).

#define BUTTON 5

void exti_callback()
{
Serial.println("working");
}
void setup() {

pinMode(BUTTON,INPUT);
attachInterrupt(BUTTON,exti_callback,FALLING);
Serial.begin(115200);
}

void loop() {
Serial.println("Not working");
delay(500);
}

Hope this helps.


#EDIT:

Code Working Screencap

Your edited code working Screencap

Sign up to request clarification or add additional context in comments.

6 Comments

it's not working still. I have used all the pin from D1 to D8 still the error is same. Could u help me to resolve the error, like what that error is trying to say?
Have you tried a code like this? I eddited the previous comment with the actual modified code. The error code is due to a boot of the board due to a possible coding error.
And btw, watch out the function attachInterrupt(digitalPinToInterrupt(D1),exti_callback,FALLING); The function should look like this: attachInterrupt(GPIOPin, ISR, Mode); so for the first argument just put the GPIO pin.
Kindly look into the question again. i have edited it with my progress.
Well, I don´t know what to say... I just tried the code in my ESP board and works perfectly for me. I would try to change the hall sensor for a simple button for testing, but the code i provided you just works fine. (Also added a delay for debuging...)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.