RAK4630 with 2 HW interrupts doesnt works

Hello Friends,

I cant to configure 2 hardware interrupts using RAK4630. My target its to configure the LIS3DH acelerometer registers to activate INT1 and INT2 pins when happens movement and freefall, each event triggers a different hardware interrupts.

Works ok with the INT1 pin from LIS3DH that activates a hardware interrupt in WB_IO5, but doesnt works with the second hardware interrupt from INT2 pin from LIS3DH and WB_IO6.

It’s works ok if i’m polling the WB_IO5 and WB_IO6 pins, but doesnt work if a assign the same IO pins to hardware interrupts. I need hardware interrupts because i need to sleep all the wisblock when nothing happens and wake up only if i recieve any of the two interrupts from acelerometer.

INT1 pin from lis3dh triggers hw interrupt in INT1 from this sensor when detects freefall events.
INT2 pin from lis3dh triggers hw interrupt in INT2 from this sensor when detects motion events.
These pins works ok, but i cant to make hardware interrupt in RAK4630 with motion events.

Here my code:

#define INT1 WB_IO5
#define INT2 WB_IO6

int eventType = 0;
bool freeFallFlag = 0;
bool motionFlag = 0;

/*Aporte Gabriel Parte Interrupciones */
void freeFallInterruptHandler() {
  freeFallFlag = 1;
}

void wakeUpInterruptHandler() {
  motionFlag = 1;
}

#include "SparkFunLIS3DH.h"
#include "Wire.h"

LIS3DH myIMU(I2C_MODE, 0x18); //Default constructor is I2C, addr 0x19.


void configIntteruptsAcelerometer()
{

  //Acá empezamos config wake-up con filtro pasa altos y frefall

  //Paso 1
  uint8_t dataToWrite = 0;
  dataToWrite |= 0x57;//WakeUP INT Config: Encendemos el sensor y activamos ejes X, Y, Z y activamos ODR (sample rate) a 100hz
  dataToWrite |= 0x57;//FreeFall INT Config: (01010111 binario) Encendemos el sensor y activamos ejes X, Y, Z y activamos ODR (sample rate) a 100hz
  myIMU.writeRegister(LIS3DH_CTRL_REG1, dataToWrite);

  //Paso 2
  dataToWrite = 0;
  dataToWrite |= 0xA;//WakeUP INT Config: Filtro pasa altos activado sobre la actividad de interrupción 2 (on interrupt activity 2)
  dataToWrite |= 0x00;//FreeFall INT Config: Filtro pasa altos desactivado
  myIMU.writeRegister(LIS3DH_CTRL_REG2, dataToWrite);


  //Paso 3
  dataToWrite = 0;
  dataToWrite |= 0x40;//FreeFall INT Config: Enlazamos Interrupción 1 al pin INT1 del sensor
  myIMU.writeRegister(LIS3DH_CTRL_REG3, dataToWrite);

  //Paso 3
  dataToWrite = 0;
  dataToWrite |= 0x20;//WakeUP INT Config: Enlazamos Actividad de Interrupción 2 al pin INT2 del sensor
  myIMU.writeRegister(LIS3DH_CTRL_REG6, dataToWrite);

  //Paso 4
  dataToWrite = 0;
  dataToWrite |= 0x00;//WakeUP INT Config: FS = +-2g
  dataToWrite |= 0x00;//FreeFall INT Config: FS = +-2g
  myIMU.writeRegister(LIS3DH_CTRL_REG4, dataToWrite);

  //Paso 5
  dataToWrite = 0;
  dataToWrite |= 0x02;//WakeUP INT Config: Convertimos el pin INT2 del sensor en latch (interruptor)
  dataToWrite |= 0x08;//FreeFall INT Config: Convertimos el pin INT1 del sensor en latch (interruptor)
  myIMU.writeRegister(LIS3DH_CTRL_REG5, dataToWrite);


  //Paso 6
  dataToWrite = 0;
  dataToWrite |= 0x10;//WakeUP INT Config: Configuramos umbral de caída libre en 250mg (0x10 es 16 decimal. Con 2g, 1 lsb es 16mg según datasheet, entonces 16 decimal * 16mg = 256mg)
  myIMU.writeRegister(0x36, dataToWrite); //0x36 = INT2_THS


  //Paso 7
  dataToWrite = 0;
  dataToWrite |= 0xA; //WakeUP INT Config:  0.1 segundos
  myIMU.writeRegister(0x37, dataToWrite); //0x37 = INT2_DURATION

  //Paso 8
  uint8_t dataRead;
  myIMU.readRegister(&dataRead, LIS3DH_REFERENCE);//WakeUP INT Config: leemos el registro REFERENCE

  //Paso 9
  dataToWrite = 0;
  dataToWrite |= 0x2A;//Configuramos el evento de wake-up deseado
  myIMU.writeRegister(0x34, dataToWrite); //WakeUP INT Config: 0x34 = INT2_CFG


  //Acá terminamos config wake-up

  //Acá seguimos configurando freefall
  //Paso 6
  dataToWrite = 0;
  dataToWrite |= 0x16;//FreeFall INT Config: Configuramos umbral de caída libre en 350mg
  myIMU.writeRegister(LIS3DH_INT1_THS, dataToWrite);

  //Paso 7
  dataToWrite = 0;
  dataToWrite |= 0x1E; //FreeFall INT Config: 0.3 segundos
  myIMU.writeRegister(LIS3DH_INT1_DURATION, dataToWrite);

  //Paso 8
  dataToWrite = 0;
  dataToWrite |= 0x95;//FreeFall INT Config: Configuramos la detección de caída libre
  myIMU.writeRegister(LIS3DH_INT1_CFG, dataToWrite);

  //Acá terminamos config freefall

}


void setupAcelerometer(){

  myIMU.begin();
    
  configIntteruptsAcelerometer();


}

void clearAcelerometerRegistersWakeUp(){

  uint8_t dataRead;
  myIMU.readRegister(&dataRead, 0x35);//cleared by reading, 0x35 = LIS3DH_INT2_SRC

}


void clearAcelerometerRegistersFreeFall(){

  uint8_t dataRead;
  myIMU.readRegister(&dataRead, LIS3DH_INT1_SRC);//cleared by reading

}

void setup() {

  pinMode(INT1, INPUT);
  pinMode(INT2, INPUT);

  // put your setup code here, to run once:
  Serial.begin(9600);
  delay(1000); //relax...

  setupAcelerometer();

  //setup DIO interrupt FreeFall
  pinMode(INT1, INPUT);
  attachInterrupt(digitalPinToInterrupt(INT1), freeFallInterruptHandler, RISING);

  //setup DIO interrupt wakeup
  pinMode(INT2, INPUT);
  attachInterrupt(digitalPinToInterrupt(INT2), wakeUpInterruptHandler, RISING);

}

void loop()
{

    if(freeFallFlag){
    Serial.println("INT1 activada (FreeFall)");
    clearAcelerometerRegistersFreeFall();
    freeFallFlag = 0;
  }

  if(motionFlag){

    if (freeFallFlag){

      clearAcelerometerRegistersWakeUp();
      Serial.println("INT1 activada (FreeFall) y también wakeup int");
      freeFallFlag = 0;
      motionFlag = 0;

    }
    else{
    Serial.println("INT2 activada (Motion)");
    clearAcelerometerRegistersWakeUp();
    motionFlag = 0;
    }
    


  }

  Serial.println("########################");

  delay(1000);

}

Hi @lossonfire

I changed your code to use Motion and Click as interrupt sources and it works without problems:


FreeFall message means CLICK detected.

Could be that Motion and Freefall cannot be used together with the LIS3DH
or you made a mistake in the setup for the Freefall.

This is my test code:
RAK4631-Dual-Interrupts.ino (9.2 KB)

Thank you, I didn’t update the post but my problem was that when i make a lot of changes in acelerometer register, i need to make a hard reset to reconfigure the right registers config.
The registers map only go to default when a disconnect from power source.

Thank you.