AnsweredAssumed Answered

STM32F4 I2C issues

Question asked by draz.raz on Sep 1, 2013
Latest reply on Sep 2, 2013 by draz.raz

I am trying to get the I2C bus to run with the MMA8452 accelerometer, but it just wont.
I can generate a start condition but nothing else. I'm watching the bus lines with a scope/logic analyzer and I can see that it doesn't generate anything after the start condition on SCL/SDA.
In debug mode I also noticed that after writing to the I2C data register the "AF - acknowledge failure" bit is set in SR1

The code:


    GPIO_InitTypeDef GPIO_InitStructure;

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOB, &GPIO_InitStructure);

    GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_I2C2);
    GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_I2C2);

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C2, ENABLE);

    I2C_InitTypeDef I2C_InitStruct;

    I2C_InitStruct.I2C_Ack = I2C_Ack_Enable;
    I2C_InitStruct.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
    I2C_InitStruct.I2C_ClockSpeed = 100000;
    I2C_InitStruct.I2C_DutyCycle = I2C_DutyCycle_2;
    I2C_InitStruct.I2C_Mode = I2C_Mode_I2C;
    I2C_InitStruct.I2C_OwnAddress1 = 0;

    I2C_Init(I2C2, &I2C_InitStruct);

    I2C_Cmd(I2C2, ENABLE);

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOA, &GPIO_InitStructure);

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOA, &GPIO_InitStructure);

    while(!GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0));

        GPIO_SetBits(GPIOA, GPIO_Pin_5); //Trigger for analyzer
        I2C_GenerateSTART(I2C2, ENABLE);

        I2C_Send7bitAddress(I2C2, 0x3A, I2C_Direction_Transmitter);


Any suggestions?