Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Esp32 interups #64

Open
dmdelorme opened this issue Dec 24, 2018 · 2 comments
Open

Esp32 interups #64

dmdelorme opened this issue Dec 24, 2018 · 2 comments

Comments

@dmdelorme
Copy link

dmdelorme commented Dec 24, 2018

void ICACHE_RAM_ATTR DigitalPinISR(int idx) {

This may or may not work as hoped/expected depending on where and when the counter values change.
ie if a interrupt is generated while changing value.. in a different area of code

I have included a snippet of code. for esp32 external interrupt.


`const byte interruptPin = 25;
volatile int interruptCounter = 0;
int numberOfInterrupts = 0;
 
portMUX_TYPE mux = portMUX_INITIALIZER_UNLOCKED;
 
void IRAM_ATTR handleInterrupt() {
  portENTER_CRITICAL_ISR(&mux); // this prevent collisions during a write
  interruptCounter++;
  portEXIT_CRITICAL_ISR(&mux); // release the lock
}
 
void setup() {
 
  Serial.begin(115200);
  Serial.println("Monitoring interrupts: ");
  pinMode(interruptPin, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(interruptPin), handleInterrupt, FALLING);
 
}
 
void loop() {
 
  if(interruptCounter>0){
 
      portENTER_CRITICAL(&mux); //lock to prevent write collision while we change the value
      interruptCounter--;
      portEXIT_CRITICAL(&mux);// unlock
 
      numberOfInterrupts++;
      Serial.print("An interrupt has occurred. Total: ");
      Serial.println(numberOfInterrupts);
  }
}`
  
@dmdelorme
Copy link
Author

dmdelorme commented Dec 24, 2018

ICACHE_RAM_ATTR vs IRAM_ATTR
on an esp32 when ICACHE is used the code is stored in flash slower when IRAM is used the code is stored in RAM faster..
https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/general-notes.html

Not a hard fix.

I not 100% on this ReactESP does this different and i do not full understand what they are doing.

@mxtommy
Copy link
Owner

mxtommy commented Jan 1, 2019

Yup need to update that stuff for esp32 :)

ReactESP is a cool little library to help with timing and stuff. rather than having a bunch of timers running ReactESP handles it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants