How to get data from a sensor's FIRST IN FIRST OUT FIFO register (from two's complement) I want to get acceleration data from a ADXL355 sensor.



My code:

void readFIFO (){
long data[3];
byte data2 [9];

digitalWrite(chipSelectPin, LOW);
SPI.transfer( (FIFO&lt;&lt;1) | 1);
for (int i = 0 ; i &lt; 9; i++){
    data2[i] = SPI.transfer(0x00);
}
digitalWrite(chipSelectPin, HIGH);

Serial.println("Byte data in hex and binary");
 for (int j = 0 ; j &lt; 9 ; j++){
    Serial.print("element "+String(j) +": ");
     Serial.print(data2[j],HEX);
     Serial.print(" ");
     Serial.println(data2[j],BIN);
 }
 for (int z = 0 ; z &lt; 3; z++){
    data[z] = ((data2[z*3]&lt;&lt;12) | (data2[z*3 +1] &lt;&lt; 4) | (data2[z*3+2]  &gt;&gt;4));
 }
 Serial.println("concatenated values: ");
 for (int i = 0 ; i &lt; 3 ; i++){
    Serial.println(data[i]);
 }
}


Sample output:

Byte data in hex and binary
element 0: F9 11111001
element 1: 1B 11011
element 2: 51 1010001
element 3: 0 0
element 4: FD 11111101
element 5: 90 10010000
element 6: C3 11000011
element 7: 2A 101010
element 8: 20 100000
concatenated values: 
-28235
4057
12962


The values are two's complement. Are these the correct values? If not what am I doing wrong?
Since you've had no response to this I'll add my experiences with this chip. I'm not sure why you are reading the FIFO buffer. The chip provides three registers for each of the three axes. I simply read those in a loop. You can find my (still very crude) Python to read these at https://github.com/markrad/ADXL355. I hope it's some help to you.