Skip to main content
fglau
Associate
February 4, 2019
Solved

How to configure I2C speed for STM32H7?

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.

This topic has been closed for replies.
Amel NASRI
Amel NASRIBest answer
ST Technical Moderator
February 5, 2019

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:

  • I2C clock source
  • the speed you need to set
  • rise and fall time
  • filter's configuration

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 "Best Answer" on the reply which solved your issue or answered your question.

7 replies

fglau
fglauAuthor
Associate
February 4, 2019

I forgot to mention - this is for the STM32H7 HAL I2C lib

Tesla DeLorean
Guru
February 4, 2019

You'd need to reintialize with the new values in the structure or disable the peripheral, change the clock parameters, and then enable again.​

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
fglau
fglauAuthor
Associate
February 4, 2019

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??

Amel NASRI
Amel NASRIBest answer
ST Technical Moderator
February 5, 2019

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:

  • I2C clock source
  • the speed you need to set
  • rise and fall time
  • filter's configuration

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 "Best Answer" on the reply which solved your issue or answered your question.
fglau
fglauAuthor
Associate
February 6, 2019

OK thanks Amel that worked just fine.