cancel
Showing results for 
Search instead for 
Did you mean: 

I2C_CCR

nanayakkaraan
Associate II
Posted on November 09, 2010 at 10:21

I2C_CCR

7 REPLIES 7
lowpowermcu
Associate II
Posted on May 17, 2011 at 14:14

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

Posted on May 17, 2011 at 14:14

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.

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

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

nanayakkaraan
Associate II
Posted on May 17, 2011 at 14:14

Hello,

Thank you for your comprehensive reply.

@lowpowermcu

Would you mind sharing the I2C specification which you have referred?

Thank you.

nanayakkaraan
Associate II
Posted on May 17, 2011 at 14:14

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.
lowpowermcu
Associate II
Posted on May 17, 2011 at 14:14

Hi ANN,

I am using I2C spec available in the reference manual of STM32L1x.

Herzlich,

MCU Lüfter

lowpowermcu
Associate II
Posted on May 17, 2011 at 14:14

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