ADXL345: weird Free Fall Threshold

Hello everybody.

Got a problem with my Arduino Nano and the ADXL345 sensor. I cannot configure correctly the threshold detection.

Below I've included the test sketch I'm running in order to find out the trigger value. The odd is that the ADXL345 is NOT triggering the FF interrupt when falling but it is triggering the FF interrupt when I turn the system facing down (the ADXL345 breakout board pointing in the -z direction).
Also I've always got a OUT-OF-THE-WORLD, NO-SENSE offset on my Z-axis (like a 4g static offset). Tried a couple of sensors, same results...

TY for your help :slight_smile:

#include "Arduino.h"
#include <Wire.h>
#include <ADXL345.h>


  ADXL345 adxl;

void setup() {
  // put your setup code here, to run once:

  Serial.begin(115200);
  Serial.println("ADXL345 Test:");

  adxl.powerOn();
  delay(100);
  adxl.setRangeSetting(ADXL345_RANGE_16G);
  adxl.setFullResBit(true);
  adxl.set_bw(ADXL345_BW_12);

//  adxl.setAxisOffset(B00101010,B10101001,B10000000);
  adxl.setAxisOffset(0,0,0);

#define NES2015_FINDFFRANGE_MIN 32    // NOT triggering
#define NES2015_FINDFFRANGE_MAX 64    // Triggering
#define NES2015_FINDFFRANGE    ((NES2015_FINDFFRANGE_MAX - NES2015_FINDFFRANGE_MIN)/2 + NES2015_FINDFFRANGE_MIN)
Serial.print("FF Th = "); Serial.println(NES2015_FINDFFRANGE);
  adxl.setFreeFallThreshold(NES2015_FINDFFRANGE); //(5 - 9) recommended - 62.5mg per increment
  adxl.setFreeFallDuration(18); //(20 - 70) recommended - 5ms per increment
  adxl.setInterruptMappingAll(
    (ADXL345_INT2_PIN << ADXL345_INT_DATA_READY_BIT) |
    (ADXL345_INT2_PIN << ADXL345_INT_SINGLE_TAP_BIT) |
    (ADXL345_INT2_PIN << ADXL345_INT_DOUBLE_TAP_BIT) |
    (ADXL345_INT2_PIN << ADXL345_INT_ACTIVITY_BIT) |
    (ADXL345_INT2_PIN << ADXL345_INT_INACTIVITY_BIT) |
    (ADXL345_INT1_PIN << ADXL345_INT_FREE_FALL_BIT) |
    (ADXL345_INT2_PIN << ADXL345_INT_WATERMARK_BIT) |
    (ADXL345_INT2_PIN << ADXL345_INT_OVERRUNY_BIT)
  );
  adxl.setInterruptAll(
    (1 << ADXL345_INT_DATA_READY_BIT) |
    (0 << ADXL345_INT_SINGLE_TAP_BIT) |
    (0 << ADXL345_INT_DOUBLE_TAP_BIT) |
    (0 << ADXL345_INT_ACTIVITY_BIT) |
    (0 << ADXL345_INT_INACTIVITY_BIT) |
    (1 << ADXL345_INT_FREE_FALL_BIT) |
    (0 << ADXL345_INT_WATERMARK_BIT) |
    (0 << ADXL345_INT_OVERRUNY_BIT)
  );

  adxl.setFIFOmode(ADXL345_FIFO_BYPASS,ADXL345_INT1_PIN,0x10);

  adxl.printAllRegister();
  Serial.println("\r\n\n\nReadings ---------------");

}


void loop() {
  // put your main code here, to run repeatedly:
  int x,y,z;
  long myRSS;

  byte interrupts = adxl.getInterruptSource();

  if( adxl.triggered(interrupts, ADXL345_FREE_FALL) ){
    adxl.readAccel(&x,&y,&z);
    Serial.print(x); Serial.print(", ");
    Serial.print(y); Serial.print(", ");
    Serial.println(z);
    Serial.println(NES2015_FINDFFRANGE);
    delay(1000);
  }

  if( adxl.triggered(interrupts, ADXL345_DATA_READY) ){
    adxl.readAccel(&x,&y,&z);
    Serial.print(x); Serial.print(", ");
    Serial.print(y); Serial.print(", ");
    Serial.print(z);
    myRSS = (long)x*x + (long)y*y + (long)z*z;
    Serial.print(";    "); Serial.println(myRSS);
  }

}

This is instead some data (axis values read from serial panel and then calculated the RSS with excel):

SAMPLE#,x,y,z,RSS
0,-115,90,864,876.2539586
1,-119,83,864,876.0970266
2,-120,89,869,881.7493975
3,-114,87,870,881.7397575
4,-118,86,866,878.2232063
5,-120,91,866,878.9977247
6,-121,91,867,880.1198782
7,-120,90,867,879.8801055
8,-122,90,867,880.1551
9,-119,89,865,877.6713508
10,-118,86,864,876.2511056
11,-121,85,861,873.6057463
12,-124,86,862,875.1091361
13,-120,90,863,875.9389248
14,-122,86,866,878.7695944
15,-121,90,867,880.0170453
16,-120,93,870,883.1472131
17,-119,84,868,880.1369212
18,-117,73,875,885.8007677
19,-138,12,894,904.6678949
20,-164,-118,904,926.3023265
21,-160,-322,905,973.8115834
22,-66,-260,923,961.1893674
23,-107,-204,947,974.6147957
24,73,-154,898,914.028993
25,0,115,955,961.8991631
26,54,244,878,912.8723898
27,67,328,848,911.6890917
28,-73,347,896,963.6150684
29,-65,317,879,936.6723013
30,-42,331,870,931.7859196
31,49,259,842,882.2958687
32,6,197,845,867.6808169
33,-23,171,847,864.3951643
34,-30,136,856,867.255441
35,-85,100,900,909.5191037
36,-36,85,875,879.85567
37,-43,69,876,879.7647413
38,-41,55,876,878.6819675
39,-39,71,878,881.7289833
40,-38,83,882,886.7113397
41,-23,89,874,878.8208008
42,-25,85,880,884.448981
43,-43,77,884,888.3884286
44,-42,75,878,882.1978236
45,-30,69,874,877.2325803
46,-138,90,877,892.3413024
47,-134,95,877,892.249965
48,-138,90,874,889.3930515
49,-136,88,873,887.9014585
50,-139,90,874,889.548762
51,-139,92,875,890.735651
52,-140,91,874,889.8072825
53,-139,90,872,887.5837989
54,-143,84,871,886.6487467
55,-139,83,865,880.0198861
56,-137,93,861,876.7776229
57,-140,87,853,868.7796038
58,-134,90,851,866.1737701
59,-142,78,838,853.5174281
60,-150,67,830,846.1022397
61,-142,67,823,837.8436608
62,-139,62,805,819.2618629
63,-140,47,781,794.8396065
64,-171,36,761,780.8059938
65,-175,50,744,765.937987
66,-181,32,743,765.3979357
67,-174,-8,720,740.7698698
68,-186,-34,708,732.8137553
69,-173,-38,704,725.9400802
70,-177,-57,697,721.3785414
71,-192,-73,687,717.0509047
72,-192,-107,702,735.6065524
73,-176,-107,670,700.9457896
74,-186,-143,689,727.8502593
75,-196,-148,687,729.5813868
76,-184,-164,687,729.877387
77,-176,-190,684,731.3904566
78,-192,-202,688,742.3018254
79,-181,-192,683,732.1980606
80,-170,-187,666,712.3377008
81,-183,-196,675,726.3126049
82,-166,-216,682,734.3949891
83,-177,-205,675,727.3094252
84,-171,-210,674,726.372494
85,-170,-220,680,734.6427703
86,-172,-217,680,734.2159083
87,-162,-223,682,735.5929581
88,-165,-220,680,733.5018746
89,-173,-211,674,727.1354757

In the attached image is the plot of the RSS column.

Reading the ADXL345 datasheet and according to it, I supposed to just find a RSS value for the trigger, multiply it by 4mg/LSB and divide it for 62.5mg/LSB in order to obtain the value for the THRESH_FF register. The resulting value of 56 I've picked is not triggering. The 48 insted (as it is in the code above) is triggering when tilted to the -z direction... :o