AnsweredAssumed Answered

STM32F0 I2C code doesn't work

Question asked by eaglewatch Employee on Nov 22, 2013
Latest reply on Nov 4, 2014 by Stroodlemuffin
Hi,
here my code for I2C setup on STM32F051R8 (STM32 discovery board practically)

void set_I2C(void){
  GPIO_InitTypeDef GPIO_InitStructure;
  I2C_InitTypeDef I2C_InitStructure;

  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
     RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);

     /* Configure the I2C clock source. The clock is derived from the HSI */
     RCC_I2CCLKConfig(RCC_I2C1CLK_SYSCLK);

     GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_1);
     GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_1);

     //Configure pins: SCL and SDA ------------------
     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
     GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
     GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
     GPIO_Init(GPIOB, &GPIO_InitStructure);

     I2C_InitStructure.I2C_AnalogFilter = I2C_AnalogFilter_Enable;
     I2C_InitStructure.I2C_DigitalFilter = 0x00;
     I2C_InitStructure.I2C_OwnAddress1 = 0x00; // MPU6050 7-bit adress = 0x68, 8-bit adress = 0xD0;
     I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
     I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
     //I2C_InitStructure.I2C_Timing = 0xA0120227;
     I2C_InitStructure.I2C_Timing = 0x20310A0D;
     I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;

     I2C_Init(I2C1, &I2C_InitStructure);

     I2C_Cmd(I2C1, ENABLE);

}



but when in the main I try to send one data:

I2C_SendData(I2C1, 0xAA);

I don't see any signal on the Pb6 PB7.

Please, can you tell me what's wrong?

Thanks a lot in advance.

Outcomes