cancel
Showing results for 
Search instead for 
Did you mean: 

What is I2C FREQR register used for?

SLasn.1
Associate II

Hi =)

I am using a STM8L151 but I am pretty sure this is the same for any STM8 with i2c.

The register I2C_FREQR is described in:

page 507 of the RM0031: https://www.st.com/resource/en/reference_manual/cd00218714-stm8l050j3-stm8l051f3-stm8l052c6-stm8l052r8-mcus-and-stm8l151l152-stm8l162-stm8al31-stm8al3l-lines-stmicroelectronics.pdf

0693W000006FQDFQA4.png 

From that description I understand it is an internal not used for the SCL output - so far so good.

But then on page 517, description of the I2C_CCRH register, it says:

0693W000006FQDUQA4.png 

i.e. it seems the FREQR defines the base frequency divided by CCR.

But then again in table 91 it seems the CPU clock fSYSCLK is the base frequency (i.e. independant of FREQR).

This is confusing o_O

Testing this it seems that FREQR has no impact on the SCL frequency, i.e. the info on table 91 is correct but the example in the description of the CCRH is not.

Hence my question: what is FREQR used for - is it just an internal clock? If so, what difference does it make to run it at 1MHz or 16MHz?

Thank you! :D

All the best

Simon

2 REPLIES 2
SLasn.1
Associate II

Ok actually I think I understand =)

It seems that FREQR is used as a base clock for the peripheral. In particular it is used to count the rise time (it will wait TRISER clock counts of FREQR). Though the SCL frequency is based on fSYSCLK and *not* FREQR.

Which also means - if I am not mistaken - that with:

  • fSYSCLK=16Mhz
  • FREQR=1Mhz
  • CCR=404 (or any non multiple of 16*2)

Which should give a frequency of 16000/(404*2)=19.8kHz, this will be rounded to 20kHz (i.e. CCR=400) because of the 1MHz clock, but would not if FREQR=16Mhz.

But anyways - it's I2C, the precision of the speed does not matter :D

I am still wondering though - is there any advantages at putting FREQR=1 instead of 16, for example power-wise or even EMI-wise?

SLasn.1
Associate II

Ok actually I think I understand even better now. FREQR does not *set* a base clock, the register is there so you can *tell* the peripheral know what its clock is! (as it is used to get the right I2C timings). So the answer is put in FREQR the speed of the peripheral input clock, which in a STM8L151 is the speed of the system clock.