Question
STM32F0 I2C timing register problem with CubeMX
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.