Problem reading registers of L3GD20H with SPI

Hello,

I am currently working on a project that uses the L3GD20H that I bought off adafruit's website. I am just playing with it right now and I am trying to read the WHO_AM_I register to start simple. according to the datasheet, the WHO_AM_I register has the value 11010111 but when i try to read it, i get 10111111.

Here is my code:

#include  <SPI.h>
#define WHOAMI      0x0F
#define CTRL1       0x20
#define CTRL2       0x21
#define OUT_X_L     0x28
#define OUT_X_H     0x29
#define OUT_Y_L     0x2A
#define OUT_Y_H     0x2B
#define OUT_Z_L     0x2C
#define OUT_Z_H     0x2D
#define STATUS      0x27
#define LOW_ODR     0x39
#define readData    0x80
void setup() {

 Serial.begin(9600);
 SPI.begin();
 pinMode(10,OUTPUT);
 digitalWrite(10,HIGH);
 readWHOAMI();

}

void loop() {


}

void readWHOAMI(){

  byte address;
  digitalWrite(10,LOW);
  address = SPI.transfer(readData | WHOAMI);
  digitalWrite(10,HIGH);
  Serial.println(address,BIN);
  
}

Not sure what i am doing wrong here

Not sure what i am doing wrong here

You read the data before you sent the command:

address = SPI.transfer(readData | WHOAMI);

As you can see in the diagram on page 30 of the datasheet, you first have to send the command byte, then read the answer:

SPI.transfer(readData | WHOAMI);
address = SPI.transfer(0x00);

It works now thank you!