Skip to main content
bifrost
Associate II
May 16, 2013
Question

[stm32f3discovery]jumpy sensor reading (megne and gyro)

  • May 16, 2013
  • 3 replies
  • 805 views
Posted on May 16, 2013 at 23:25

Hi,

i'm reading the sensors on my STM32F3-discovery, and i've found out the reading arequite ''jumpy''. That means gyro and magnetometer value have consistent change (>1024) aven when the board is static. notice that accelerometer reading are fine.

gyro and accelerometer are in sigle reading, and i chek the data ready bit (ZYXDA for gyro and acc, DRDY for magne) is set. BTW it still give me strange update frequency for sensor, like this bit is almost always set...

I'm writing the reading over USB as audio USB card. here the output:

[code]

MagZ    diff: 1024.0    a:-16896.0    b:-17920.0

GyroY    diff: 17495.0    a:17491.0    b:-4.0

GyroZ    diff: 16621.0    a:16640.0    b:19.0

GyroY    diff: -17477.0    a:14.0    b:17491.0

GyroZ    diff: -16627.0    a:13.0    b:16640.0

MagZ    diff: 1024.0    a:-16896.0    b:-17920.0

GyroY    diff: 17495.0    a:17491.0    b:-4.0

GyroZ    diff: 16621.0    a:16640.0    b:19.0

GyroY    diff: -17477.0    a:14.0    b:17491.0

GyroZ    diff: -16627.0    a:13.0    b:16640.0

MagZ    diff: 1024.0    a:-16896.0    b:-17920.0

GyroY    diff: 17495.0    a:17491.0    b:-4.0

GyroZ    diff: 16621.0    a:16640.0    b:19.0

GyroY    diff: -17477.0    a:14.0    b:17491.0

GyroZ    diff: -16627.0    a:13.0    b:16640.0

MagZ    diff: 1024.0    a:-16896.0    b:-17920.0

GyroY    diff: 17495.0    a:17491.0    b:-4.0

GyroZ    diff: 16621.0    a:16640.0    b:19.0

GyroY    diff: -17477.0    a:14.0    b:17491.0

GyroZ    diff: -16627.0    a:13.0    b:16640.0

MagZ    diff: 1024.0    a:-16896.0    b:-17920.0

GyroY    diff: 17495.0    a:17491.0    b:-4.0

GyroZ    diff: 16621.0    a:16640.0    b:19.0

GyroY    diff: -17477.0    a:14.0    b:17491.0

GyroZ    diff: -16627.0    a:13.0    b:16640.0

MagZ    diff: 1024.0    a:-16896.0    b:-17920.0

GyroY    diff: 17495.0    a:17491.0    b:-4.0

GyroZ    diff: 16621.0    a:16640.0    b:19.0

GyroY    diff: -17477.0    a:14.0    b:17491.0

GyroZ    diff: -16627.0    a:13.0    b:16640.0

read/sec:20963.831867057674 byte/sec: 179863.147605083

sensor read/s: giro 2783 acc 5110 magne 5206

different sensor read/s: giro 2783 acc 2783 magne 2476

[/code]

and a peace of code, the part for gyro reding:

[code]

uint8_t Gyro_ReadAngRate (uint16_t* pfData)

{

    uint8_t tmpreg;

    L3GD20_Read(&tmpreg,L3GD20_STATUS_REG_ADDR,1);

    if (!(tmpreg & 0x08)){ //no data ready!

        return 0;

    }

    int i =0;

    L3GD20_Read(buffer,L3GD20_OUT_X_L_ADDR,6);

    for(i=0; i<3; i++)

    {

        pfData[i]=(int16_t)(((uint16_t)buffer[2*i+1] << 8) + buffer[2*i]);

    }

    return 1;

}

[/code]
    This topic has been closed for replies.

    3 replies

    bifrost
    bifrostAuthor
    Associate II
    August 23, 2013
    Posted on August 23, 2013 at 18:06

    up?

    raptorhal2
    Lead
    August 24, 2013
    Posted on August 24, 2013 at 16:01

    One observation - the code uses unsigned 8 and 16 bit variables for gyro readings, the gyro produces 2's complement 16 bit values. That could explain the large jumps.

    Cheers, Hal

    raptorhal2
    Lead
    August 27, 2013
    Posted on August 27, 2013 at 18:37

    The supplied driver for this device says L3GD20_Read gets MS byte first, LS byte second. Are you processing the buffer bytes backwards ?

    Cheers, Hal