2010-11-09 01:21 AM
I2C_CCR
2011-05-17 05:14 AM
Hi ANN,
I think that there is a typo FREQR should be replaced by FREQ[5:0] If FREQ[5:0] = 08 (IEC peripheral is clocked by 8MHz => 1/8MHz = 0.125µs => 125ns ), TPCLK1 = 125 ns so CCR must be programmed with 0x28 (0x28 <=> 40d x 125 ns = 5000 ns.)'' Hope this helps. Herzlich, MCU Lüfter2011-05-17 05:14 AM
Can somebody explain how to calculate the value for CCR bits in the I2C_CCR register?
What is given in the reference manual is not clear for me. Try examining the algorithm expressed in the firmware library source.
2011-05-17 05:14 AM
Hi again,
After spending much time to understand I2C spec. I thinkly that I understand it now. 0x28 <=> 40d x 125 ns = 5000 ns = 5 µs = 1/ (2 * 100 KHz). I have understand that if your APB is clocked by 8MHz at you want to get your I2C SCL at 100KHz. You have to do the following computatios: CCR = Thigh/TPCLK1 TPCLK1 is 8MHz and Thigh is I2C SCL freq * 2 so TPCLK1 is 1/8MHz = 125 ns Assuming that duty cycle is 50%: Thigh = 1/ (2 * 100KHz) = 5 µs = 5000 ns Consequently CCR = 5000 / 125 = 40 = 0x28 Hope that helps. MCU LÜfter2011-05-17 05:14 AM
Hello,
Thank you for your comprehensive reply. @lowpowermcu Would you mind sharing the I2C specification which you have referred? Thank you.2011-05-17 05:14 AM
Hello again,
I need another clarification something mentioned on the Reference manual. It states that ''the master waits for a read of the SR1 register followed by a write in the DR register with the Slave address'' I can write to DR register. But it result in acknowledge failure given by I2C1_SR1 = 0x0400. So is there anything to be done with ''master waits for a read of the SR1 register''? Some of the bits of SR1 are read only as well. Ask in another way how to clear bit0 of SR1? Thanks.2011-05-17 05:14 AM
Hi ANN,
I am using I2C spec available in the reference manual of STM32L1x. Herzlich, MCU Lüfter2011-05-17 05:14 AM
Hi ANN,
You get an acknowdgement failure means your slave isn't responding (perhaps a matter of address matching). AF: Acknodge Failure is cleared by writing 0 <=> I2C1->SR1 &= 0xFBFF; Hope that helps. Herzlich, MCU Lüfter