Multiple ADXL362 sensors over SPI

Hi,
I am building a project using arduino uno that samples multiple ADXL362 sensors over an SPI connection.
I can make one work and read the correct values, but whenever i connect multiple sensors all of their readings are the same’ even though i am moving one of them (image attached).
my circuit is connect as suggested in this post: Better SPI Bus Design in 3 Steps

i have tried changing their reading speed setting a higher delay and using transactions but i cant seem to make it work.

this is my program code:

#include <SPI.h>
#include <ADXL362.h>

int startPin = 10;
const int numSensors = 3;
ADXL362 XL[numSensors];
double M[numSensors][3];
int iteration = 4;
String name = "XL";
int8_t XValue, YValue, ZValue, Temperature;

void setup() {
  Serial.begin(9600);
  SPI.begin();
  SPI.setDataMode(SPI_MODE0); //CPHA = CPOL = 0    MODE = 0
  delay(1000);
  for(int i = 0; i < numSensors; i++) {
    XL[i].begin(startPin - i);                   // Setup SPI protocol, issue device soft reset
    XL[i].beginMeasure();              // Switch ADXL362 to measure mode
  }
  for(int i = 0; i < numSensors; i++) {
    digitalWrite(startPin - i, HIGH);
  }
}

void loop() {
  // read all three axis in burst to ensure all measurements correspond to same sample time
  double tempX, tempY, tempZ;
  long t = millis();
  for(int j = 0; j < iteration; j++) {
    for(int i = 0; i < numSensors; i++) {
      XL[i].readRawXYZTData(XValue, YValue, ZValue);
      tempX = XValue / (127.0 / 2);
      tempY = YValue / (127.0 / 2);
      tempZ = ZValue / (127.0 / 2);
      M[i][0] += tempX / iteration;
      M[i][1] += tempY / iteration;
      M[i][2] += tempZ / iteration;
      delay(10);
    }
  }
  for(int i = 0; i < numSensors; i++) {
    Serial.print(name + (i+1) + "\tXVALUE=");
    Serial.print(M[i][0] + 0.24);
    Serial.print("\tYVALUE=");
    Serial.print(M[i][1] + 0.06);
    Serial.print("\tZVALUE=");
    Serial.println(M[i][2] - 0.5);
    M[i][0] = 0;
    M[i][1] = 0;
    M[i][2] = 0;
  }
  delay(100);                // Arbitrary delay to make serial monitor easier to observe
}

this is the ADXL362 library with minor changes to it:

void ADXL362::begin(int16_t chipSelectPin) {
 slaveSelectPin = chipSelectPin;
 pinMode(slaveSelectPin, OUTPUT);
 delay(1);
 // soft reset
 SPIwriteOneRegister(0x1F, 0x52);  // Write to SOFT RESET, "R"
 delay(10);
 digitalWrite(slaveSelectPin, HIGH);
#ifdef ADXL362_DEBUG
 Serial.println("Soft Reset\n");
#endif
 }
 
//
//  beginMeasure()
//  turn on Measurement mode - required after reset
// 
void ADXL362::beginMeasure() {
 byte temp = SPIreadOneRegister(0x2D); // read Reg 2D before modifying for measure mode
 byte filter = SPIreadOneRegister(0x2C);
#ifdef ADXL362_DEBUG
 Serial.print(  "Setting Measeurement Mode - Reg 2D before = "); 
 Serial.print(temp); 
#endif

 // turn on measurement mode
 byte tempwrite = temp | 0x02; // turn on measurement bit in Reg 2D
 byte filterWrite = 0x13;
 SPIwriteOneRegister(0x2C, filterWrite); // Write to FILTER_CTL, Measurement Mode
 delay(10);
 SPIwriteOneRegister(0x2D, tempwrite); // Write to POWER_CTL_REG, Measurement Mode
 delay(10);
#ifdef ADXL362_DEBUG
 temp = SPIreadOneRegister(0x2D);
 Serial.print(  ", Reg 2D after = "); 
 Serial.println(temp); 
 Serial.println();
#endif
}

void ADXL362::readRawXYZTData(int8_t &XData, int8_t &YData, int8_t &ZData){
  // burst SPI read
  // A burst read of all three axis is required to guarantee all measurements correspond to same sample time
  SPI.beginTransaction(SPISettings(14000000, MSBFIRST, SPI_MODE0));
  digitalWrite(slaveSelectPin, LOW);
  SPI.transfer(0x0B);  // read instruction
  SPI.transfer(0x08);  // Start at XData Reg
  XData = SPI.transfer(0x00);
  YData = SPI.transfer(0x00);
  ZData = SPI.transfer(0x00);
  digitalWrite(slaveSelectPin, HIGH);
  SPI.endTransaction();
}

byte ADXL362::SPIreadOneRegister(byte regAddress){
 byte regValue = 0;
  
 digitalWrite(slaveSelectPin, LOW);
 SPI.transfer(0x0B);  // read instruction
 SPI.transfer(regAddress);
 regValue = SPI.transfer(0x00);
 digitalWrite(slaveSelectPin, HIGH);

 return regValue;
}

void ADXL362::SPIwriteOneRegister(byte regAddress, byte regValue){
  
 digitalWrite(slaveSelectPin, LOW);
 SPI.transfer(0x0A);  // write instruction
 SPI.transfer(regAddress);
 SPI.transfer(regValue);
 digitalWrite(slaveSelectPin, HIGH);
}

int16_t ADXL362::SPIreadTwoRegisters(byte regAddress){
 int16_t twoRegValue = 0;
  
 digitalWrite(slaveSelectPin, LOW);
 SPI.transfer(0x0B);  // read instruction
 SPI.transfer(regAddress);  
 twoRegValue = SPI.transfer(0x00);
 twoRegValue = twoRegValue + (SPI.transfer(0x00) << 8);
 digitalWrite(slaveSelectPin, HIGH);

 return twoRegValue;
}  

void ADXL362::SPIwriteTwoRegisters(byte regAddress, int16_t twoRegValue){
 byte twoRegValueH = twoRegValue >> 8;
 byte twoRegValueL = twoRegValue;
  
 digitalWrite(slaveSelectPin, LOW);
 SPI.transfer(0x0A);  // write instruction
 SPI.transfer(regAddress);  
 SPI.transfer(twoRegValueL);
 SPI.transfer(twoRegValueH);
 digitalWrite(slaveSelectPin, HIGH);
}

Any help will be appreciated, I’m running out of ideas.
Thanks.

my circuit is connect as suggested in this post: Better SPI Bus Design in 3 Steps

Which of these? For your setup you should choose the one labeled "Poor Design".

Before calling the begin() method of the ADXL362 class you should set all CS pins as outputs and to high. This is necessary because the begin method does already send commands over the SPI bus, so the CS pins must be high for all chips not involved.

Was the attachment intentional? I don't hope so.