AnsweredAssumed Answered

i2c is not working for stm32f051

Question asked by Evert on Nov 5, 2013
Latest reply on Nov 5, 2013 by Clive One
Hello everybody,

I have an application for the STM32f051 wich has a i2c device connected
I have configured and initialized the i2c, however when I send some data both SDA and SDI lines are staying 'high', I don't see any pulses on any of the lines.
I have configured the bus like this:

    /* Connect PXx to I2C_SCL */
    GPIO_PinAFConfig(GPIOB, GPIO_Pin_6, GPIO_AF_1);

    /* Connect PXx to I2C_SDA */
    GPIO_PinAFConfig(GPIOB, GPIO_Pin_7, GPIO_AF_1);

    /*!< Configure I2C pins: SCL */
    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_NOPULL;
    GPIO_Init(GPIOB, &GPIO_InitStructure);

    /*!< Configure I2C pins: SDA */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
    GPIO_Init(GPIOB, &GPIO_InitStructure);

I have initialized my clocks like this:

         RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA |
         RCC_AHBPeriph_GPIOB |
         RCC_AHBPeriph_GPIOC |
         RCC_AHBPeriph_GPIOF , ENABLE);
         RCC_APB1PeriphClockCmd( RCC_APB1Periph_TIM2  |        /* for 1ms timer */
         RCC_APB1Periph_TIM3  |
         RCC_APB1Periph_USART2 |
         RCC_APB1Periph_I2C1 , ENABLE); /* for event timer */
        /* Configure the I2C clock source. The clock is derived from the HSI */
         RCC_I2CCLKConfig(RCC_I2C1CLK_HSI);

I have initialized the i2c bus like this:
   
    /* I2C configuration */
    I2C_InitTypeDef  I2C_InitStructure;
    I2C_InitStructure.I2C_Mode = I2C_Mode_I2C; 
    //I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
    I2C_InitStructure.I2C_AnalogFilter = I2C_AnalogFilter_Enable;
    I2C_InitStructure.I2C_DigitalFilter = 0x00;
    I2C_InitStructure.I2C_OwnAddress1 = 0x00;
    I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
    I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
    I2C_InitStructure.I2C_Timing = 0x1045061D; //I2C_TIMING;

    /* Apply I2C configuration after enabling it */
    I2C_Init(I2C1, &I2C_InitStructure);

    /* I2C Peripheral Enable */
    I2C_Cmd(I2C1, ENABLE);


Can anyone say what i'am doing wrong?
Thanks in advance,

Evert

Outcomes