cancel
Showing results for 
Search instead for 
Did you mean: 

Readings not constant

gazelle
Associate

Hi all,

I'm a newbie in approaching STM32, so sorry if question could be stupid. I am trying to connect via I2C an IMU sensor MPU6050 to my nucleo board STM32f44.

I read data through the following function that I call from main function, as you could see in the following code excerpt.

......

void MPU6050_Get_Accel_RawData(RawData_Def *rawDef)

{

uint8_t i2cBuf[2];

uint8_t AcceArr[6], GyroArr[6];

uint8_t ReadTemp[2];

I2C_Read(INT_STATUS_REG, &i2cBuf[1],1);

if((i2cBuf[1]&&0x01))

{

I2C_Read(ACCEL_XOUT_H_REG, AcceArr,6);

//Accel Raw Data

rawDef->x = ((AcceArr[0]<<8) + AcceArr[1]); // x-Axis

rawDef->y = ((AcceArr[2]<<8) + AcceArr[3]); // y-Axis

rawDef->z = ((AcceArr[4]<<8) + AcceArr[5]); // z-Axis

//Read Temp Data

I2C_Read(TEMP_OUT_H_REG, ReadTemp,2);

Temp=((ReadTemp[0]<<8) + ReadTemp[1]);

//Gyro Raw Data

I2C_Read(GYRO_XOUT_H_REG, GyroArr,6);

GyroRW[0] = ((GyroArr[0]<<8) + GyroArr[1]);

GyroRW[1] = (GyroArr[2]<<8) + GyroArr[3];

GyroRW[2] = ((GyroArr[4]<<8) + GyroArr[5]);

}

}

........

int main(void){ 

 while (1)

  {

  ...

  MPU6050_Get_Accel_RawData(....);

  ...

   HAL_Delay(1000);

  }

 }

If could be useful, I report below the implementation of I2CRead function

void I2C_Read(uint8_t ADDR, uint8_t *i2cBif, uint8_t NofData)

{

uint8_t i2cBuf[2];

uint8_t MPUADDR;

//Need to Shift address to make it proper to i2c operation

MPUADDR = (MPU_ADDR<<1);

i2cBuf[0] = ADDR;

HAL_I2C_Master_Transmit(&i2cHandler, MPUADDR, i2cBuf, 1, 10);

HAL_I2C_Master_Receive(&i2cHandler, MPUADDR, i2cBif, NofData, 100);

}

 Said this, what I observe is that while temperature values are constant (as expected), althought my sensor is still, readings of accelerometer (Ax,Ay,Az in the following lines) and gyroscope (Gx,Gy,Gz) values are variable.

Below an example of the output:

  

Reading #

3197

******

Ax: 70.4....

Ay: 1.34....

Az: 1071....

Gx: -7.9....

Gy: 1.49....

Gz: -1.2....

**** Temperature 23.5 C....

Reading #

3198

******

Ax: 76.2....

Ay: 6.46....

Az: 1066....

Gx: -7.9....

Gy: 1.44....

Gz: -1.2....

**** Temperature 23.5 C....

Why do this happens? Is it a normal behaviour?

Thank you all for your precious help.

3 REPLIES 3

This doesn't look to be corrupted data during tranfer but sensor noise. Thus, for answer you have to resort to the sensor's datasheet/manual.

JW

gazelle
Associate

Hi @Community member​ , thank you for your quick reply.

Sorry again for the stupid question.

Are you maybe referring to this?

0690X00000BwZ9hQAF.png

If yes, could you please indicate me how to proceed?

Thank you again for your precious help.

I'm not familiar with gyro/accelerometers, sorry.

Generally, you cope with sensor noise by filtering, of which the sliding average is the simplest one. It's then the matter of tradeoff between response/speed and precision, how many values you want to include in the average.

JW