Skip to main content
pranathi1091
Associate III
November 29, 2012
Question

Busy flag Set in I2C

  • November 29, 2012
  • 19 replies
  • 2888 views
Posted on November 29, 2012 at 06:22

The original post was too long to process during our migration. Please click on the attachment to read the original post.
    This topic has been closed for replies.

    19 replies

    pranathi1091
    Associate III
    November 30, 2012
    Posted on November 30, 2012 at 06:35

    YEs i have changed the GPIO configurations

    If i probe he SCL line its always high

    I have no clue whats happening

    void RCC_Configuration(void).

    Here is my clock and GPIO code

    Pls let me know where am i wrong

    {

     RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);

      RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);

    }

    void I2C_Config(void)

    {

    GPIO_InitTypeDef GPIO_InitStruct;

    I2C_InitTypeDef  I2C_InitStruct;

    GPIO_InitStruct.GPIO_OType = GPIO_OType_OD;

    GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP;

    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;

    GPIO_InitStruct.GPIO_Pin =TEMP_I2c_SDA;

    GPIO_InitStruct.GPIO_Speed = GPIO_Speed_100MHz;           

    GPIO_Init(GPIOB, &GPIO_InitStruct);

    GPIO_PinAFConfig(GPIOB,GPIO_PinSource7,GPIO_AF_I2C1);

    GPIO_InitStruct.GPIO_OType = GPIO_OType_OD;

    GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP;

    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;

    GPIO_InitStruct.GPIO_Pin =TEMP_I2C_SCL;

    GPIO_InitStruct.GPIO_Speed = GPIO_Speed_100MHz;            

    GPIO_Init(GPIOB, &GPIO_InitStruct);

    GPIO_PinAFConfig(GPIOB,GPIO_PinSource6,GPIO_AF_I2C1);

    I2C_InitStruct.I2C_ClockSpeed=2000000;

    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_Enable;

    I2C_InitStruct.I2C_AcknowledgedAddress=I2C_AcknowledgedAddress_7bit;

    I2C_Init(I2C1,&I2C_InitStruct);

    I2C_Cmd(I2C1,ENABLE);

    }

    Tesla DeLorean
    Guru
    November 30, 2012
    Posted on November 30, 2012 at 11:50

    GPIO_InitStruct.GPIO_Pin =TEMP_I2c_SDA; // Check definition, you explicitly call out the AF pin

    ..

    GPIO_InitStruct.GPIO_Pin =TEMP_I2C_SCL;

    ..

    I2C_InitStruct.I2C_ClockSpeed=2000000; // 2 MHz ???

    Otherwise initialization looks reasonable.
    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    pranathi1091
    Associate III
    November 30, 2012
    Posted on November 30, 2012 at 11:59

    Thanks Clive.

    You mean to say i have to use GPIO_AF_I2C1. Currently I have defined SCL as GPIO_Pin_6 and GPIO_Pin_7 as SDA.i

    I have changed the frequency to 100kHz(standard mode)

    And these are the values i could see when i debug in I2C registers

    CR1->0x00000401(PE bit is set, ACK bit is set)

    CR2->0x0000001E(Freq is set with this value)

    OAR1->0x00004000(ADD is 0x00)

    OAR2->0x0000000(ADD2 is 0x00)

    DAR will be written with the data i send

    SR1 is 0

    SR2->0x00000002 Busy bit is set

    CCR->0x00000096

    TRISE->0x0000001F

    Tesla DeLorean
    Guru
    November 30, 2012
    Posted on November 30, 2012 at 12:30

    Try enabling before initializing.

    I2C_Cmd(I2C1,ENABLE);

    I2C_Init(I2C1,&I2C_InitStruct);

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    pranathi1091
    Associate III
    November 30, 2012
    Posted on November 30, 2012 at 12:49

    No change

    I get this Flag always busy  I2C_FLAG_BUSY

    pranathi1091
    Associate III
    November 30, 2012
    Posted on November 30, 2012 at 12:50

    No change

    I get this Flag always busy  I2C_FLAG_BUSY

    Nickname12657_O
    Associate III
    December 7, 2012
    Posted on December 07, 2012 at 11:32

    Hi,

    Try to reset the I2C after enabling its clock:

     /* Reset I2C1 IP */

      RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C1, ENABLE);

     /* Release reset signal of I2C1 IP */

      RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C1, DISABLE);

    Let me know the result.

    Cheers,

    STOne-32

     
    shivasankarg
    Visitor II
    November 25, 2015
    Posted on November 25, 2015 at 22:23

    Hi,

    I am facing the same problem. i'm betting an ACK failure after sending the slave address. So I am not sure what the problem is. I have attached a screenshot of the data being transmitted when viewed on a logic analyzer. Please help.

    0690X000006035hQAA.jpg

    Gutierrez.Guillermo
    Visitor II
    February 29, 2016
    Posted on February 29, 2016 at 20:50

    Hi, maybe it is a little old thread but i was having the same problems with the start getting stuck. What i did to fix was to enable the i2c clock AFTER i  call GPIO_PinAFConfig() because seems to be there is a glitch that makes the i2C module to stay with the BUSY bit on when you enable first the clocks.

    Hopefully it helps somebody struggling as i was