Skip to main content
mengsophia
Associate II
June 19, 2012
Question

lsm330dl output read problem

  • June 19, 2012
  • 24 replies
  • 4541 views
Posted on June 19, 2012 at 16:50

hi, everyone. i don't understand why the output data XH,XL. is unchange all the time , when i  read the status_reg, i find that there is no new data coming ..and sometimes the same code gave me different output ,like the data is keep changing but totally wrong, even my board is stastic on the table, but the output gives me thousands of degrees bias. i really confusing., any one can help me ?

here is a part of my output

part1:

GYRO_XH  [1]

GYRO_XL: [5]

GYRO_XH  [fffffff5]

GYRO_XL: [c7]

GYRO_XH  [ffffff80]

GYRO_XL: [0]

GYRO_XH  [ffffffff]

GYRO_XL: [f3]

GYRO_XH  [fffffffd]

GYRO_XL: [ef]

GYRO_XH  [ffffffe8]

GYRO_XL: [74]

GYRO_XH  [ffffffff]

GYRO_XL: [ba]

part2:

GYRO_XH: [ffffffff]

GYRO_XL: [e6]

GYRO_X: [ffffffe6]

GYRO_X2: [-26] //2's complement always -26

GYRO_XH: [ffffffff]

GYRO_XL: [e6]

GYRO_X: [ffffffe6]

GYRO_X2: [-26]

very urgent ,many thanks for any help,

#gyro-lsm330dl
    This topic has been closed for replies.

    24 replies

    frankmeyer9
    Associate III
    June 19, 2012
    Posted on June 19, 2012 at 21:17

    You might either misunderstand the sensor, or he is not actually on.

    Did you check the bus ?

    By the way, you could have told if you use SPI or I2C.

    If you receive data correctly, this could mean the sensor is not in the state you suppose, or you interpret the data in an incorrect way.

     

    GYRO_XH  [fffffff5]

     

    GYRO_XH  [ffffff80]

     

    GYRO_XH  [ffffffff]

     

    ...

    This looks like small negative numbers.

    Did you initialize the sensor properly ?

    Maybe the gyros are still off, or uninitialized.

    very urgent ,...

    Don't want to offend you, but this is rarely helpful.

    People here are volunteering, and won't take the pressure.

    But it might be helpful if you post some of the ''problematic'' code.

    Tesla DeLorean
    Guru
    June 19, 2012
    Posted on June 19, 2012 at 21:23

    It was attached.

    The 2's complementing code doesn't make any sense to me, and I would probably cast the floating point conversion differently.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    mengsophia
    Associate II
    June 20, 2012
    Posted on June 20, 2012 at 03:06

    thanks for ur suggestion.

    i did attached my code. i use spi bus, from now on , the read and write  through spi seems correct.  but still can't get valid value from gyro inside.

    by the way , i didn't use any interrupt.  so i don't understand why my senser is not activated. is there something wrong with my configuration? or my define value for the registers are wrong?

    mengsophia
    Associate II
    June 20, 2012
    Posted on June 20, 2012 at 03:14

    er, i'm a bit don't understand.so u think my output value unchange has some relationship with the floating point convertion? er ,may i know how u do it? 

    frankmeyer9
    Associate III
    June 20, 2012
    Posted on June 20, 2012 at 09:44

    It was attached.

     

    Sorry, I didn't notice ..

    The 2's complementing code doesn't make any sense to me,

    Neither to me.

    You just need to put the two byte together properly (i.e. the correct byte order), then you have already a signed short int.

    mengsophia
    Associate II
    June 20, 2012
    Posted on June 20, 2012 at 12:29

    but now the problem is that i can't get valid output data from the gyro. no matter how i turn it , it value is still unchange. how come the same value is overwriten all the time? 

    frankmeyer9
    Associate III
    June 20, 2012
    Posted on June 20, 2012 at 13:24

    And what about the accelerometer data ?

    They are easier to check for correctness, they are supposedly static. Just turn over by 180 deg. in any direction, and one value should change sign (pos.->neg. or vice versa).

    Gyro data are the rotation rate, which is harder to check for sanity without proper test rig.

    mengsophia
    Associate II
    June 20, 2012
    Posted on June 20, 2012 at 16:16

    thanks for suggestion. but i haven't done the accel part. i change to use another new board, now it can give me some valid data, so maybe it's the hardware problem.:( but the calculated degree seems  incorrectly, it's there some wrong with this part?

    GYRO_Y = GYRO_YH<<8 | GYRO_YL;   

        if((GYRO_YH&0x80)==0x80)

         GYRO_Y =-1*  (~GYRO_Y+1);

        GYRO_Yfold = GYRO_Yf;

        GYRO_Yf = GYRO_Y*0.07 - GYRO_Ybias + GYRO_YbiasOffset;

    GYRO_Y_Dold = GYRO_Y_D;

    GYRO_X_D = (GYRO_Xf  + GYRO_Xfold)*0.5 * (GYRO_X_Time-GYRO_X_TimeOld)*0.00001 + GYRO_X_Dold;

    the degree i got are very samll, even i turn 180 degree.it shows me like 20 degrees

    frankmeyer9
    Associate III
    June 20, 2012
    Posted on June 20, 2012 at 16:42

    the degree i got are very samll, even i turn 180 degree.

     

    If you turn it over, the ACCELEROMETER output will flip sign, whatever axis is up/down.

    ...it shows me like 20 degrees

     

    You might have got this wrong.

    A gyro does not give you degrees, it gives you degree per second, i.e. how fast you turn it.

    This is not as easy to test manually, as it produces a significant output only while you turn it - therefore my suggestion to look for the accelerometer output.

    Tesla DeLorean
    Guru
    June 20, 2012
    Posted on June 20, 2012 at 18:43

    The numbers are already in two complement form, testing the sign and multiplying by -1 makes no sense to me.

    GYRO_X = GYRO_XH<<8 | GYRO_XL;          //16-bits, XH followed by XL

    printf(''\r\nGYRO_X: [%x] '',GYRO_X);

    printf(''\r\nGYRO_X2: [%d] '',GYRO_X);

    GYRO_Xfold = GYRO_Xf;

    GYRO_Xf = ((float)GYRO_X * (70.0 / 1000.0)) - GYRO_Xbias + GYRO_XbiasOffset;  //divide the gyro values by 70 to get degrees per second

    GYRO_XmaArray[GYRO_MA_Index] = GYRO_Xf;

    printf(''\r\nGYRO_Xf1: [%f] '',GYRO_Xf);

    I'd probably hold GYRO_XH and GYRO_XL as uint16_t

    Further I would mask the data bits return

    uint16_t GYRO_ReadByte(uint16_t HalfWord)

    {

        uint16_t temp;

        HalfWord = HalfWord << 8;

        HalfWord |= 0x8000;

        GYRO_CS_LOW();

      while (SPI_I2S_GetFlagStatus(GYRO_SPI, SPI_I2S_FLAG_TXE) == RESET);

      SPI_I2S_SendData(GYRO_SPI, HalfWord);

      while (SPI_I2S_GetFlagStatus(GYRO_SPI, SPI_I2S_FLAG_RXNE) == RESET);

        temp = SPI_I2S_ReceiveData(GYRO_SPI) & 0xFF; // should mask the data bits

        GYRO_CS_HIGH();

      return temp;

    }

    I don't know enough about the device, or have one to test, to provide a working example.
    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..