MPU6050 With STM32 reading axes X,Y,Z values problems

by Abdelkader Ben   Last Updated May 25, 2018 09:25 AM

i have a STM32F303 Discovery and i want to use the i2C Bus to receive the x,y,z data from an accelerometer MPU6050 Does anyone has a code source , who can help me ? , the problem is that the adress of the buffers (i2cBuff) are 0 , and the Xaccel , Yaccel , Zaccel too ....

Here is my code:

#include "main.h"
#include "stm32f3xx_hal.h"

/* Private variables-----*/
I2C_HandleTypeDef hi2c1;
uint8_t i;
uint8_t i2cBuff[8];
uint16_t ax,ay,az;
float Xaccel,Yaccel,Zaccel;

#define mpu6050Address 0xD0


int main(void)
{
   HAL_Init();
   /* Configure the system clock */

   /* USER CODE BEGIN 2 */
   for(uint8_t i=0 ; i <255;i++)
   {
       if(HAL_I2C_IsDeviceReady(&hi2c1,i,1 ,10) == HAL_OK )
       {
          HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_12);
          break;
       }
    }


    /* USER CODE END 2 */

    /* Infinite loop */
    /* USER CODE BEGIN WHILE */
    while (1)
    {

       HAL_I2C_Mem_Read(&hi2c1, mpu6050Address, 0x3B, I2C_MEMADD_SIZE_8BIT, &i2cBuff[1], 6, 10);



       ax = -(i2cBuff[1]<<8 | i2cBuff[2]);
       ay = -(i2cBuff[3]<<8 | i2cBuff[4]);
       az = -(i2cBuff[5]<<8 | i2cBuff[6]);

       Xaccel = ax/8192.0;
       Yaccel = ay/8192.0;
       Zaccel = az/8192.0;
      /* USER CODE END WHILE */

      /* USER CODE BEGIN 3 */

      }
      /* USER CODE END 3 */

   }


Related Questions


Calculating the azimuth from LSM303DLHC

Updated May 21, 2018 18:25 PM

LSM6DS3 TIMINGS

Updated March 01, 2018 15:25 PM

Calculating speed using accelerometer

Updated May 11, 2018 09:25 AM


Interrupt and FIFO settings in LSM6DS3

Updated February 27, 2018 13:25 PM