cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F0 I2C timing register problem with CubeMX

Lukasz Nowak
Associate III
Posted on July 31, 2016 at 17:02

Hi,

I need to run I2C over a long cable (several meters). I know it is not a greatest thing to do, but I have no other option, as a 3rd party device only exposes an I2C interface.

In order to minimize interference I am going to run I2C bus at low speeds, e.g. 10 KHz - higher speed is not needed.

I have a problem with STM32 CubeMX tool, which calculates I2C timing register. At anything lower than 100 KHz, the values appear completely wrong.

I am using CubeMX 4.16 for STM32F042.

When I select 10 KHz, 300ns rise and fall time, the tool calculates: 0x10208EFB. I2C Clock is 8 MHz (from HSI).

This does result in more-less 10 KHz clock, but the low period (SCLL=0xFB) is much longer than the high perios (SCLH=0x8E). There seems to be no obvious justification for that difference.

But things get much worse - when selecting for instance 15 KHz clock, CubeMX calculatates timing register to 0x10200FF5. This maxes the clock cycle extremely asymetric: 0x0F high and 0xF5 low.

When I manually set the timing register to have the same low and high value (e.g. 0x82 for 15 KHz), I get a ''normal'' symmetric clock. Problem with that is CubeMX will overwrite it every time I regenerate the code.

Is there a reason why the I2C clock is made so asymetric? Or is that a bug in CubeMX?

Thanks for help with this.
2 REPLIES 2
Nesrine M_O
Lead II
Posted on August 02, 2016 at 11:42

Hi nowak.lukasz,

Thank you for your feedback. The issue has been reported internally.

-Syrine-

Jeanne Joly
Senior III
Posted on January 12, 2018 at 16:11

Hi,

Sorry for the late delay. 

I can advise you to read this AN (

http://www.st.com/content/ccc/resource/technical/document/application_note/de/14/eb/51/75/e3/49/f8/DM00074956.pdf/files/DM00074956.pdf/jcr:content/translations/en.DM00074956.pdf

). it will help you with the I2C timing configuration tool if you still have request on that tool.

BR.

Jeanne