Arduino deepsleep with ADXL345 interrupts

Hi, I am trying to write code that would achieve the following:

The arduino is in deep sleep with interrupt 1 from ADXL345 attached to D3. ADXL345 records values in its FIFO buffer until the FIFO buffer's watermark level is reached. At this point the ADXL345 will generate an interrupt that should wake up the Arduino, the Arduino will now burst read values from the FIFO buffer and store them in an array. It will then go back to sleep.
This cycle will keep on repeating.

Here's my code:

#include <Wire.h>
#include <ADXL345.h>
#include <LowPower.h>

ADXL345 adxl;

const byte interruptPin = 3;

void setup() {
  Serial.begin(115200);
  // put your setup code here, to run once:
  adxl.powerOn();
  adxl.setLowPower(1);

  //look of activity movement on this axes - 1 == on; 0 == off
  adxl.setActivityX(1);
  adxl.setActivityY(1);
  adxl.setActivityZ(1);

  //setting all interrupts to take place on int pin 1
  adxl.setInterruptMapping(ADXL345_INT_DATA_READY_BIT,   ADXL345_INT1_PIN );
  adxl.setInterruptMapping(ADXL345_INT_WATERMARK_BIT,     ADXL345_INT1_PIN);

  //register interrupt actions - 1 == on; 0 == off
  adxl.setInterrupt( ADXL345_INT_DATA_READY_BIT, 1 );
  adxl.setInterrupt( ADXL345_INT_WATERMARK_BIT, 1);

  //setting lowest sampling rate
  adxl.setRate(12.5);
  //setting device into FIFO mode
  adxl.setMode(ADXL345_MODE_FIFO);
  //set watermark for Watermark interrupt
  adxl.setWatermark(25);
}

void wakeUp()
{
  Serial.println("I just woke up...");
}

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

  adxl.getInterruptSource();  // reading interrupt status flags
  Serial.println("Going to sleep...");
  attachInterrupt(digitalPinToInterrupt(interruptPin), wakeUp, CHANGE);
  LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
  detachInterrupt(digitalPinToInterrupt(interruptPin));

  int x[25], y[25], z[25];
  byte fifoentries, intEvent;
  fifoentries = adxl.getFifoEntries();
  intEvent = adxl.getInterruptSource();  // reading interrupt status flags
  if (adxl.triggered(intEvent, ADXL345_WATERMARK) )  // if watermark interrupt occured
  {
    Serial.println("Watermark interrupt triggered. Fetching data now." );

    if (fifoentries != 0) {
      // burst read will cause the fifo to empty
      adxl.burstReadXYZ(&x[0], &y[0], &z[0], fifoentries); // reading all samples of FIFO
      for (int i = 0; i < fifoentries; i = i + 5) //Printing only every 5th sample to prevent spam on console
      {
        Serial.print("FIFO data sample: ");
        Serial.print(i);
        Serial.print(", x: ");
        Serial.print(x[i]);
        Serial.print(", y: ");
        Serial.print(y[i]);
        Serial.print(", z: ");
        Serial.println(z[i]);
      }

    }
  }
}

The wakeUp() function is never called with this code, only "Goi?" is printed on the Serial Monitor. I am using the Seeed Studio ADXL345 library and the RocketScream LowPower library for deep sleep. Without the attachInterrupt and the powerDown parts the code works flawlessly with accelerometer values being printed whenever the WATERMARK INTERRUPT is triggered.

Any help would be appreciated. Thanks

The wakeUp() function is never called with this code, only "Goi?" is printed on the Serial Monitor.

 attachInterrupt(digitalPinToInterrupt(interruptPin), wakeUp, CHANGE);

On the hardware interrupt pins only a level interrupt (HIGH or LOW) can awake from powerDown sleeps. A pin change interrupt might be your solution as they trigger only on a change and are able to awake from powerDown sleeps.

I think there is an issue with how the watermark interrupt is implemented, because it never changes state. I have tried to read the value of D3 connected to INT1 pin on the ADXL using digitalRead(3) at various points in the loop and setup and it always returns HIGH. It never changes state when the data sheet states that as soon as the fifo is cleared by burst reading the buffer the watermark bit is cleared.

I have tried to also implement pin change interrupt on pin D3 using this code:

void setup() {
  cli();
  PCICR |= B00000100; // enable PCIE2 group
  PCMSK2 |= B00000010; //enable PCINT17
  sei();
}

ISR(PCINT2_vect)
{
  Serial.println("Interrupt on pin D3...");
}

This infinitely prints "Interrupt on pin D3..." in the Serial Monitor and the actual accelerometer readings are never printed.

I think there is an issue with how the watermark interrupt is implemented, because it never changes state.

What is a "watermark interrupt"?

ISR(PCINT2_vect)
{
  Serial.println("Interrupt on pin D3...");
}

Never, never print to the Serial interface inside an ISR. The Serial object depends on interrupts to do it's work. As inside ISRs interrupts are disabled this may produce a dead lock.

  PCMSK2 |= B00000010; //enable PCINT17

PCINT17 is on pin D1 (TX) so it's activated if you print something on the serial interface. D3 is PCINT19.