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üfter
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Üfter
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.
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