UTILS I2C Overview

Introducing I2C Timing

group UTILS_I2C_Introduction

This module provides utility functions to simplify the configuration of I2C and SMBUS peripherals. It automates the calculation of timing and timeout values, ensuring compliance with protocol specifications and reliable communication.

Important: Calculate timing and timeout values using STM32CubeMX2. It isrecommendedto use STM32CubeMX2 for these calculations, as the C functions provided here are computationally intensive.

There are two approaches for I2C timing configuration:

  • Basic mode: Bus frequencies are predefined (100 kHz for normal mode, 400 kHz for fast mode, 1 MHz for fast mode plus). Provide the clock source frequency and desired I2C speed. The module calculates the timing value to meet the I2C standard.

  • Advanced mode: Allows full customization:

    • Frequency ranges:

      • 1 Hz to 100 kHz for normal mode

      • 101 kHz to 400 kHz for fast mode

      • 401 kHz to 1 MHz for fast mode plus

    • Parameters to fine-tune:

      • Rising time

      • Falling time

      • Digital noise filter coefficient

      • Analog filter mode

This distinction allows for quick setup using standard values (basic) or full customization (advanced) for specific requirements.

The computed values are used directly to fill hardware registers (I2C_TIMINGR for timings, I2C_TIMEOUTR for SMBUS timeouts) via the appropriate LL/HAL functions or direct register access.

Module and files

The following diagram illustrates the I2C Timing utility and its associated files.

Module and files diagram