2010-03-17 12:02 AM
i2c busy flag
2011-05-17 04:43 AM
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.2011-05-17 04:43 AM
2011-05-17 04:43 AM
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,2011-05-17 04:43 AM
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.2011-05-17 04:43 AM
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.2011-05-17 04:43 AM
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);
2011-05-17 04:43 AM
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!