AnsweredAssumed Answered


Question asked by miller.mike.006 on Aug 3, 2016
Latest reply on Aug 7, 2016 by mich.lei
Hello everyone. I have searched the forums but could not figure this out.

I am using the STM32 F4 Discovery, AC6 (System Workbench), and the standard peripheral libraries.

On the Discovery Kit PA8 (pin 100) should be SCL,  PC9 (pin 99) should be SDA.

1.) The problem is that before I call  I2C3_Init() both SDA and SCL lines are high as expected.  But, after I call  I2C3_Init();  The clock line is held low and the SDA is high.  This doesn't look right so I wanted to see if there was anything obvious that I was doing wrong.

#include "stm32f4xx.h"
#include "stm32f4xx_gpio.h"

void I2C3_Init(){

    /* Enable Peripheral Clock for I2C3 */
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C3, ENABLE);

    /* Enable Peripheral Clock for SDA (PC9) SCL (PA8)  */
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOC  , ENABLE);

    GPIO_InitTypeDef GPIO_InitStructure_1;
    GPIO_InitStructure_1.GPIO_Pin = GPIO_Pin_8;
    GPIO_InitStructure_1.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStructure_1.GPIO_Speed = GPIO_Speed_2MHz;
    GPIO_InitStructure_1.GPIO_OType = GPIO_OType_OD;
    GPIO_InitStructure_1.GPIO_PuPd = GPIO_PuPd_NOPULL;
    GPIO_Init(GPIOA, &GPIO_InitStructure_1);

    GPIO_InitTypeDef GPIO_InitStructure_2;
    GPIO_InitStructure_2.GPIO_Pin = GPIO_Pin_9;
    GPIO_InitStructure_2.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStructure_2.GPIO_Speed = GPIO_Speed_2MHz;
    GPIO_InitStructure_2.GPIO_OType = GPIO_OType_OD;
    GPIO_InitStructure_2.GPIO_PuPd = GPIO_PuPd_NOPULL;
    GPIO_Init(GPIOC, &GPIO_InitStructure_2);

    /* Connect I2C1 pins to AF */
    GPIO_PinAFConfig(GPIOA, GPIO_Pin_8, GPIO_AF_I2C3);
    GPIO_PinAFConfig(GPIOC, GPIO_Pin_9, GPIO_AF_I2C3);

    /* configure I2C1 */
    I2C_InitTypeDef I2C_InitStruct;
    I2C_InitStruct.I2C_ClockSpeed = 100000;
    I2C_InitStruct.I2C_Mode = I2C_Mode_I2C;
    I2C_InitStruct.I2C_DutyCycle = I2C_DutyCycle_2;
    I2C_InitStruct.I2C_OwnAddress1 = 0x00;
    I2C_InitStruct.I2C_Ack = I2C_Ack_Disable;
    I2C_InitStruct.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
    I2C_Init(I2C1, &I2C_InitStruct);

    /* enable I2C3 */
    I2C_Cmd(I2C3, ENABLE);

int main(void)


    // Even at this point things don't look right.


    I2C_GenerateSTART(I2C3, ENABLE);

    I2C_Send7bitAddress(I2C3, 0x41, I2C_Direction_Transmitter);

    I2C_SendData(I2C3, 0xAA);