cancel
Showing results for 
Search instead for 
Did you mean: 

I2c2 start bit generation fail in STM32F103RB

avi239955_stm1
Associate II
Posted on May 29, 2011 at 12:41

Hi, all

I2c2 start bit generation fail - after timeout of 10 ms I2C_FLAG_SB = RESET = 0 but I2c1 work well read and write. anyone can help ?

More details:

10k poll up on each pin.

Clock Speed - 50000.

I2c2 start bit generation fail - after timeout of 10 ms I2C_FLAG_SB = RESET = 0 but I2c1 work well read and write.

More details:

10k poll up on each pin.

Clock Speed - 50000.

my code:

/*******************************************************************************

* Function Name  : ISC_Config

* Description    : Configure the ISC interface

* Input          : None

* Output         : None

* Return         : None

*******************************************************************************/

void I2C_Config(void)

{

    GPIO_InitTypeDef GPIO_InitStructure;

    I2C_InitTypeDef  I2C_InitStructure;

   /* Configure the SDA And the SCL line to alternate function Open Drain */

    I2C_DeInit(I2C1);

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_7;

    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

    GPIO_InitStructure.GPIO_Mode =GPIO_Mode_AF_OD;

    GPIO_Init(I2C_PORT, &GPIO_InitStructure);

    /* Configure the I2C peripheral */

    I2C_SoftwareResetCmd(I2C1,ENABLE);

    I2C_SoftwareResetCmd(I2C1,DISABLE);

    I2C_Cmd(I2C1, DISABLE);

    I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;

    I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;

    I2C_InitStructure.I2C_OwnAddress1 = I2C_SLAVEADDRESS;

    I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;

    I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;

    I2C_InitStructure.I2C_ClockSpeed = I2C_CLOCKSPEED;

    I2C_Init(I2C1, &I2C_InitStructure);

    I2C_Cmd(I2C1, ENABLE);

    I2C_AcknowledgeConfig (I2C1, DISABLE);

    I2C_DeInit(I2C2);

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10|GPIO_Pin_11;

    GPIO_Init(I2C_PORT, &GPIO_InitStructure);

    /* Configure the I2C peripheral */

    I2C_SoftwareResetCmd(I2C2,ENABLE);

    I2C_SoftwareResetCmd(I2C2,DISABLE);

    I2C_Cmd(I2C2, DISABLE);

    I2C_Init(I2C2, &I2C_InitStructure);

    I2C_Cmd(I2C2, ENABLE);

    I2C_AcknowledgeConfig (I2C2, DISABLE);

}

/*******************************************************************************

* Function Name  : GenerateStartCondition

* Description    : Generates the I2C start condition

* Input          : None

* Output         : None

* Return         : TRUE - Start condition generated successfuly. FALSE - otherwise

*******************************************************************************/

static BOOL GenerateStartCondition(void)

{

    BOOL bRes=FALSE;

    BOOL bStatusChangeTimeout=FALSE;

    I2C_GenerateSTART (I2C2, ENABLE);

    if (TriggerTimeoutCounter(I2C_STATUS_CHANGE_TIMEOUT_MSEC))

    {

        while ((I2C_GetFlagStatus (I2C2,I2C_FLAG_SB)== RESET) && !bStatusChangeTimeout)

        {

            if (IsTimeoutExpired())

                  bStatusChangeTimeout=TRUE;

        }

        if (!bStatusChangeTimeout)

            bRes=TRUE;

    }

    return bRes;

}

main()

{

        return GenerateStartCondition(); //it's return false

}

#i2c2-start-bit-generation-fail-in-stm32f103rb
8 REPLIES 8
mtaallah
Associate II
Posted on June 06, 2011 at 16:52

Hi,

Are you working with STM32 EVAL board, if yes which is this eval board ???

Posted on June 06, 2011 at 18:13

Where do you initialize the clocks?

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
avi239955_stm1
Associate II
Posted on June 12, 2011 at 12:05

avi239955_stm1
Associate II
Posted on June 12, 2011 at 12:39

Hi,

I attached an example that run on STM32F10X-128K-EVAL and illustrate the problem.

Tank you very much

________________

Attachments :

STM32F103_i2c2_bug.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I18c&d=%2Fa%2F0X0000000biu%2FlQAiIQ_THhOsgMfN74P2SVMyFm9C2giWai47nhiwNFg&asPdf=false
Posted on June 12, 2011 at 15:58

I attached an example that run on STM32F10X-128K-EVAL and illustrate the problem.

The I2C_Config() function in the attached project does not initialize the pins for the I2C2 port.

Generally I'd put all the pin configurations in one place, like GPIO_Config()

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
avi239955_stm1
Associate II
Posted on June 13, 2011 at 19:18

Is the STM32F10X-128K-EVAL (STM3210B-EVAL) even wired suitably to sustain a second I2C bus? Aren't the PB10 & PB11 pins connect to the smart card interface?

Follow Up : Initializing and testing two I2C buses on the VL Discovery, without additional hardware/pull-ups, I2C1 fails your test, I2C2 passes your test.

 

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
vikas_sinha75
Associate II
Posted on July 06, 2011 at 08:03

Try examples available at

http://www.st.com/stonline/stappl/resourceSelector/app?page=resourceSelector&doctype=FIRMWARE&ClassID=1734

also refer the errata sheet avaialble for I2C. its a good document available on internet and will give you an insight of problem and its solution I2C optimized example availble at

http://www.st.com/stonline/stappl/resourceSelector/app?page=resourceSelector&doctype=APPLICATION_NOTE&ClassID=1734