2019-02-03 10:17 PM
I am looking for a way to change the HAL I2C lib clock speed during runtime to either 100k or 400k or 1M.
I tried the following.....
hi2c1.Init.ClockSpeed = 100000;
However when compiling this the compiler do not recognize the parameter.
Solved! Go to Solution.
2019-02-05 3:28 AM
Hi @fglau ,
The I2C speed configuration is based on I2C_TIMINGR register content.
So, in the HAL structure, you need to program properly the parameter hi2c1.Init.Timing:
hi2c1.Init.Timing = I2C_TIMING;
I2C_TIMING value depends on:
The appropriate value may be calculated using STM32CubeMX interface: you will see that a suitable value for TIMINGR will be suggested depending on what you provide as inputs.
-Amel
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2019-02-03 10:18 PM
I forgot to mention - this is for the STM32H7 HAL I2C lib
2019-02-04 1:17 AM
You'd need to reintialize with the new values in the structure or disable the peripheral, change the clock parameters, and then enable again.
2019-02-04 1:53 AM
Yes changing the speed and then calling MX_I2C1_Init(); again make sense - however
I cannot find the register for the STM32H7xx in the HAL I2C lib to set the new SCL clock rate.
I tried hi2c1.Init.ClockSpeed = 100000; but the Atollic compiler did not recognize the HAL parameter
Which parameter should i change to update the speed??
2019-02-05 3:28 AM
Hi @fglau ,
The I2C speed configuration is based on I2C_TIMINGR register content.
So, in the HAL structure, you need to program properly the parameter hi2c1.Init.Timing:
hi2c1.Init.Timing = I2C_TIMING;
I2C_TIMING value depends on:
The appropriate value may be calculated using STM32CubeMX interface: you will see that a suitable value for TIMINGR will be suggested depending on what you provide as inputs.
-Amel
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2019-02-05 4:21 PM
OK thanks Amel that worked just fine.
2021-06-30 7:36 AM
Hello @Amel NASRI
where can I find the formula used by CubeMx to calculate I2C_TIMING?
Thanks.
2021-07-01 2:15 AM
Hello @RDums.1 ,
I2C_TIMING calculation in STM32CubeMX is based on formulas described in the RM. You need to refer to I2C timing register (I2C_TIMINGR).
For any follow-up question, please submit a new discussion as the current one is old.
-Amel
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
We’re moving the ST Community to a new platform to give you a better and more reliable community experience.