External interrupt problem with ESP32

haythemjls
Posts: 27
Joined: Mon Apr 06, 2020 1:32 pm

External interrupt problem with ESP32

Postby haythemjls » Fri Apr 10, 2020 2:01 pm

Hello,
I tested the mpr121 capcitive touche module with my ESP32 via I2C protocol and it works well in loop part, but when I want to test my code with external interrupt by using (IRQ PIN) nothhing happen when I touch any key, despit I tested the same code with my Arduino uno board and it works well with external inetrrupt, I used mpr121_driver from Adafruit.

I attached you my code, anyone help me please.

#include <Wire.h>
#include "Adafruit_MPR121.h"
Adafruit_MPR121 cap = Adafruit_MPR121();

#define IRQ_pin 2
#define Buz 13

volatile uint16_t lasttouched = 0;
volatile uint16_t currtouched = 0;



void IRAM_ATTR data_Interrupt(){

interrupts();


// Get the currently touched pads
currtouched = cap.touched();



for (uint8_t i=0; i<12; i++) {
// it if *is* touched and *wasnt* touched before, alert!
if ((currtouched & _BV(i)) && !(lasttouched & _BV(i)) ) {

Serial.print(i); Serial.println(" touched");
}


// if it *was* touched and now *isnt*, alert!
if (!(currtouched & _BV(i)) && (lasttouched & _BV(i)) ) {

Serial.print(i); Serial.println(" released");
}

}

// reset our state
lasttouched = currtouched;

attachInterrupt(digitalPinToInterrupt(IRQ_pin),data_Interrupt,FALLING);
}


void setup() {
pinMode(IRQ_pin, INPUT_PULLUP);
pinMode(Buz, OUTPUT);
Serial.begin(115200);



if (!cap.begin(0x5A)) {
Serial.println("MPR121 not found, check wiring?");
while (1);
}

delay(2000);

Serial.println("MPR121 found!");
attachInterrupt(digitalPinToInterrupt(IRQ_pin),data_Interrupt,FALLING);
}

void loop() {
// put your main code here, to run repeatedly:



}

ESP_Sprite
Posts: 9730
Joined: Thu Nov 26, 2015 4:08 am

Re: External interrupt problem with ESP32

Postby ESP_Sprite » Sat Apr 11, 2020 8:19 am

Moved to Arduino subforum.

Who is online

Users browsing this forum: No registered users and 54 guests