How to get values in terms of G in STM32F3 Discovery board

accelerometerststm32

I am working on STM32 F3 Discovery Board. I am accessing accelerometer of the board. While doing so I am getting values for X,Y and Z axes.
But these values are some random numbers.
I want the output in terms of G (9.8).
The sensitivity of sensor is set to 2g.
The function I wrote for getting these values is as follows:
I am showing code for one axis only because it is same for all three axes.

USART_SendData(USART1, 'Y');
    //  tab=Yval;
    tab= (int8_t)Buffer[1];
        if(tab<0)
        {
        USART_SendData(USART1, '-');
            tab*=-1;
        }
        rem=tab/100;
        tab=tab-rem*100;
        s=rem+48;
        USART_SendData(USART1,s);
         Delay(5);
        rem=tab/10;
        tab=tab-rem*10;
        s=rem+48;
        USART_SendData(USART1,s);
         Delay(5);
        rem=tab;
        //tab=tab-rem*100;
        s=rem+48;
        USART_SendData(USART1,s);
         Delay(5);
        //  send(tab);
            USART_SendData(USART1, '\n');

             Delay(5);

I have also read in the data sheet of acceleromter used on the board "LIS302DL" that these values are stored in registers Outx, Outy and Outz but I am not able to access these registers.
Please help me to get the values in terms of G.

Best Answer

You can work out the scaling of your sensor by repeating your measurement with the board flipped over. The difference between the two measurements will be 2g. So, record your x1, y1 and z1 values. Flip the board over and record second x2, y2 and z2 values. Your zero points are then just the average of each pair of readings.

X0 = (x1+x2)/2. (Same for y0 and z0)

Scaling is the distance between the two measurements divided by 2g

Counts per g = Sqrt ((z1-z2)^2+(y1-y2)^2+(x1-x2)^2)/2

If only one measurement changes significantly (say x), while the other two have nearly the same value, then this simplifies to:

Counts per g = (X1-x2)/2