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 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.
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.
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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
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!