cancel
Showing results for 
Search instead for 
Did you mean: 

MPU6050(I2C) not working

palak patel
Associate
Posted on September 08, 2017 at 15:38

Hello All,

I am using STM32F100 MCU for MPU6050 sensor interfacing.

I am using I2C.

when i generate code , i get it

void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c)

{

GPIO_InitTypeDef GPIO_InitStruct;

if(hi2c->Instance==I2C1)

{

/* USER CODE BEGIN I2C1_MspInit 0 */

/* USER CODE END I2C1_MspInit 0 */

/**I2C1 GPIO Configuration

PB6 ------> I2C1_SCL

PB7 ------> I2C1_SDA

*/

GPIO_InitStruct.Pin = MPU6050_SCL_Pin|MPU6050_SDA_Pin;

GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;

GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;

HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

/* Peripheral clock enable */

/* USER CODE BEGIN I2C1_MspInit 1 */

__HAL_RCC_I2C1_CLK_ENABLE();

/* USER CODE END I2C1_MspInit 1 */

}

}

with this code,

  • i am not getting Device address as 0x68/69 everytime.1 out of 15 times, i get 0x68 .
  • Device is not initializing.(Getting HAL_BUSY flag) when address is not 0x68.
  • when i get 0x68(it is very rare) , MPU is working and i get correct steps count from my code of MPU6050

when i put CLOCK_ENABLE before GPIO_ENABLE ,

  • i got device address correctly every time(15 out of 15).
  • but I am getting 2 issues

                   1. functionality of MPU is not working. step count is not working

                      2. I am getting switch interrupt continuously,even if i am not pressing switch.

                      3. when i disable interrupt, still MPU6050 is not working.

Please help me to resolve this.

why I2C is not giving correct address??♯♯♯♯♯@@♯♯

#i2c-busy #i2c #mpu6050
1 REPLY 1
Posted on September 09, 2017 at 23:25

Hi!

>>'when i put CLOCK_ENABLE before GPIO_ENABLE'

In my opinion this is irrelevant with issue.

>>'Device is not initializing.(Getting HAL_BUSY flag) when address is not 0x68'

the address of mpu 6050 is 0x68 ORed with AD0 pin (0x01, 0x00).

AD0 pin normaly is connected to ground or VCC.

So the slave address is determined.  Is 0x68  or 0x69

Use this determined address only.

>>' 2. I am getting switch interrupt continuously,even if i am not pressing switch.'

>>' 3. when i disable interrupt, still MPU6050 is not working.'

Make a new project with only the relevant with problem code, to have clearer view about the SPI issue.

This switch and interrupt doesn't help to focus to this problem.

Assuming that you use a 3.3v module

Check I2C bus's pullup resistors first.

Check AD0 pin not to be floated.

After I2c initialisation code, call HAL_I2C_Mem_Read(&hi2c, MPU6050_I2C_ADDR<<1, 0x0075, 1, &data, 1, 100). returned data must be 0x68

In case you don't make any progress, Post your  .IOC file  with main .c  and some schematic of your MPU module.