cancel
Showing results for 
Search instead for 
Did you mean: 

i2c Hard Reset Issue

officialkesh
Associate III
Posted on April 20, 2016 at 14:06

Hi,

In our environment , we have interfaced codec IC with I2C peripheral .

Once codec IC has been configured , both SDA and SCL @ High logic level .

Now if controller reset happened , SDA line remains low and inhibits the STM32 start condition .

To resolve this, I have written following code .

Now if I go for configuring I2C peripheral ,busy flag has been set just after RCC_APB1PeriphClockCmd() API .

Any reason behind this ?

void ResetI2cLines()

{

    uint8_t i;

    GPIO_InitTypeDef gpio;

    // Provid delay before I2c Reset line

    DelayMS(1);

    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);

    // Config SDA and SCL Pin

    bzero(&gpio, sizeof(gpio));

    gpio.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;

    gpio.GPIO_Mode = GPIO_Mode_OUT;

    gpio.GPIO_OType = GPIO_OType_PP;

    gpio.GPIO_PuPd = GPIO_PuPd_UP;

    gpio.GPIO_Speed = GPIO_Speed_50MHz;

    GPIO_Init(GPIOB, &gpio);

    GPIO_SetBits(GPIOB, GPIO_Pin_7);

    // 9th Pulse NACK signal

    for(i=0; i<10; i++)

    {

        // SCL line Clocking

        GPIO_SetBits(GPIOB, GPIO_Pin_6);

        DelayUS(5);

        GPIO_ResetBits(GPIOB, GPIO_Pin_6);

        DelayUS(5);

    }

    //Stop Signal - SDA Low to High while SCL High

    GPIO_ResetBits(GPIOB, GPIO_Pin_7);

    DelayUS(5);

    GPIO_SetBits(GPIOB, GPIO_Pin_6);

    DelayUS(2);

    GPIO_SetBits(GPIOB, GPIO_Pin_7);

    DelayUS(2);

}

#i2c #stm32f4 #discovery
1 REPLY 1
Walid FTITI_O
Senior II
Posted on April 22, 2016 at 20:56

Hi pinkesh,

Make sure that you have well configured the I2C and the SCL & SDA pins (ex: GPIO_Otype = OD)

You can refer to the I2C example at this path :

stm32f4_dsp_stdperiph_lib\STM32F4xx_DSP_StdPeriph_Lib_V1.6.1\Project\STM32F4xx_StdPeriph_Examples\I2C\I2C_TwoBoards

-Hannibal-