Problem using my accelerometer LIS331

Hi guys, I'm a student in need of help : I have a project and I need to collect data from an accelerometer. The accelerometer that I'm using is the LIS331.
I saw an other topic on the forum about this sensor but it didn't help me. Let me explain you the problem :
I found a program (the same for the guy in the other topic, attached at the end of my message) which is using a library and works perfectly but when I'll need to explain how it works in my project review I'm sure I won't be able to do it. So i prefer to have my own program and be sure to understand everything.

So here is my program : I'll attach the datasheet of the accelerometer.

#include <Wire.h>
#define adress 0x31 // transmit to device #49 (0x31)

void setup()
{
  Wire.begin(); // join i2c bus
  Serial.begin(9600);
  config();
}

void loop()
{
  dispvalues();
  delay(100);
}

void config(void)
{
  Wire.beginTransmission(adress);
  Wire.write(0x20); //going to CTRL_REG1
  Wire.write(0x27); //default value of the register is 0x07 which means that X,Y,Z axis are enabled
  //but the power is down so i need to change power mode by setting it to normal mode
  //which is 0x27 if you look at page 24 of the datasheet.
  Wire.endTransmission();
  delay(15);
  Wire.beginTransmission(adress);
  Wire.write(0x21); //going to CTRL_REG2
  Wire.write(0x00); //begining to be lost here I don't know if i need to access to all the 
  //ctrl registers so I don't write anything in this one. Even if i need to access to several
  //registers I don't know if it is in a particular sequence.
  Wire.endTransmission();
}

void dispvalues(void)
{
  Serial.print("X=");
  Serial.print(readX());
  Serial.print("\t");
  Serial.print("Y=");
  Serial.print(readY());
  Serial.print("\t");
  Serial.print("Z=");
  Serial.print(readZ());
  Serial.println();
}

int readX(void)
{
  int XL, XH;
  Wire.beginTransmission(adress);
  Wire.write(0x28);//going to OUT_X_L REG
  Wire.endTransmission();
  delay(10);
  Wire.requestFrom(adress, 1);
  while(Wire.available())
  {
    XL = Wire.read();
  }
  delay(10);
  Wire.beginTransmission(adress);
  Wire.write(0x29);//going to OUT_X_H REG
  Wire.endTransmission();
  delay(10);
  Wire.requestFrom(adress, 1);
  while(Wire.available())
  {
    XH = Wire.read();
  }
  int xout = (XL|(XH << 8));
  return xout;
}

int readY(void)
{
  int YL, YH;
  Wire.beginTransmission(adress);
  Wire.write(0x2A);//going to OUT_Y_L REG
  Wire.endTransmission();
  delay(10);
  Wire.requestFrom(adress, 1);
  while(Wire.available())
  {
    YL = Wire.read();
  }
  delay(10);
  Wire.beginTransmission(adress);
  Wire.write(0x2B);//going to OUT_Y_H REG
  Wire.endTransmission();
  delay(10);
  Wire.requestFrom(adress, 1);
  while(Wire.available())
  {
    YH = Wire.read();
  }
  int yout = (YL|(YH << 8));
  return yout;
}

int readZ(void)
{
  int ZL, ZH;
  Wire.beginTransmission(adress);
  Wire.write(0x2C);//going to OUT_Z_L REG
  Wire.endTransmission();
  delay(10);
  Wire.requestFrom(adress, 1);
  while(Wire.available())
  {
    ZL = Wire.read();
  }
  delay(10);
  Wire.beginTransmission(adress);
  Wire.write(0x2D);//going to OUT_Z_H REG
  Wire.endTransmission();
  delay(10);
  Wire.requestFrom(adress, 1);
  while(Wire.available())
  {
    ZH = Wire.read();
  }
  int zout = (ZL|(ZH << 8));
  return zout;
}

As you can see I'm not sure about what I did accessing the registers and configuring all of this. I can ensure you that the connections are correct because when I use the program with the library I have my X,Y and Z values displayed correctly. I repost the link of the library because it's clearer to read it : LIS331.h LIS331.cpp
If someone could help me I would be glad because I feel I'm close to make it works

LIS331.h (2.72 KB)

LIS331.cpp (5.83 KB)

AccelerometerValues.ino (334 Bytes)

LIS331HH datasheet.pdf (678 KB)

Do you understand the I2C essentials, and how to use the Wire library?

You'll have to figure out yourself, which control registers are essential for your mode of operation. Look at the working sketch, which further registers are initialized, and what difference this will make to the readings.

You can read and write multiple registers in sequence, by setting the MS (auto increment) bit in the address byte. Else if you transfer a single byte register, you don't need a while loop for reading that value. A check for Wire.available() is meaningful only if you handle the error case, that no bytes have been received before. Else your program may end up in an endless loop, waiting for a Wire.available() that will never become true again. You can check the number of received bytes once, as the result of Wire.requestFrom(). If that's just the requested number of bytes, as should always be, get the bytes in a sequence of Wire.read() calls.