AnsweredAssumed Answered

MPU6050(I2C) not working

Question asked by palak patel on Sep 8, 2017
Latest reply on Sep 9, 2017 by Vangelis Fortounas

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??#####@@##

Outcomes