Arduino uno with LIS2DH accelerometer

Hi everyone, I’m new to the forum and to Arduino programming. I’m trying to program an Arduino UNO to read an LIS2DH accelerometer via SPI. Unfortunately I keep getting 0’s in the x, y and z values. Here is my code:

#include <SPI.h>

//Register Addresses
const int OUT_X_L = 0x28; //X-axis acceleration data
const int OUT_X_H = 0x29;
const int OUT_Y_L = 0x2A; //Y-axis acceleration data
const int OUT_Y_H = 0x2B;
const int OUT_Z_L = 0x2C; //Z-axis acceleration data
const int OUT_Z_H = 0x2D;
const byte READ = 0b10000000; 
   
const int CS = 10; 


unsigned int readRegister(byte x) {
    unsigned int r = 0; 
    byte b = x | READ;
    
    digitalWrite (CS, LOW); 
    SPI.transfer(b); 
    r = SPI.transfer (0xFF); 
    digitalWrite (CS, HIGH); 
    return r; 
}

int readval (int x) {
  int val = 0; 
  byte h, l; 
  
       if (x==1) {
       l = readRegister(OUT_X_L);
       h = readRegister(OUT_X_H);
       }
         else if (x == 2) { 
         l = readRegister(OUT_Y_L);
         h = readRegister(OUT_Y_H);
         }
            else if (x == 3) {
            l = readRegister(OUT_Z_L);
            h = readRegister(OUT_Z_H);
            }
            
     val = ( (h<<8) | l);
     return val; 
}


void setup()
{
  pinMode(CS,OUTPUT); 
  
  SPI.begin(); 
  SPI.setBitOrder(MSBFIRST);
  //clock is idle high and data is shifted in and out
  //on the rising edge of the data clock signal, pg. 23
  SPI.setDataMode(SPI_MODE3);
  
  SPI.setClockDivider(SPI_CLOCK_DIV2);
  //Create a serial connection to display the data on the terminal.
  Serial.begin(9600);
  //writeRegister(CTRL_REG1,0x07);

  //SPISettings settingsA(9600, MSBFIRST, SPI_MODE3);

  //SPI.beginTransaction(settingsA);
  
  delay(100);
}



void loop()
{
  Serial.print(" x = "); 
  Serial.print(readval(1));
  Serial.print(" y = "); 
  Serial.print(readval(2));
  Serial.print(" z = "); 
  Serial.println(readval(3));
  delay (500); 

}

My connections are:
Vdd and Vdd0 to 3.3V
GND to GND
CS to pin 10
MISO to pin 12
MOSI to pin 11
SCK to pin 13

And I pulled up (10k) the CS, the MOSI and the CLK and pulled down (10k) the MISO.

And I pulled up (10k) the CS, the MOSI and the CLK and pulled down (10k) the MISO.

Don't pull anything for SPI. The signals will be to slow with resistors pulling up or down the line.

I did it but still doesn't work unfortunately

My connections are:
Vdd and Vdd0 to 3.3V
GND to GND
CS to pin 10
MISO to pin 12
MOSI to pin 11
SCK to pin 13

As the pins in the chip datasheet have different names than you used here I guess that you don't use the chip directly but by some breakout board. Post a link to that board's schematics (it's relevant if you don't connect directly to the chip)!

Define the h variable in readval() to be of type "uint16_t".

Try reading out the temperature value.