cancel
Showing results for 
Search instead for 
Did you mean: 

i2c busy flag

spa2
Associate II
Posted on March 17, 2010 at 08:02

i2c busy flag

16 REPLIES 16
Posted on May 17, 2011 at 13:43

You would need to make sure it was controlled by the GPIO, and not the I2C controller.

 GPIO_Mode_Out_OD

The purpose of banging the clock up and down is the clear a I2C slave on the bus.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
bogao3037
Associate II
Posted on May 17, 2011 at 13:43

I am using I2C for my temperature sensor and serial eeprom. I am using a timer to wait for every I2C event. It is working properly but I just want a recovery mechanism in case of something going wrong with I2C so that I don't have to reset the whole system.

bogao3037
Associate II
Posted on May 17, 2011 at 13:43

Hi,

It still doesn't work.

Here is my code, PB11 is the SDA and PB10 is SCL. The speed of I2C is set at 100K.

             I2C2->CR1.B.PE = DISABLE;

             GPIOB->CRH.B.MODE10 = MAX_OUT_SPEED_50MHz;     

             GPIOB->CRH.B.CNF10 =  GPIO_OUT_PUSH_PULL;           

             j=0;

             while(GPIOB->IDR.B.IDR11 == RESET)

             {

                   if(j++ > 9)

                 {

                    break;

                 }

                /*Reset the SCL Pin*/

                GPIOB->BRR.B.BR10= SET;

               

                Dly5us(1);

                /*Set the SCL Pin*/

               

                GPIOB->BSRR.B.BS10= SET;

                Dly5us(1);;

            }

            GPIOB->CRH.B.MODE10 = MAX_OUT_SPEED_50MHz;     

            GPIOB->CRH.B.CNF10 =  GPIO_AF_OPEN_DRAIN;           

            I2C2->CR1.B.PE = ENABLE; I checked with Logic Analyzer and found that after the last instruction(I2C2->CR1.B.PE = ENABLE;

), both the SCL and SDA are brounght to low. But what I am expecting is both SCL and SDA are high, which mean the bus is free and idle.

Thank you,

Posted on May 17, 2011 at 13:43

You could always try while(1) if you want to see it bang the clock up/down to confirm that portion is working.

Set the initial conditions of PB.10 with

                GPIOB->BSRR.B.BS10= SET;

                Dly5us(1);

otherwise it is undefined

You basically need to send enough clocks to clear an I2C slave that is stuck active.

I'm not sure you need to disable the I2C controller, but if you do perhaps you should consider the port settings of PB.11, set it as an input or whatever.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Singh.Harjit
Senior II
Posted on May 17, 2011 at 13:43

I was able to reproduce what you say below.

In fact what I noticed is that if I assign the pins to I2C before I enable the clock to the I2C module, then as soon as I enable the clock, the busy flag is set.

If I enable the clock to the I2C module and then assign the pins to I2C, I don't see the busy flag.

Clearly there is a dependency that needs to be documented.

jramirez2
Associate
Posted on May 17, 2011 at 13:43

Thanks that totally fixed my issue too here is my code for others to see and hopefully it will help some one

RCC_APB1PeriphClockCmd( RCC_APB1Periph_I2C1 ,ENABLE );

  /* I2C configuration ------------------------------------------------------*/

  I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;

  I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;

  I2C_InitStructure.I2C_OwnAddress1 = 0x30;

  I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;

  I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;

  I2C_InitStructure.I2C_ClockSpeed = 100000;

  I2C_Init(I2C1, &I2C_InitStructure);

  GPIO_I2C1Configuration();   // function that configures the PB6 and PB7 I2C lines

  I2C_Cmd(I2C1, ENABLE);

DiBosco
Senior
Posted on May 17, 2011 at 13:43

I worked out a better fix. (I'm encountering the exact same problems.)

Just rip the sodding I2C device out and use an SPI one. That's certainly what I'm doing when I upissue the board. I2C is horrible enough without ST's flaky hardware!