AnsweredAssumed Answered

I2C Issues in STM32F215

Question asked by p.thirukkannan on Jun 26, 2014

I am using STM32F215(master) in my custom board. In this controller is connected to the MPU9150 sensor(slave) via I2C interface.I tried to read the  slave Id of the slave device, but i am getting  whatever i am sending the slave address.Here i note down one thing, after configured the i2c always i am getting the BUSY in SR2 register. I don't know the problem, please help me asap.

Below is my configuration,read and write code for I2C.

static void I2C_Config(void)
    GPIO_InitTypeDef  GPIO_InitStructure;
    I2C_InitTypeDef I2C_InitStructure;
     RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
  /* GPIO Configuration */
  /*Configure I2C SCL pin */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
  GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_UP;
  GPIO_Init(GPIOB, &GPIO_InitStructure);
  /*Configure I2C SDA pin */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
  GPIO_Init(GPIOB, &GPIO_InitStructure);
  /* Connect PXx to I2C_SCL */
 // GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_I2C1);
  /* Connect PXx to I2C_SDA */
 // GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_I2C1);
  /*!< I2C Struct Initialize */
  I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
  I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
  I2C_InitStructure.I2C_OwnAddress1 = 0xA0;
  I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
  I2C_InitStructure.I2C_ClockSpeed = I2C_SPEED;
  I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;

  I2C_Init(I2C1, &I2C_InitStructure);
  I2C_Cmd(I2C1, ENABLE);
 // I2C_GenerateSTART(I2C1, ENABLE);


void MPU_Write(unsigned char Address,unsigned char DataVal)
    I2C_GenerateSTART(I2C1, ENABLE);
    I2C_GenerateSTOP(I2C1, ENABLE);

unsigned char MPU_Read(unsigned char Address)
    int i;
    unsigned char c;
    I2C_GenerateSTART(I2C1, ENABLE);
    I2C_Send7bitAddress(I2C1, 0x68,I2C_Direction_Transmitter);
    I2C_Send7bitAddress(I2C1, 0x68,I2C_Direction_Receiver);
    I2C_GenerateSTOP(I2C1, ENABLE);
    return c;

Advance thanks for your help.