cancel
Showing results for 
Search instead for 
Did you mean: 

How to read from magnetic sensor?

oleg_sidorovich_1981
Associate II

I use LSM303DLHC. I set the data reading speed for the accelerometer 50 Hz, and for the magnetometer 30 Hz.

For the accelerometer, I check in the STATUS_REG_A register (p.28 LSM303DLHC datasheet) the state of the 3rd bit and at the time = 1 I read the data from the output registers, and I have this flag rises with a frequency of 50 Hz.

int8_t n_bit_status_ready_Acc = 3;

status_ready_Acc = Accel_IO_Read(0x32,LSM303DLHC_STATUS_REG_A);

    if ( ((1 << n_bit_status_ready_Acc) & status_ready_Acc) == (1 << n_bit_status_ready_Acc) )

    {

    ptr = Accel_ReadAcc();

    Ax_3 = ptr[0];

    Ay_3 = ptr[1];

    Az_3 = ptr[2];

    Ax_sum3 = Ax_sum3 + Ax_3;

    Ay_sum3 = Ay_sum3 + Ay_3;

    Az_sum3 = Az_sum3 + Az_3;

    Ncal_current = Ncal_current + 1;

    free(ptr);

     }

those. the variable Ncal_current reaches the value 50 in 1 second.

I do the same for the magnetometer. Status register SR_REG_M (09h) (p.39 LSM303DLHC datasheet). I see data from the magnetometer on the graph that the frequency changes

(if I change the frequency of data output), i.e. The magnetometer is programmed adequately, but I also check the zero bit with the accelerometer. Status register SR_REG_M (09h)

and there almost all the time 1. And it turns out the speed of hundreds of Hz instead of my 30Hz. Why is that? It seems that the same chip works with an axel, but not with a magnetometer.

0 REPLIES 0