cancel
Showing results for 
Search instead for 
Did you mean: 

How to calculate the I2C Timing Register value.

HI Team,

We are using the STM32WB controller for our project, in that we are using the I2C1 for to communicate with Eeprom Module.

Can anyone explain how to configure/Calculate the Exact Timing Register value. If we have any sample calculator for different I2C Speeds along with other register settings it is very helpful to us.

Currently My Register value:  hi2c1.hi2c1.Init. Timing = 0x00000E14, for which I2C speed it is calculated we are not understanding.

Regards,

Srinivas.V

17 REPLIES 17

Why would you just not use CubeMX to give you the setup code? You just type in the I2C speed that you want and it gives you the timing value.

Is learning the minutiae of poking timing registers the important bit (is this to pass some course) or is getting your device running the important thing?

Either way, read the I1C section of the reference manual.

Well it does cause a lot of people not knowing how anything actually works.

Perhaps one could take the Reference Manual, and unpack the register, and see how it divides the APB clock, and modulates the waveform.

If you're dealing with a lot of I2C peripherals, assorted STM32, and perhaps want to do some adaptive clock-gearing, being able to change it on the fly becomes more important.

This gets to be more important if people just randomly cut-n-paste things between projects or families of parts, as they are context sensitive, and often dependent on them even being commented correctly.

ST should really provide algorithms to pack and unpack these "constants" so the process is less opaque.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Piranha
Chief II

Proper calculation of the I2C timings is not just a single formula, but is an algorithm. If the HAL developers would be competent, they would implement this algorithm in the HAL initialization/configuration functions. After all HAL is meant to be a high level Hardware Abstraction Layer!

Hi Piranha,

Thanks for your reply.

Can you just explain how the value is calculated in example project, "hi2c1.hi2c1.Init. Timing 0x00000E14". we are trying to recalculate the same but not able to understand and same value is not getting with any of the settings which are in STMCubeMx Tool.

Could you please explain and corelate the example project value with STMCubeMx Tool, how it is generated, based on that we will generate the values for our project with Different I2C speeds.

We have downloaded the one excel exe which is for Timing Regester value generation, with that one also we are not able to corelate the Example project Register value.

Example project Path:

ST\STM32CubeWB-master\Projects\P-NUCLEO-WB55.Nucleo\Examples\I2C\I2C_TwoBoards_ComDMA

Excel sheet Name:

I2C_Timing_Configuration_V1.0.1

Regards,

Srinivas

Foued_KH
ST Employee

Hello @User16669512935851271792​,

I suggest you look to the Reference manual (RM0478) in Sections for more details:

  • I2C timings
  • 26.4.10 I2C_TIMINGR register configuration examples
  • 26.7.5 Timing register (I2C_TIMINGR)
  • 26.7.6 Timeout register (I2C_TIMEOUTR)

You find formulas to understand as a reference.

Multiprotocol wireless 32-bit MCU Arm<Sup>®</Sup>-based Cortex<Sup>®</Sup>-M4 with FPU, Bluetooth<Sup>®</Sup> 5.3 radio solution - Reference manual (st.com)

Foued

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.

Hi Khalsi,

Thanks for your reply.

I already overlooked into this document and crosschecked the registers, but still i am unable to simulate the TIMING REGISTER Value.

We have referred the Example code and they are using the value hi2c1.hi2c1.Init. Timing = 0x00000E14, we also reusing the same example code and only change is we need to run in Higher speeds like 400Khz and 1 Mz. For this we need to update the Timing Reg value, and rest of the settings are same. For that only we are asking how this value is generated and what are the values they have used for Rise and Fall Time values. If we know these values, we will generate the reg Value for different speeds.

Just explain the Example project Timing Reg value, that is sufficient for us.

Regards,

Srinivas.V

Foued_KH
ST Employee

Hello,

For the Timing register value : 0x00000E14, the Rise Time = 0 ns and the Fall time = 0 ns too,

For example : for Fast mode (400KHz) :

0693W00000WKZDSQA5.pngthis timing register value is generated automatically by the STM32CubeMX.

Foued

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.

Thanks for your reply.

In your image The Timing Reg value is showing 0x00004, But the value is example project is 0x00000E14.

Please mention the I2C Clock source Frequency, Analog Filter Delay, Coefficient of Digital Filter and Rise and Fall times.

we are using the excel sheet for generating the Timing Register value. Attached the same in reply.

Regards,

Srinivas.V

Foued_KH
ST Employee

The timing register value is 0x00000004 generated automatically by the STM32CubeMX for :

  • I2C Clock Source Frequency : 4MHz

0693W00000WKZQ7QAP.png

  • I2C Speed Frequency : 400 KHz
  • Rise Time : 0 ns
  • Fall Time : 0 ns

Foued

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.