Arduino Due with SPI & LIS3DH

HI Everybody, I’ve recently got hold of a Due and trying to implement a SPI connection to a lis3dh accelerometer.
Data sheet: http://www.st.com/st-web-ui/static/active/en/resource/technical/document/datasheet/CD00274221.pdf

I’ve started ti read of the WHO_I_AM register, just to make sure that my connection works and that I can actually read something, which return the correct value.
But after that I tried to write to the ctrl_reg1-register to take it out of powerdown mode, and set it in measure mode of 400MHz.
Then to make sure the Write succeded, I’m reading the value of the same register. That´s where something goes wrong as I keep getting the default value of 0x07 instead of the one I tried to write(0x77).

Could if misinterpret the correct data mode or bit order from the datasheet?
I’m currently using mode3 and MSB-first.
Anyone have any good suggestions? Am I totally stupid? :slight_smile:

#include <SPI.h>

//Register Addresses:
const int CTRL_REG1 = 0x20; //Register that can enable,disable axes and Powermodes
const int WHO_AM_I = 0x0F; //Dummy register, set at 0x33
const byte READ = 0b10000000;//LIS3DH's read command
const byte WRITE = 0b00111111;//LIS3DH's write command
const int ss = 10;//Arduino ss pin10

void setup() {  
  Serial.begin(9600);//Pc communication  
  pinMode(ss,OUTPUT); //set ss-pin to output
  
  SPI.begin();//initiate SPI
  SPI.setBitOrder(MSBFIRST);//page 23/42 in datasheet
  SPI.setDataMode(SPI_MODE3); //page 22/42-23/42 in datasheet
  SPI.setClockDivider(ss,21);// 4 MHz
  
  //get out of powerdown and set to 400Hz,all axis on.
  writeRegister(CTRL_REG1,0x77); //set controllreg1 to 0b01110111 (0x77)
  delay(100);//maybe not needed?
  Serial.println(readRegister(CTRL_REG1), HEX);//Make sure controllreg1 is actually set to 0x77. 
  delay(100);//maybe not needed?
}

void loop() {    
  delay(500);//just to have something to loop
}


byte readRegister(byte thisRegister)
{
    byte result = 0;   //result to return
    byte dataToSend = thisRegister | READ; //make sure that the two MSB are set to 10, to enable read-mode.
    
    digitalWrite(ss,LOW); //set slaveselect
    SPI.transfer(dataToSend);//Send a byte with "read-command and reg-adress"
    result = SPI.transfer(0x00);//Send whatever just to initiate transfer 
    digitalWrite(ss, HIGH);//Set the Chips Select pin high to end the SPI packet.
    
    return result;
}

void writeRegister(byte thisRegister, byte thisValue)
{
  //set the two MSB to 00, to enable write mode.
  byte dataToSend = thisRegister & WRITE;//Maybe not needed as LIS3dh reg-adress is always in lower 6bits?
  
  digitalWrite(ss,LOW);//Set Chip Select pin low to signal the beginning of an SPI packet
  SPI.transfer(dataToSend);//Transfer the register address over SPI
  SPI.transfer(thisValue);//Transfer the desired register value over SPI.
  digitalWrite(ss,HIGH);//Set the Chip Select pin high to signal the end of an SPI packet
}

It seems that Spi_mode(0) lets me write to a register and when I read it, I got the new,correct, value. But I can´t undestand from the data sheet why it should be mode0 and not mode3. Can anyone explain this perhaps?