50. Inter-integrated circuit interface (I2C)

50.1 I2C introduction

The I2C peripheral handles the interface between the device and the serial I2C (inter-integrated circuit) bus. It provides multicontroller capability, and controls all I2C-bus-specific sequencing, protocol, arbitration and timing. It supports Standard-mode (Sm), Fast-mode (Fm) and Fast-mode Plus (Fm+).

The I2C peripheral is also SMBus (system management bus) and PMBus® (power management bus) compatible.

It can use DMA to reduce the CPU load.

50.2 I2C main features


a. To check the compliance of the GPIOs selected for SMBus with the specified logical levels, refer to the product datasheet.

For information on I2C instantiation, refer to Section 50.3: I2C implementation.

50.3 I2C implementation

This section provides an implementation overview with respect to the I2C instantiation.

Table 345. I2C implementation

I2C features(1)I2C1I2C2I2C3I2C4I2C5I2C6
7-bit addressing modeXXXXXX
10-bit addressing modeXXXXXX
Standard-mode (up to 100 kbit/s)XXXXXX
Fast-mode (up to 400 kbit/s)XXXXXX
Fast-mode Plus with 20 mA output drive I/Os (up to 1 Mbit/s)XXXXXX
Independent clockXXXXXX
Wake-up from Stop modeXXXXXX
SMBus/PMBusXXXXXX

1. X = supported.

50.4 I2C functional description

In addition to receiving and transmitting data, the peripheral converts them from serial to parallel format and vice versa. The interrupts are enabled or disabled by software. The peripheral is connected to the I2C-bus through a data pin (SDA) and a clock pin (SCL). It supports Standard-mode (up to 100 kHz), Fast-mode (up to 400 kHz), and Fast-mode Plus (up to 1 MHz) I2C-bus.

The peripheral can also be connected to an SMBus, through the data pin (SDA), the clock pin (SCL), and an optional SMBus alert pin (SMBA).

The independent clock function allows the I2C communication speed to be independent of the i2c_pclk frequency.

For I2C I/Os supporting 20 mA output current drive for Fast-mode Plus operation, the driving capability is enabled through control bits in the system configuration block(SYSCFG).

50.4.1 I2C block diagram

Figure 514. Block diagram

Block diagram of the I2C interface showing internal components and external pins.

The block diagram illustrates the internal architecture of the I2C interface. It is organized into several functional blocks:

Reference: MSv46198V4

Block diagram of the I2C interface showing internal components and external pins.

50.4.2 I2C pins and internal signals

Table 346. I2C input/output pins

Pin nameSignal typeDescription
I2C_SDABidirectionalI2C-bus data
I2C_SCLBidirectionalI2C-bus clock
I2C_SMBABidirectionalSMBus alert
Table 347. I2C internal input/output signals
Internal signal nameSignal typeDescription
i2c_ker_ckInputI2C kernel clock, also named I2CCLK in this document
i2c_pclkInputI2C APB clock
i2c_itOutputI2C interrupts, refer to Table 361 for the list of interrupt sources
i2c_rx_dmaOutputI2C receive data DMA request (I2C_RX)
i2c_tx_dmaOutputI2C transmit data DMA request (I2C_TX)

50.4.3 I2C clock requirements

The I2C kernel is clocked by i2c_ker_ck.

The i2c_ker_ck period \(t_{I2CCLK}\) must respect the following conditions:

\[t_{I2CCLK} < (t_{LOW} - t_{filters}) / 4\]

\[t_{I2CCLK} < t_{HIGH}\]

where \(t_{LOW}\) is the SCL low time, \(t_{HIGH}\) is the SCL high time, and \(t_{filters}\) is the sum of the analog and digital filter delays (when enabled).

The digital filter delay is DNF[3:0] × \(t_{I2CCLK}\).

The i2c_pclk clock period \(t_{PCLK}\) must respect the condition \(t_{PCLK} < 4/3 t_{SCL}\), where \(t_{SCL}\) is the SCL period.

Caution: When the I2C kernel is clocked by i2c_pclk, this clock must respect the conditions for \(t_{I2CCLK}\).

50.4.4 I2C mode selection

The peripheral can operate as:

By default, the peripheral operates in target mode. It automatically switches from target to controller mode upon generating START condition, and from controller to target mode upon arbitration loss or upon generating STOP condition. This allows the use of the I2C peripheral in a multicontroller I2C-bus environment.

Communication flow

In controller mode, the I2C peripheral initiates a data transfer and generates the clock signal. Serial data transfers always begin with a START condition and end with a STOP condition. Both START and STOP conditions are generated in controller mode by software.

In target mode, the peripheral recognizes its own 7-bit or 10-bit address, and the general call address. The general call address detection can be enabled or disabled by software. The reserved SMBus addresses can also be enabled by software.

Data and addresses are transferred as 8-bit bytes, MSB first. The address is contained in the first byte (7-bit addressing) or in the first two bytes (10-bit addressing) following the START condition. The address is always transmitted in controller mode.

The following figure shows the transmission of a single byte. The controller generates nine SCL pulses. The transmitter sends the eight data bits to the receiver with the SCL pulses 1 to 8. Then the receiver sends the acknowledge bit to the transmitter with the ninth SCL pulse.

Figure 515. I2C-bus protocol

Timing diagram for I2C-bus protocol showing SDA and SCL signals. The SDA line shows data bits (MSB to LSB) and an ACK bit. The SCL line shows nine pulses numbered 1 to 9. The diagram includes Start and Stop conditions indicated by double-headed arrows. The SDA line is high during the Start condition and low during the Stop condition. The SCL line is high during the data transmission and low during the ACK transmission.

MS19854V1

Timing diagram for I2C-bus protocol showing SDA and SCL signals. The SDA line shows data bits (MSB to LSB) and an ACK bit. The SCL line shows nine pulses numbered 1 to 9. The diagram includes Start and Stop conditions indicated by double-headed arrows. The SDA line is high during the Start condition and low during the Stop condition. The SCL line is high during the data transmission and low during the ACK transmission.

The acknowledge can be enabled or disabled by software. The own addresses of the I2C peripheral can be selected by software.

50.4.5 I2C initialization

Enabling and disabling the peripheral

Before enabling the I2C peripheral, configure and enable its clock through the RCC, and initialize its control registers.

The I2C peripheral can then be enabled by setting the PE bit of the I2C_CR1 register.

Disabling the I2C peripheral by clearing the PE bit resets the I2C peripheral. Refer to Section 50.4.6 for more details.

Noise filters

Before enabling the I2C peripheral by setting the PE bit of the I2C_CR1 register, the user must configure the analog and/or digital noise filters, as required.

The analog noise filter on the SDA and SCL inputs complies with the I2C-bus specification which requires, in Fast-mode and Fast-mode Plus, the suppression of spikes shorter than 50 ns. Enabled by default, it can be disabled by setting the ANFOFF bit.

The digital filter is controlled through the DNF[3:0] bitfield of the I2C_CR1 register. When it is enabled, the internal SCL and SDA signals only take the level of their corresponding I2C-bus line when remaining stable for more than DNF[3:0] periods of i2c_ker_ck. This allows suppressing spikes shorter than the filtering capacity period programmable from one to fifteen i2c_ker_ck periods.

The following table compares the two filters.

Table 348. Comparison of analog and digital filters
ItemAnalog filterDigital filter
Filtering capacity(1)≥ 50 nsOne to fifteen i2c_ker_ck periods
BenefitsAvailable in Stop mode
  • – Programmable filtering capacity
  • – Extra filtering capability versus I2C-bus specification requirements
  • – Stable filtering capacity
DrawbacksFiltering capacity variation with temperature, voltage, and silicon processWake-up from Stop mode on address match not supported when the digital filter is enabled

1. Maximum duration of spikes that the filter can suppress

Caution: The filter configuration cannot be changed when the I2C peripheral is enabled.

I2C timings

To ensure correct data hold and setup times, the corresponding timings must be configured through the PRESC[3:0], SCLDEL[3:0], and SDADEL[3:0] bitfields of the I2C_TIMINGR register.

The STM32CubeMX tool calculates and provides the I2C_TIMINGR content in the I2C configuration window.

Figure 516. Setup and hold timings

Figure 516: Setup and hold timings. The diagram shows two timing diagrams for I2C. The top diagram, 'DATA HOLD TIME', shows SCL falling edge internal detection, t_SYNC1, SDADEL (SCL stretched low by the I2C), SDA output delay, and t_HD;DAT. The bottom diagram, 'DATA SETUP TIME', shows SCLDEL (SCL stretched low by the I2C) and t_SU;STA. Text below the top diagram: 'Data hold time: in case of transmission, the data is sent on SDA output after the SDADEL delay, if it is already available in I2C_TXDR.' Text below the bottom diagram: 'Data setup time: in case of transmission, the SCLDEL counter starts when the data is sent on SDA output.' Reference: MSv40108V1.

DATA HOLD TIME

SCL falling edge internal detection

\(t_{SYNC1}\) SDADEL: SCL stretched low by the I2C

SDA output delay

\(t_{HD;DAT}\)

Data hold time: in case of transmission, the data is sent on SDA output after the SDADEL delay, if it is already available in I2C_TXDR.

DATA SETUP TIME

SCLDEL
SCL stretched low by the I2C

\(t_{SU;STA}\)

Data setup time: in case of transmission, the SCLDEL counter starts when the data is sent on SDA output.

MSv40108V1

Figure 516: Setup and hold timings. The diagram shows two timing diagrams for I2C. The top diagram, 'DATA HOLD TIME', shows SCL falling edge internal detection, t_SYNC1, SDADEL (SCL stretched low by the I2C), SDA output delay, and t_HD;DAT. The bottom diagram, 'DATA SETUP TIME', shows SCLDEL (SCL stretched low by the I2C) and t_SU;STA. Text below the top diagram: 'Data hold time: in case of transmission, the data is sent on SDA output after the SDADEL delay, if it is already available in I2C_TXDR.' Text below the bottom diagram: 'Data setup time: in case of transmission, the SCLDEL counter starts when the data is sent on SDA output.' Reference: MSv40108V1.

When the SCL falling edge is internally detected, the delay \(t_{SDADEL}\) (impacting the hold time \(t_{HD;DAT}\)) is inserted before sending SDA output:

\[t_{SDADEL} = SDADEL \times t_{PRESC} + t_{I2CCLK}, \text{ where } t_{PRESC} = (PRESC + 1) \times t_{I2CCLK}.\]

The total SDA output delay is:

\[t_{SYNC1} + \{[SDADEL \times (PRESC + 1) + 1] \times t_{I2CCLK}\}\]

The \(t_{SYNC1}\) duration depends upon:

To bridge the undefined region of the SCL falling edge, the user must set SDADEL[3:0] so as to fulfill the following condition:

\[\{t_{f(max)} + t_{HD;DAT(min)} - t_{AF(min)} - [(DNF + 3) \times t_{I2CCLK}]\} / \{(PRESC + 1) \times t_{I2CCLK}\} \leq SDADEL\]

\[SDADEL \leq \{t_{HD;DAT(max)} - t_{AF(max)} - [(DNF + 4) \times t_{I2CCLK}]\} / \{(PRESC + 1) \times t_{I2CCLK}\}\]

Note: \(t_{AF(min)}\) and \(t_{AF(max)}\) are only part of the condition when the analog filter is enabled. Refer to the device datasheet for \(t_{AF}\) values.

The \(t_{HD;DAT}\) time can at maximum be 3.45 μs for Standard-mode, 0.9 μs for Fast-mode, and 0.45 μs for Fast-mode Plus. It must be lower than the maximum of \(t_{VD;DAT}\) by a transition time. This maximum must only be met if the device does not stretch the LOW period (\(t_{LOW}\)) of the SCL signal. When it stretches SCL, the data must be valid by the set-up time before it releases the clock.

The SDA rising edge is usually the worst case. The previous condition then becomes:

\[SDADEL \leq \{t_{VD;DAT (max)} - t_r (max) - t_{AF (max)} - [(DNF + 4) \times t_{I2CCLK}]\} / \{(PRESC + 1) \times t_{I2CCLK}\}\]

Note: This condition can be violated when NOSTRETCH = 0, because the device stretches SCL low to guarantee the set-up time, according to the SCLDEL[3:0] value.

After \(t_{SDADEL}\), or after sending SDA output when the target had to stretch the clock because the data was not yet written in I2C_TXDR register, the SCL line is kept at low level during the setup time. This setup time is \(t_{SCLDEL} = (SCLDEL + 1) \times t_{PRESC}\), where \(t_{PRESC} = (PRESC + 1) \times t_{I2CCLK}\). \(t_{SCLDEL}\) impacts the setup time \(t_{SU;DAT}\).

To bridge the undefined region of the SDA transition (rising edge usually worst case), the user must program SCLDEL[3:0] so as to fulfill the following condition:

\[\{[t_r (max) + t_{SU;DAT (min)}] / [(PRESC + 1) \times t_{I2CCLK}]\} - 1 \leq SCLDEL\]

Refer to the following table for \(t_f\), \(t_r\), \(t_{HD;DAT}\), \(t_{VD;DAT}\), and \(t_{SU;DAT}\) standard values.

Use the SDA and SCL real transition time values measured in the application to widen the scope of allowed SDADEL[3:0] and SCLDEL[3:0] values. Use the maximum SDA and SCL transition time values defined in the standard to make the device work reliably regardless of the application.

Note: At every clock pulse, after SCL falling edge detection, I2C operating as controller or target stretches SCL low during at least \([(SDADEL + SCLDEL + 1) \times (PRESC + 1) + 1] \times t_{I2CCLK}\), in both transmission and reception modes. In transmission mode, if the data is not yet written in I2C_TXDR when SDA delay elapses, the I2C peripheral keeps stretching SCL low until the next data is written. Then new data MSB is sent on SDA output, and SCLDEL counter starts, continuing stretching SCL low to guarantee the data setup time.

When the NOSTRETCH bit is set in target mode, the SCL is not stretched. The SDADEL[3:0] must then be programmed so that it ensures a sufficient setup time.

Table 349. I2C-bus and SMBus specification data setup and hold times

SymbolParameterStandard-mode (Sm)Fast-mode (Fm)Fast-mode Plus (Fm+)SMBusUnit
MinMaxMinMaxMinMaxMinMax
\(t_{HD;DAT}\)Data hold time0-0-0-0.3-μs
\(t_{VD;DAT}\)Data valid time-3.45-0.9-0.45--
\(t_{SU;DAT}\)Data setup time250-100-50-250-ns
\(t_r\)Rise time of both SDA and SCL signals-1000-300-120-1000
\(t_f\)Fall time of both SDA and SCL signals-300-300-120-300

Additionally, in controller mode, the SCL clock high and low levels must be configured by programming the PRESC[3:0], SCLH[7:0], and SCLL[7:0] bitfields of the I2C_TIMINGR register.

When the SCL falling edge is internally detected, the I2C peripheral releasing the SCL output after the delay \(t_{SCLL} = (SCLL + 1) \times t_{PRESC}\), where \(t_{PRESC} = (PRESC + 1) \times t_{I2CCLK}\). The \(t_{SCLL}\) delay impacts the SCL low time \(t_{LOW}\).

When the SCL rising edge is internally detected, the I2C peripheral forces the SCL output to low level after the delay \(t_{SCLH} = (SCLH + 1) \times t_{PRESC}\), where \(t_{PRESC} = (PRESC + 1) \times t_{I2CCLK}\). The \(t_{SCLH}\) impacts the SCL high time \(t_{HIGH}\).

Refer to I2C controller initialization for more details.

Caution: Changing the timing configuration and the NOSTRETCH configuration is not allowed when the I2C peripheral is enabled. Like the timing settings, the target NOSTRETCH settings must also be done before enabling the peripheral. Refer to I2C target initialization for more details.

Figure 517. I2C initialization flow

Flowchart showing I2C initialization steps: Initial settings, Clear PE bit in I2C_CR1, Configure ANFOFF and DNF[3:0] in I2C_CR1, Configure PRESC[3:0], SDADEL[3:0], SCLDEL[3:0], SCLH[7:0], and SCLL[7:0] in I2C_TIMINGR, Configure NOSTRETCH in I2C_CR1, Set PE bit in I2C_CR1, End.
graph TD
    A([Initial settings]) --> B[Clear PE bit in I2C_CR1]
    B --> C[Configure ANFOFF and DNF[3:0] in I2C_CR1]
    C --> D[Configure PRESC[3:0], SDADEL[3:0], SCLDEL[3:0], SCLH[7:0], and SCLL[7:0] in I2C_TIMINGR]
    D --> E[Configure NOSTRETCH in I2C_CR1]
    E --> F[Set PE bit in I2C_CR1]
    F --> G([End])
  

MS19847V3

Flowchart showing I2C initialization steps: Initial settings, Clear PE bit in I2C_CR1, Configure ANFOFF and DNF[3:0] in I2C_CR1, Configure PRESC[3:0], SDADEL[3:0], SCLDEL[3:0], SCLH[7:0], and SCLL[7:0] in I2C_TIMINGR, Configure NOSTRETCH in I2C_CR1, Set PE bit in I2C_CR1, End.

50.4.6 I2C reset

The reset of the I2C peripheral is performed by clearing the PE bit of the I2C_CR1 register. It has the effect of releasing the SCL and SDA lines. Internal state machines are reset and the communication control bits and the status bits revert to their reset values. This reset does not impact the configuration registers.

The impacted register bits are:

  1. 1. I2C_CR2 register: START, STOP, PECBYTE, and NACK
  2. 2. I2C_ISR register: BUSY, TXE, TXIS, RXNE, ADDR, NACKF, TCR, TC, STOPF, BERR, ARLO, PECERR, TIMEOUT, ALERT, and OVR

PE must be kept low during at least three APB clock cycles to perform the I2C reset. To ensure this, perform the following software sequence:

  1. 1. Write PE = 0
  2. 2. Check PE = 0
  3. 3. Write PE = 1

50.4.7 I2C data transfer

The data transfer is managed through transmit and receive data registers and a shift register.

Reception

The SDA input fills the shift register. After the eighth SCL pulse (when the complete data byte is received), the shift register is copied into the I2C_RXDR register if it is empty (RXNE = 0). If RXNE = 1, which means that the previous received data byte has not yet been read, the SCL line is stretched low until I2C_RXDR is read. The stretch occurs between the eighth and the ninth SCL pulse (before the acknowledge pulse).

Figure 518. Data reception

Timing diagram for I2C data reception showing SCL, Shift register, RXNE, and I2C_RXDR signals. It illustrates the process of receiving data bytes, including SCL stretching and ACK pulses.

The diagram illustrates the I2C data reception process across four signals over time:

Arrows indicate the flow of data: 'data1' moves from the shift register to I2C_RXDR, and 'data2' moves from the shift register to I2C_RXDR. Labels 'rd data0' and 'rd data1' point to the moments when data is read from the I2C_RXDR register. A legend indicates that a blue line represents an 'SCL stretch'.

Timing diagram for I2C data reception showing SCL, Shift register, RXNE, and I2C_RXDR signals. It illustrates the process of receiving data bytes, including SCL stretching and ACK pulses.

MS19848V1

Transmission

If the I2C_TXDR register is not empty (TXE = 0), its content is copied into the shift register after the ninth SCL pulse (the acknowledge pulse). Then the shift register content is shifted out on the SDA line. If TXE = 1, which means that no data is written yet in I2C_TXDR, the SCL line is stretched low until I2C_TXDR is written. The stretch starts after the ninth SCL pulse.

Figure 519. Data transmission

Timing diagram for I2C data transmission showing SCL, Shift register, TXE, and I2C_TXDR signals.

The diagram illustrates the timing of data transmission in I2C. It shows four signals over time: SCL (clock), Shift register, TXE (transmit empty flag), and I2C_TXDR (transmit data register). The SCL signal shows a series of pulses, with two specific pulses circled and labeled 'ACK pulse'. The Shift register contains data segments labeled 'xx', 'data1', 'xx', 'data2', and 'xx'. The TXE signal is high when the I2C_TXDR register is empty and low when it contains data. Arrows labeled 'wr data1' and 'wr data2' indicate the writing of data into the I2C_TXDR register. The I2C_TXDR register contains data segments labeled 'data0', 'data1', and 'data2'. A legend indicates that a blue line represents an 'SCL stretch'.

Timing diagram for I2C data transmission showing SCL, Shift register, TXE, and I2C_TXDR signals.

MS19849V1

Hardware transfer management

The I2C features an embedded byte counter to manage byte transfer and to close the communication in various modes, such as:

In controller mode, the byte counter is always used. By default, it is disabled in target mode. It can be enabled by software, by setting the SBC (target byte control) bit of the I2C_CR1 register.

The number of bytes to transfer is programmed in the NBYTES[7:0] bitfield of the I2C_CR2 register. If this number is greater than 255, or if a receiver wants to control the acknowledge value of a received data byte, the reload mode must be selected, by setting the RELOAD bit of the I2C_CR2 register. In this mode, the TCR flag is set when the number of bytes programmed in NBYTES[7:0] is transferred (when the associated counter reaches zero), and an interrupt is generated if TCIE is set. SCL is stretched as long as the TCR flag is set. TCR is cleared by software when NBYTES[7:0] is written to a non-zero value.

When NBYTES[7:0] is reloaded with the last number of bytes to transfer, the RELOAD bit must be cleared.

When RELOAD = 0 in controller mode, the counter can be used in two modes:

Caution: The AUTOEND bit has no effect when the RELOAD bit is set.

Table 350. I2C configuration

FunctionSBC bitRELOAD bitAUTOEND bit
Controller Tx/Rx NBYTES + STOPX01
Controller Tx/Rx + NBYTES + RESTARTX00
Target Tx/Rx, all received bytes ACKed0XX
Target Rx with ACK control11X

50.4.8 I2C target mode

I2C target initialization

To work in target mode, the user must enable at least one target address. The I2C_OAR1 and I2C_OAR2 registers are available to program the target own addresses OA1 and OA2, respectively.

OA1 can be configured either in 7-bit (default) or in 10-bit addressing mode, by setting the OA1MODE bit of the I2C_OAR1 register.

OA1 is enabled by setting the OA1EN bit of the I2C_OAR1 register.

If an additional target addresses are required, the second target address OA2 can be configured. Up to seven OA2 LSBs can be masked, by configuring the OA2MSK[2:0] bitfield of the I2C_OAR2 register. Therefore, for OA2MSK[2:0] configured from 1 to 6, only OA2[7:2], OA2[7:3], OA2[7:4], OA2[7:5], OA2[7:6], or OA2[7] are compared with the received address. When OA2MSK[2:0] is other than 0, the address comparator for OA2 excludes the I2C reserved addresses (0000 XXX and 1111 XXX) and they are not acknowledged. If OA2MSK[2:0] = 7, all received 7-bit addresses are acknowledged (except reserved addresses). OA2 is always a 7-bit address.

When enabled through the specific bit, the reserved addresses can be acknowledged if they are programmed in the I2C_OAR1 or I2C_OAR2 register with OA2MSK[2:0] = 0.

OA2 is enabled by setting the OA2EN bit of the I2C_OAR2 register.

The general call address is enabled by setting the GCEN bit of the I2C_CR1 register.

When the I2C peripheral is selected by one of its enabled addresses, the ADDR interrupt status flag is set, and an interrupt is generated if the ADDRIE bit is set.

By default, the target uses its clock stretching capability, which means that it stretches the SCL signal at low level when required, to perform software actions. If the controller does not

support clock stretching, I2C must be configured with NOSTRETCH = 1 in the I2C_CR1 register.

After receiving an ADDR interrupt, if several addresses are enabled, the user must read the ADDCODE[6:0] bitfield of the I2C_ISR register to check which address matched. The DIR flag must also be checked to know the transfer direction.

Target with clock stretching

As long as the NOSTRETCH bit of the I2C_CR1 register is zero (default), the I2C peripheral operating as an I2C-bus target stretches the SCL signal in the following situations:

Target without clock stretching

As long as the NOSTRETCH bit of the I2C_CR1 register is set, the I2C peripheral operating as an I2C-bus target does not stretch the SCL signal.

The SCL clock is not stretched while the ADDR flag is set.

In transmission, the data must be written in the I2C_TXDR register before the first SCL pulse corresponding to its transfer occurs. If not, an underrun occurs, the OVR flag is set in the I2C_ISR register and an interrupt is generated if the ERRIE bit of the I2C_CR1 register is set. The OVR flag is also set when the first data transmission starts and the STOPF bit is still set (has not been cleared). Therefore, if the user clears the STOPF flag of the previous transfer only after writing the first data to be transmitted in the next transfer, it ensures that the OVR status is provided, even for the first data to be transmitted.

In reception, the data must be read from the I2C_RXDR register before the ninth SCL pulse (ACK pulse) of the next data byte occurs. If not, an overrun occurs, the OVR flag is set in the I2C_ISR register, and an interrupt is generated if the ERRIE bit of the I2C_CR1 register is set.

Target byte control mode

To allow byte ACK control in target reception mode, the target byte control mode must be enabled, by setting the SBC bit of the I2C_CR1 register. This is required to comply with SMBus standards.

The reload mode must be selected to allow byte ACK control in target reception mode (RELOAD = 1). To get control of each byte, NBYTES[7:0] must be initialized to 0x1 in the ADDR interrupt subroutine, and reloaded to 0x1 after each received byte. When the byte is received, the TCR bit is set, stretching the SCL signal low between the eighth and the ninth SCL pulse. The user can read the data from the I2C_RXDR register, and then decide to acknowledge it or not by configuring the ACK bit of the I2C_CR2 register. The SCL stretch is released by programming NBYTES to a non-zero value: the acknowledge or not-acknowledge is sent and the next byte can be received.

NBYTES[7:0] can be loaded with a value greater than 0x1. Receiving then continues until the corresponding number of bytes are received.

Note: The SBC bit must be configured when the I2C peripheral is disabled, when the target is not addressed, or when ADDR = 1.

The RELOAD bit value can be changed when ADDR = 1, or when TCR = 1.

Caution: The target byte control mode is not compatible with NOSTRETCH mode. Setting SBC when NOSTRETCH = 1 is not allowed.

Figure 520. Target initialization flow

Flowchart of Target initialization flow. The process starts with 'Target initialization' (oval), followed by 'Initial settings' (rectangle), 'Clear OA1EN and OA2EN in I2C_OAR1/I2C_OAR2' (rectangle), 'Configure OA1[9:0], OA1MODE, OA1EN, OA2[6:0], OA2MSK[2:0], OA2EN, and GCEN' (rectangle), 'Optional: Configure SBC in I2C_CR1(1)' (rectangle), 'Enable interrupts and/or DMA in I2C_CR1' (rectangle), and ends with 'End' (oval).
graph TD
    Start([Target initialization]) --> Step1[Initial settings]
    Step1 --> Step2[Clear OA1EN and OA2EN in I2C_OAR1/I2C_OAR2]
    Step2 --> Step3[Configure OA1[9:0], OA1MODE, OA1EN, OA2[6:0],
OA2MSK[2:0], OA2EN, and GCEN] Step3 --> Step4[Optional: Configure SBC in I2C_CR1(1)] Step4 --> Step5[Enable interrupts and/or DMA in I2C_CR1] Step5 --> End([End])

MSv19850V4

Flowchart of Target initialization flow. The process starts with 'Target initialization' (oval), followed by 'Initial settings' (rectangle), 'Clear OA1EN and OA2EN in I2C_OAR1/I2C_OAR2' (rectangle), 'Configure OA1[9:0], OA1MODE, OA1EN, OA2[6:0], OA2MSK[2:0], OA2EN, and GCEN' (rectangle), 'Optional: Configure SBC in I2C_CR1(1)' (rectangle), 'Enable interrupts and/or DMA in I2C_CR1' (rectangle), and ends with 'End' (oval).

1. SBC must be set to support SMBus features.

Target transmitter

A transmit interrupt status (TXIS) flag is generated when the I2C_TXDR register becomes empty. An interrupt is generated if the TXIE bit of the I2C_CR1 register is set.

The TXIS flag is cleared when the I2C_TXDR register is written with the next data byte to transmit.

When NACK is received, the NACKF flag is set in the I2C_ISR register and an interrupt is generated if the NACKIE bit of the I2C_CR1 register is set. The target automatically releases the SCL and SDA lines to let the controller perform a STOP or a RESTART condition. The TXIS bit is not set when a NACK is received.

When STOP is received and the STOPIE bit of the I2C_CR1 register is set, the STOPF flag of the I2C_ISR register is set and an interrupt is generated. In most applications, the SBC bit is usually programmed to 0. In this case, if TXE = 0 when the target address is received (ADDR = 1), the user can choose either to send the content of the I2C_TXDR register as the first data byte, or to flush the I2C_TXDR register, by setting the TXE bit in order to program a new data byte.

In target byte control mode (SBC = 1), the number of bytes to transmit must be programmed in NBYTES[7:0] in the address match interrupt subroutine (ADDR = 1). In this case, the number of TXIS events during the transfer corresponds to the value programmed in NBYTES[7:0].

Caution: When NOSTRETCH = 1, the SCL clock is not stretched while the ADDR flag is set, so the user cannot flush the I2C_TXDR register content in the ADDR subroutine to program the first data byte. The first data byte to send must be previously programmed in the I2C_TXDR register:

If STOPF is still set when the first data transmission starts, an underrun error is generated (the OVR flag is set).

If a TXIS event (transmit interrupt or transmit DMA request) is required, the user must set the TXIS bit in addition to the TXE bit, to generate the event.

Figure 521. Transfer sequence flow for I2C target transmitter, NOSTRETCH = 0

Flowchart for I2C target transmitter transfer sequence. It starts with 'Target transmission' (oval), followed by 'Target initialization' (rectangle). A decision diamond 'I2C_ISR.ADDR = 1?' loops back if 'No'. If 'Yes', it proceeds to a process box: 'Read ADDCODE and DIR in I2C_ISR; Optional: Set I2C_ISR.TXE = 1; Set I2C_ICR.ADDRCF'. Then a decision diamond 'I2C_ISR.TXIS = 1?' loops back to the process box if 'No'. If 'Yes', it proceeds to 'Write I2C_TXDR.TXDATA' (rectangle), which then loops back to the 'I2C_ISR.TXIS = 1?' decision. A vertical double-headed arrow on the right is labeled 'SCL stretched'.
graph TD; Start([Target transmission]) --> Init[Target initialization]; Init --> AddrCheck{I2C_ISR.ADDR = 1?}; AddrCheck -- No --> AddrCheck; AddrCheck -- Yes --> ReadRegs[Read ADDCODE and DIR in I2C_ISR
Optional: Set I2C_ISR.TXE = 1
Set I2C_ICR.ADDRCF]; ReadRegs --> TxIsCheck{I2C_ISR.TXIS = 1?}; TxIsCheck -- No --> TxIsCheck; TxIsCheck -- Yes --> WriteData[Write I2C_TXDR.TXDATA]; WriteData --> TxIsCheck;

MSv19851V3

Flowchart for I2C target transmitter transfer sequence. It starts with 'Target transmission' (oval), followed by 'Target initialization' (rectangle). A decision diamond 'I2C_ISR.ADDR = 1?' loops back if 'No'. If 'Yes', it proceeds to a process box: 'Read ADDCODE and DIR in I2C_ISR; Optional: Set I2C_ISR.TXE = 1; Set I2C_ICR.ADDRCF'. Then a decision diamond 'I2C_ISR.TXIS = 1?' loops back to the process box if 'No'. If 'Yes', it proceeds to 'Write I2C_TXDR.TXDATA' (rectangle), which then loops back to the 'I2C_ISR.TXIS = 1?' decision. A vertical double-headed arrow on the right is labeled 'SCL stretched'.

Figure 522. Transfer sequence flow for I2C target transmitter, NOSTRETCH = 1

Flowchart of I2C target transmitter transfer sequence
graph TD; Start([Target transmission]) --> Init[Target initialization]; Init --> Join(( )); Join --> TXIS{I2C_ISR.TXIS = 1?}; Join --> STOPF{I2C_ISR.STOPF = 1?}; TXIS -- Yes --> Write[Write I2C_TXDR.TXDATA]; Write --> TXIS; TXIS -- No --> Join; STOPF -- Yes --> Optional[Optional: Set I2C_ISR.TXE = 1 and I2C_ISR.TXIS=1]; Optional --> SetStopCF[Set I2C_ICR.STOPCF]; STOPF -- No --> Join;

The flowchart illustrates the transfer sequence for an I2C target transmitter when NOSTRETCH is set to 1. It begins with 'Target transmission' (oval) leading to 'Target initialization' (rectangle). From initialization, the flow splits into two parallel paths. The left path is a loop: it checks if 'I2C_ISR.TXIS = 1?'. If 'Yes', it performs 'Write I2C_TXDR.TXDATA' and loops back to the check. If 'No', it proceeds to the right path. The right path checks if 'I2C_ISR.STOPF = 1?'. If 'Yes', it optionally sets 'I2C_ISR.TXE = 1 and I2C_ISR.TXIS=1', followed by 'Set I2C_ICR.STOPCF'. If 'No', it loops back to the join point before the decision diamonds. The join point is an implicit connection point where the two paths merge before the flowchart ends.

MSv19852V3

Flowchart of I2C target transmitter transfer sequence
Figure 523. Transfer bus diagrams for I2C target transmitter (mandatory events only) Timing diagram for Example I2C target transmitter 3 bytes with 1st data flushed, NOSTRETCH=0: Shows S, Address, A, data1, A, data2, A, data3, NA, P sequences with TXE waveform, ADDR/TXIS event markers EV1, EV2, EV3, EV4, EV5, and SCL stretch indications. Timing diagram for Example I2C target transmitter 3 bytes without 1st data flush, NOSTRETCH=0: Shows S, Address, A, data1, A, data2, A, data3, NA, P sequences with TXE waveform, ADDR/TXIS event markers EV1, EV2, EV3, EV4, and SCL stretch indications. Timing diagram for Example I2C target transmitter 3 bytes, NOSTRETCH=1: Shows S, Address, A, data1, A, data2, A, data3, NA, P sequences with TXE waveform, TXIS and STOPF event markers EV1, EV2, EV3, EV4, EV5.

Example I2C target transmitter 3 bytes with 1st data flushed, NOSTRETCH=0:

legend:

EV1: ADDR ISR: check ADDCODE and DIR, set TXE, set ADDRCF
EV2: TXIS ISR: wr data1
EV3: TXIS ISR: wr data2
EV4: TXIS ISR: wr data3
EV5: TXIS ISR: wr data4 (not sent)

Example I2C target transmitter 3 bytes without 1st data flush, NOSTRETCH=0:

legend :

EV1: ADDR ISR: check ADDCODE and DIR, set ADDRCF
EV2: TXIS ISR: wr data2
EV3: TXIS ISR: wr data3
EV4: TXIS ISR: wr data4 (not sent)

Example I2C target transmitter 3 bytes, NOSTRETCH=1:

legend:

EV1: wr data1
EV2: TXIS ISR: wr data2
EV3: TXIS ISR: wr data3
EV4: TXIS ISR: wr data4 (not sent)
EV5: STOPF ISR: (optional: set TXE and TXIS), set STOPCF

MSv19853V3

Timing diagram for Example I2C target transmitter 3 bytes with 1st data flushed, NOSTRETCH=0: Shows S, Address, A, data1, A, data2, A, data3, NA, P sequences with TXE waveform, ADDR/TXIS event markers EV1, EV2, EV3, EV4, EV5, and SCL stretch indications. Timing diagram for Example I2C target transmitter 3 bytes without 1st data flush, NOSTRETCH=0: Shows S, Address, A, data1, A, data2, A, data3, NA, P sequences with TXE waveform, ADDR/TXIS event markers EV1, EV2, EV3, EV4, and SCL stretch indications. Timing diagram for Example I2C target transmitter 3 bytes, NOSTRETCH=1: Shows S, Address, A, data1, A, data2, A, data3, NA, P sequences with TXE waveform, TXIS and STOPF event markers EV1, EV2, EV3, EV4, EV5.

Target receiver

The RXNE bit of the I2C_ISR register is set when the I2C_RXDR is full, which generates an interrupt if the RXIE bit of the I2C_CR1 register is set. RXNE is cleared when I2C_RXDR is read.

When STOP condition is received and the STOPIE bit of the I2C_CR1 register is set, the STOPF flag in the I2C_ISR register is set and an interrupt is generated.

Figure 524. Transfer sequence flow for I2C target receiver, NOSTRETCH = 0

Flowchart showing the transfer sequence for I2C target receiver. It starts with 'Target reception' (oval), followed by 'Target initialization' (rectangle). A decision diamond 'I2C_ISR.ADDR = 1?' loops back if 'No'. If 'Yes', it proceeds to 'Read ADDCODE and DIR in I2C_ISR; Set I2C_ICR.ADDRCF' (rectangle). Then a decision diamond 'I2C_ISR.RXNE = 1?' loops back to the previous step if 'No'. If 'Yes', it proceeds to 'Write I2C_RXDR.RXDATA' (rectangle), which then loops back to the 'I2C_ISR.RXNE = 1?' decision. A vertical double-headed arrow on the right is labeled 'SCL stretched'.
graph TD; Start([Target reception]) --> Init[Target initialization]; Init --> AddrCheck{I2C_ISR.ADDR = 1?}; AddrCheck -- No --> AddrCheck; AddrCheck -- Yes --> ReadAddr[Read ADDCODE and DIR in I2C_ISR
Set I2C_ICR.ADDRCF]; ReadAddr --> RXNECheck{I2C_ISR.RXNE = 1?}; RXNECheck -- No --> RXNECheck; RXNECheck -- Yes --> WriteData[Write I2C_RXDR.RXDATA]; WriteData --> RXNECheck;

SCL stretched

MSv19855V3

Flowchart showing the transfer sequence for I2C target receiver. It starts with 'Target reception' (oval), followed by 'Target initialization' (rectangle). A decision diamond 'I2C_ISR.ADDR = 1?' loops back if 'No'. If 'Yes', it proceeds to 'Read ADDCODE and DIR in I2C_ISR; Set I2C_ICR.ADDRCF' (rectangle). Then a decision diamond 'I2C_ISR.RXNE = 1?' loops back to the previous step if 'No'. If 'Yes', it proceeds to 'Write I2C_RXDR.RXDATA' (rectangle), which then loops back to the 'I2C_ISR.RXNE = 1?' decision. A vertical double-headed arrow on the right is labeled 'SCL stretched'.

Figure 525. Transfer sequence flow for I2C target receiver, NOSTRETCH = 1

Figure 525. Transfer sequence flow for I2C target receiver, NOSTRETCH = 1
graph TD
    Start([Target reception]) --> Init[Target initialization]
    Init --> CheckRXNE{I2C_ISR.RXNE
=1?}
    Init --> CheckSTOPF{I2C_ISR.STOPF
=1?}
    CheckRXNE -- No --> CheckRXNE
    CheckRXNE -- Yes --> ReadData[Read I2C_RXDR.RXDATA]
    ReadData --> CheckRXNE
    CheckSTOPF -- No --> CheckSTOPF
    CheckSTOPF -- Yes --> SetSTOPCF[Set I2C_ICR.STOPCF]

MSv19856V3

Figure 525. Transfer sequence flow for I2C target receiver, NOSTRETCH = 1

Figure 526. Transfer bus diagrams for I2C target receiver
(mandatory events only)

Figure 526. Transfer bus diagrams for I2C target receiver (mandatory events only)

Example I2C target receiver 3 bytes, NOSTRETCH = 0:

Legend
□ Transmission
□ Reception
— SCL stretch

RXNE

EV1: ADDR ISR: check ADDCODE and DIR, set ADDRCF
EV2: RXNE ISR: rd data1
EV3: RXNE ISR: rd data2
EV4: RXNE ISR: rd data3

Example I2C target receiver 3 bytes, NOSTRETCH = 1:

Legend
□ Transmission
□ Reception
— SCL stretch

RXNE

EV1: RXNE ISR: rd data1
EV2: RXNE ISR: rd data2
EV3: RXNE ISR: rd data3

MSv19857V5

Figure 526. Transfer bus diagrams for I2C target receiver (mandatory events only)

50.4.9 I2C controller mode

I2C controller initialization

Before enabling the peripheral, the I2C controller clock must be configured, by setting the SCLH and SCLL bits in the I2C_TIMINGR register.

The STM32CubeMX tool calculates and provides the I2C_TIMINGR content in the I2C Configuration window.

A clock synchronization mechanism is implemented in order to support multicontroller environment and target clock stretching.

In order to allow clock synchronization:

I2C detects its own SCL low level after a \(t_{SYNC1}\) delay depending on the SCL falling edge, SCL input noise filters (analog and digital), and SCL synchronization to the I2CxCLK clock. I2C releases SCL to high level once the SCLL counter reaches the value programmed in the SCLL[7:0] bitfield of the I2C_TIMINGR register.

I2C detects its own SCL high level after a \(t_{SYNC2}\) delay depending on the SCL rising edge, SCL input noise filters (analog and digital), and SCL synchronization to the I2CxCLK clock. I2C ties SCL to low level once the SCLH counter reaches the value programmed in the SCLH[7:0] bitfield of the I2C_TIMINGR register.

Consequently the controller clock period is:

\[t_{SCL} = t_{SYNC1} + t_{SYNC2} + \{[(SCLH+1) + (SCLL+1)] \times (PRESC+1) \times t_{I2CCLK}\}\]

The duration of \(t_{SYNC1}\) depends upon:

The duration of \(t_{SYNC2}\) depends upon:

Figure 527. Controller clock generation

SCL controller clock generation and synchronization diagrams.

The diagram is divided into two sections: 'SCL controller clock generation' and 'SCL controller clock synchronization'.

SCL controller clock generation: This section shows a single SCL waveform. It starts with 'SCL released', followed by a rise time. A box indicates 'SCL high level detected SCLH counter starts'. The high period is labeled 'SCLH'. A synchronization interval 'tSYNC2' is shown between the rising edge and the start of the high period. After the high period, there is a fall time. A box indicates 'SCL low level detected SCLL counter starts'. The low period is labeled 'SCLL'. A synchronization interval 'tSYNC1' is shown between the falling edge and the start of the low period. A box 'SCL driven low' points to the falling edge.

SCL controller clock synchronization: This section shows a continuous SCL waveform with multiple cycles. It illustrates how the controller handles external events. In the first cycle, 'SCL high level detected SCLH counter starts' is shown at the rising edge, followed by 'SCLH'. Then, 'SCL driven low by another device' occurs during the low period, and 'SCL low level detected SCLL counter starts' is shown. In the second cycle, 'SCL released' occurs during the low period. In the third cycle, 'SCL high level detected SCLH counter starts' is shown at the rising edge, followed by 'SCLH'. Then, 'SCL driven low by another device' occurs during the low period, and 'SCL low level detected SCLL counter starts' is shown. The low periods are labeled 'SCLL'.

MSv19858V2

SCL controller clock generation and synchronization diagrams.

Caution: For compliance with the I2C-bus or SMBus specification, the controller clock must respect the timings in the following table.

Table 351. I2C-bus and SMBus specification clock timings
SymbolParameterStandard-mode (Sm)Fast-mode (Fm)Fast-mode Plus (Fm+)SMBusUnit
MinMaxMinMaxMinMaxMinMax
fSCLSCL clock frequency-100-400-1000-100kHz
tHD:STAHold time (repeated) START condition4.0-0.6-0.26-4.0-μs
tSU:STASet-up time for a repeated START condition4.7-0.6-0.26-4.7-
tSU:STOSet-up time for STOP condition4.0-0.6-0.26-4.0-
tBUFBus free time between a STOP and START condition4.7-1.3-0.5-4.7-
tLOWLow period of the SCL clock4.7-1.3-0.5-4.7-
tHIGHHigh period of the SCL clock4.0-0.6-0.26-4.050ns
trRise time of both SDA and SCL signals-1000-300-120-1000
tfFall time of both SDA and SCL signals-300-300-120-300

Note: The SCLL[7:0] bitfield also determines the tBUF and tSU:STA timings and SCLH[7:0] the tHD:STA and tSU:STO timings.

Refer to Section 50.4.10 for examples of I2C_TIMINGR settings versus the i2c_ker_ck frequency.

Controller communication initialization (address phase)

To initiate the communication with a target to address, set the following bitfields of the I2C_CR2 register:

Note: Changing these bitfields is not allowed as long as the START bit is set.

Before launching the communication, make sure that the I2C-bus is idle. This can be checked using the bus idle detection function or by verifying that the IDR bits of the GPIOs selected as SDA and SCL are set. Any low-level incident on the I2C-bus lines that coincides with the START condition asserted by the I2C peripheral may cause its deadlock if not filtered out by the input filters. If such incidents cannot be prevented, design the software so that it restores the normal operation of the I2C peripheral in case of a deadlock, by toggling the PE bit of the I2C_CR1 register.

To launch the communication, set the START bit of the I2C_CR2 register. The controller then automatically sends a START condition followed by the target address, either immediately if the BUSY flag is low, or \(t_{BUF}\) time after the BUSY flag transits from high to low state. The BUSY flag is set upon sending the START condition.

In case of an arbitration loss, the controller automatically switches back to target mode and can acknowledge its own address if it is addressed as a target.

Note: The START bit is reset by hardware when the target address is sent on the bus, whatever the received acknowledge value. The START bit is also reset by hardware upon arbitration loss.

In 10-bit addressing mode, the controller automatically keeps resending the target address in a loop until the first address byte (first seven address bits) is acknowledged by the target. Setting the ADDRCF bit makes I2C quit that loop.

If the I2C peripheral is addressed as a target (ADDR = 1) while the START bit is set, the I2C peripheral switches to target mode and the START bit is cleared when the ADDRCF bit is set.

Note: The same procedure is applied for a repeated START condition. In this case, BUSY = 1.

Figure 528. Controller initialization flow

Flowchart of Controller initialization flow
graph TD
    A([Controller initialization]) --> B[Initial settings]
    B --> C[Enable interrupts and/or DMA in I2C_CR1]
    C --> D([End])
  

MSv19859V3

Flowchart of Controller initialization flow

Initialization of a controller receiver addressing a 10-bit address target

If the target address is in 10-bit format, the user can choose to send the complete read sequence, by clearing the HEAD10R bit of the I2C_CR2 register. In this case, the controller automatically sends the following complete sequence after the START bit is set:

(RE)START + Target address 10-bit header Write + Target address second byte +
(RE)START + Target address 10-bit header Read.

Figure 529. 10-bit address read access with HEAD10R = 0

Timing diagram for 10-bit address read access with HEAD10R = 0

The diagram illustrates the sequence of events for a 10-bit address read access when HEAD10R = 0. It shows two phases: Write and Read.

Write Phase:

Read Phase:

MSv41066V2

Timing diagram for 10-bit address read access with HEAD10R = 0

If the controller addresses a 10-bit address target, transmits data to this target and then reads data from the same target, a controller transmission flow must be done first. Then a repeated START is set with the 10-bit target address configured with HEAD10R = 1. In this case, the controller sends this sequence:

RESTART + Target address 10-bit header Read.

Figure 530. 10-bit address read access with HEAD10R = 1

Diagram of 10-bit address read access sequence. It shows two phases: 'Write' and 'Read'. The 'Write' phase starts with a START condition (S), followed by the 1st 7 bits of the target address, a Read/Write bit (R/W bar), an ACK (A), the 2nd byte of the target address, another ACK (A), and a DATA byte. The 'Read' phase starts with a RESTART condition (Sr), followed by the 1st 7 bits of the target address, a Read/Write bit (R/W), an ACK (A), a DATA byte, and an ACK (A). The sequence ends with a DATA byte, a NACK (A bar), and a STOP condition (P).

The diagram illustrates the I2C communication sequence for a 10-bit address read access. It is divided into two main parts: 'Write' and 'Read'.

Write Phase: The sequence begins with a START condition (S). This is followed by the first 7 bits of the target address, a Read/Write bit (R/W bar), and an ACK (A). Then, the second byte of the target address is sent, followed by another ACK (A) and a DATA byte. The sequence ends with a DATA byte and an ACK (A).

Read Phase: The sequence begins with a RESTART condition (Sr). This is followed by the first 7 bits of the target address, a Read/Write bit (R/W), and an ACK (A). Then, a DATA byte is sent, followed by an ACK (A). The sequence ends with a DATA byte, a NACK (A bar), and a STOP condition (P).

MSv19823V2

Diagram of 10-bit address read access sequence. It shows two phases: 'Write' and 'Read'. The 'Write' phase starts with a START condition (S), followed by the 1st 7 bits of the target address, a Read/Write bit (R/W bar), an ACK (A), the 2nd byte of the target address, another ACK (A), and a DATA byte. The 'Read' phase starts with a RESTART condition (Sr), followed by the 1st 7 bits of the target address, a Read/Write bit (R/W), an ACK (A), a DATA byte, and an ACK (A). The sequence ends with a DATA byte, a NACK (A bar), and a STOP condition (P).

Controller transmitter

In the case of a write transfer, the TXIS flag is set after each byte transmission, after the ninth SCL pulse when an ACK is received.

A TXIS event generates an interrupt if the TXIE bit of the I2C_CR1 register is set. The flag is cleared when the I2C_TXDR register is written with the next data byte to transmit.

The number of TXIS events during the transfer corresponds to the value programmed in NBYTES[7:0]. If the total number of data bytes to transmit is greater than 255, the reload mode must be selected by setting the RELOAD bit in the I2C_CR2 register. In this case, when the NBYTES[7:0] number of data bytes is transferred, the TCR flag is set and the SCL line is stretched low until NBYTES[7:0] is written with a non-zero value.

When RELOAD = 0 and the number of data bytes defined in NBYTES[7:0] is transferred:

When a NACK is received, the TXIS flag is not set and a STOP condition is automatically sent. The NACKF flag of the I2C_ISR register is set. An interrupt is generated if the NACKIE bit is set.

Figure 531. Transfer sequence flow for I2C controller transmitter, N ≤ 255 bytes

Flowchart for I2C controller transmitter transfer sequence. It starts with 'Controller transmission' (oval), followed by 'Controller initialization' (rectangle). Then a process block: 'NBYTES = N', 'AUTOEND = 0 for RESTART; 1 for STOP', 'Configure target address', 'Set I2C_CR2.START'. The flow then enters a loop. A decision diamond 'I2C_ISR.NACKF = 1?' leads to 'End' if Yes, or loops back if No. Another decision diamond 'I2C_ISR.TXIS = 1?' leads to 'Write I2C_TXDR' if Yes, or loops back if No. After writing, a decision 'NBYTES transmitted?' loops back if No, or leads to 'I2C_ISR.TC = 1?' if Yes. 'I2C_ISR.TC = 1?' leads to 'End' if No, or to 'Set I2C_CR2.START with target address NBYTES ...' if Yes, which then loops back. The diagram is labeled MSv19860V3 in the bottom right corner.
graph TD; Start([Controller transmission]) --> Init[Controller initialization]; Init --> Config["NBYTES = N
AUTOEND = 0 for RESTART; 1 for STOP
Configure target address
Set I2C_CR2.START"]; Config --> NACKF{I2C_ISR.NACKF = 1?}; NACKF -- Yes --> End1([End]); NACKF -- No --> TXIS{I2C_ISR.TXIS = 1?}; TXIS -- Yes --> WriteTXDR[Write I2C_TXDR]; TXIS -- No --> Loop1(( )); WriteTXDR --> Transmitted{NBYTES transmitted?}; Transmitted -- No --> Loop1; Transmitted -- Yes --> TC{I2C_ISR.TC = 1?}; TC -- No --> End2([End]); TC -- Yes --> SetCR2["Set I2C_CR2.START with
target address NBYTES
..."]; SetCR2 --> Loop1; style Loop1 fill:none,stroke:none

MSv19860V3

Flowchart for I2C controller transmitter transfer sequence. It starts with 'Controller transmission' (oval), followed by 'Controller initialization' (rectangle). Then a process block: 'NBYTES = N', 'AUTOEND = 0 for RESTART; 1 for STOP', 'Configure target address', 'Set I2C_CR2.START'. The flow then enters a loop. A decision diamond 'I2C_ISR.NACKF = 1?' leads to 'End' if Yes, or loops back if No. Another decision diamond 'I2C_ISR.TXIS = 1?' leads to 'Write I2C_TXDR' if Yes, or loops back if No. After writing, a decision 'NBYTES transmitted?' loops back if No, or leads to 'I2C_ISR.TC = 1?' if Yes. 'I2C_ISR.TC = 1?' leads to 'End' if No, or to 'Set I2C_CR2.START with target address NBYTES ...' if Yes, which then loops back. The diagram is labeled MSv19860V3 in the bottom right corner.

Figure 532. Transfer sequence flow for I2C controller transmitter, N > 255 bytes

Flowchart for I2C controller transmitter transfer sequence for N > 255 bytes. It starts with Controller transmission, followed by Controller initialization. Then it sets NBYTES = 0xFF, N = N-255, RELOAD = 1, configures target address, and sets I2C_CR2.START. The flow then branches into two paths: one for NACKF and one for TXIS. The TXIS path involves writing to I2C_TXDR, checking if NBYTES are transmitted, and then checking TC and TCR flags. If TC is set, it sets I2C_CR2.START with target address and NBYTES. If TCR is set, it updates NBYTES and N based on whether N is less than 256. The process loops back until all bytes are transmitted or a NACK is received.
graph TD; Start([Controller transmission]) --> Init[Controller initialization]; Init --> Init2["NBYTES = 0xFF; N=N-255
RELOAD = 1
Configure target address
Set I2C_CR2.START"]; Init2 --> J1(( )); J1 --> NACKF{I2C_ISR.NACKF = 1?}; J1 --> TXIS{I2C_ISR.TXIS = 1?}; NACKF -- Yes --> End1([End]); NACKF -- No --> J1; TXIS -- No --> J1; TXIS -- Yes --> WriteTXDR[Write I2C_TXDR]; WriteTXDR --> Transmitted{NBYTES transmitted?}; Transmitted -- No --> J1; Transmitted -- Yes --> TC{I2C_ISR.TC = 1?}; TC -- Yes --> SetCR2["Set I2C_CR2.START
with target address
NBYTES ..."]; SetCR2 -.-> J1; TC -- No --> TCR{I2C_ISR.TCR = 1?}; TCR -- Yes --> UpdateVars["IF N< 256
NBYTES = N; N = 0; RELOAD = 0
AUTOEND = 0 for RESTART; 1 for STOP
ELSE
NBYTES = 0xFF; N = N-255
RELOAD = 1"]; UpdateVars --> J1; TCR -- No --> End2([End]);

MSv19861V4

Flowchart for I2C controller transmitter transfer sequence for N > 255 bytes. It starts with Controller transmission, followed by Controller initialization. Then it sets NBYTES = 0xFF, N = N-255, RELOAD = 1, configures target address, and sets I2C_CR2.START. The flow then branches into two paths: one for NACKF and one for TXIS. The TXIS path involves writing to I2C_TXDR, checking if NBYTES are transmitted, and then checking TC and TCR flags. If TC is set, it sets I2C_CR2.START with target address and NBYTES. If TCR is set, it updates NBYTES and N based on whether N is less than 256. The process loops back until all bytes are transmitted or a NACK is received.
Figure 533. Transfer bus diagrams for I2C controller transmitter (mandatory events only) Timing diagram for I2C controller transmitter 2 bytes, automatic end mode (STOP), showing start condition S, target address transmission, ACK bit reception, data1 write at EV1 via TXIS interrupt, data2 write at EV2 via TXIS interrupt, final ACK reception, and automatic STOP bit P generation along with TXE and NBYTES transitions. Timing diagram for I2C controller transmitter 2 bytes, software end mode (RESTART), showing transfer of address, data1 (EV1), data2 (EV2), followed by TC (transfer complete) event leading to EV3 ISR where target address and NBYTES are programmed and START/RESTART is set, continuing with ReS Address.

Example I2C controller transmitter 2 bytes, automatic end mode (STOP)

legend:
□ transmission
□ reception
— SCL stretch

INIT: program target address, program NBYTES = 2, AUTOEND = 1, set START
EV1: TXIS ISR: wr data1
EV2: TXIS ISR: wr data2

Example I2C controller transmitter 2 bytes, software end mode (RESTART)

legend:
□ transmission
□ reception
— SCL stretch

INIT: program target address, program NBYTES = 2, AUTOEND = 0, set START
EV1: TXIS ISR: wr data1
EV2: TXIS ISR: wr data2
EV3: TC ISR: program target address, program NBYTES = N, set START

MSv19862V3

Timing diagram for I2C controller transmitter 2 bytes, automatic end mode (STOP), showing start condition S, target address transmission, ACK bit reception, data1 write at EV1 via TXIS interrupt, data2 write at EV2 via TXIS interrupt, final ACK reception, and automatic STOP bit P generation along with TXE and NBYTES transitions. Timing diagram for I2C controller transmitter 2 bytes, software end mode (RESTART), showing transfer of address, data1 (EV1), data2 (EV2), followed by TC (transfer complete) event leading to EV3 ISR where target address and NBYTES are programmed and START/RESTART is set, continuing with ReS Address.

Controller receiver

In the case of a read transfer, the RXNE flag is set after each byte reception, after the eighth SCL pulse. An RXNE event generates an interrupt if the RXIE bit of the I2C_CR1 register is set. The flag is cleared when I2C_RXDR is read.

If the total number of data bytes to receive is greater than 255, select the reload mode, by setting the RELOAD bit of the I2C_CR2 register. In this case, when the NBYTES[7:0] number of data bytes is transferred, the TCR flag is set and the SCL line is stretched low until NBYTES[7:0] is written with a non-zero value.

When RELOAD = 0 and the number of data bytes defined in NBYTES[7:0] is transferred:

Figure 534. Transfer sequence flow for I2C controller receiver, N ≤ 255 bytes

Flowchart for I2C controller receiver transfer sequence. It starts with 'Controller reception' (oval), followed by 'Controller initialization' (rectangle). Then a process block: 'NBYTES = N', 'AUTOEND = 0 for RESTART; 1 for STOP', 'Configure target address', 'Set I2C_CR2.START'. A loop follows: decision 'I2C_ISR.RXNE = 1?'. If 'No', it loops back. If 'Yes', it goes to 'Read I2C_RXDR' (rectangle), then decision 'NBYTES received?'. If 'No', it loops back. If 'Yes', it goes to decision 'I2C_ISR.TC = 1?'. If 'No', it goes to 'End' (oval). If 'Yes', it goes to 'Set I2C_CR2.START with target address NBYTES ...' (rectangle) and loops back. The ID 'MSv19863V3' is at the bottom right.
graph TD; Start([Controller reception]) --> Init[Controller initialization]; Init --> Config["NBYTES = N
AUTOEND = 0 for RESTART; 1 for STOP
Configure target address
Set I2C_CR2.START"]; Config --> RXNE{I2C_ISR.RXNE = 1?}; RXNE -- No --> RXNE; RXNE -- Yes --> Read[Read I2C_RXDR]; Read --> NBYTESRec{NBYTES received?}; NBYTESRec -- No --> RXNE; NBYTESRec -- Yes --> TC{I2C_ISR.TC = 1?}; TC -- No --> End([End]); TC -- Yes --> SetCR2["Set I2C_CR2.START with
target address NBYTES
..."]; SetCR2 --> RXNE;

MSv19863V3

Flowchart for I2C controller receiver transfer sequence. It starts with 'Controller reception' (oval), followed by 'Controller initialization' (rectangle). Then a process block: 'NBYTES = N', 'AUTOEND = 0 for RESTART; 1 for STOP', 'Configure target address', 'Set I2C_CR2.START'. A loop follows: decision 'I2C_ISR.RXNE = 1?'. If 'No', it loops back. If 'Yes', it goes to 'Read I2C_RXDR' (rectangle), then decision 'NBYTES received?'. If 'No', it loops back. If 'Yes', it goes to decision 'I2C_ISR.TC = 1?'. If 'No', it goes to 'End' (oval). If 'Yes', it goes to 'Set I2C_CR2.START with target address NBYTES ...' (rectangle) and loops back. The ID 'MSv19863V3' is at the bottom right.

Figure 535. Transfer sequence flow for I2C controller receiver, N > 255 bytes

Flowchart for I2C controller receiver transfer sequence for N > 255 bytes. The process starts with Controller reception, followed by Controller initialization. Then, NBYTES is set to 0xFF, N is set to N-255, RELOAD is set to 1, the target address is configured, and I2C_CR2.START is set. The flow then enters a loop: it checks if I2C_ISR.RXNE = 1. If No, it loops back to the start of the loop. If Yes, it reads I2C_RXDR and checks if NBYTES has been received. If No, it loops back. If Yes, it checks if I2C_ISR.TC = 1. If Yes, it sets I2C_CR2.START with the target address NBYTES and loops back. If No, it checks if I2C_ISR.TCR = 1. If Yes, it updates NBYTES, N, and RELOAD based on whether N < 256. If N < 256, NBYTES = N, N = 0, RELOAD = 0, and AUTOEND is set to 0 for RESTART or 1 for STOP. If N >= 256, NBYTES = 0xFF, N = N - 255, and RELOAD = 1. If No, it loops back to the start of the loop. The process ends when I2C_ISR.TCR = 1 is No and the loop has completed.
graph TD; Start([Controller reception]) --> Init[Controller initialization]; Init --> Init2[NBYTES = 0xFF; N=N-255
RELOAD =1
Configure target address
Set I2C_CR2.START]; Init2 --> RXNE{I2C_ISR.RXNE = 1?}; RXNE -- No --> LoopBack1(( )); LoopBack1 --> RXNE; RXNE -- Yes --> ReadRXDR[Read I2C_RXDR]; ReadRXDR --> NBYTESRec{NBYTES received?}; NBYTESRec -- No --> LoopBack1; NBYTESRec -- Yes --> TC{I2C_ISR.TC = 1?}; TC -- Yes --> SetStart[Set I2C_CR2.START with target address NBYTES ...]; SetStart --> LoopBack1; TC -- No --> TCR{I2C_ISR.TCR = 1?}; TCR -- Yes --> Update[NBYTES = N; N=0; RELOAD=0
AUTOEND=0 for RESTART; 1 for STOP
ELSE
NBYTES = 0xFF; N=N-255
RELOAD=1]; Update --> LoopBack1; TCR -- No --> End([End]);
Flowchart for I2C controller receiver transfer sequence for N > 255 bytes. The process starts with Controller reception, followed by Controller initialization. Then, NBYTES is set to 0xFF, N is set to N-255, RELOAD is set to 1, the target address is configured, and I2C_CR2.START is set. The flow then enters a loop: it checks if I2C_ISR.RXNE = 1. If No, it loops back to the start of the loop. If Yes, it reads I2C_RXDR and checks if NBYTES has been received. If No, it loops back. If Yes, it checks if I2C_ISR.TC = 1. If Yes, it sets I2C_CR2.START with the target address NBYTES and loops back. If No, it checks if I2C_ISR.TCR = 1. If Yes, it updates NBYTES, N, and RELOAD based on whether N < 256. If N < 256, NBYTES = N, N = 0, RELOAD = 0, and AUTOEND is set to 0 for RESTART or 1 for STOP. If N >= 256, NBYTES = 0xFF, N = N - 255, and RELOAD = 1. If No, it loops back to the start of the loop. The process ends when I2C_ISR.TCR = 1 is No and the loop has completed.

MSv19864V3

Figure 536. Transfer bus diagrams for I2C controller receiver (mandatory events only)

Diagram of I2C controller receiver 2 bytes, automatic end mode (STOP). The bus sequence is: S (START), Address (transmission), A (ACK, reception), data1 (reception), A (ACK, reception), data2 (reception), NA (NOT ACK, reception), P (STOP, transmission). Events: INIT at S, EV1 at data1, EV2 at data2. RXNE events are at the end of data1 and data2. NBYTES register shows xx for address and 2 for data bytes. Diagram of I2C controller receiver 2 bytes, software end mode (RESTART). The bus sequence is: S (START), Address (transmission), A (ACK, reception), data1 (reception), A (ACK, reception), data2 (reception), NA (NOT ACK, reception), TC (SCL stretch), ReS (RESTART), Address (transmission). Events: INIT at S, EV1 at data1, EV2 at data2. RXNE events are at the end of data1 and data2. NBYTES register shows xx for address, 2 for data bytes, and N for the next address.

Example I2C controller receiver 2 bytes, automatic end mode (STOP)

legend:
  transmission
  reception
— SCL stretch

NBYTES: xx | 2

INIT: program target address, program NBYTES = 2, AUTOEND=1, set START
EV1: RXNE ISR: rd data1
EV2: RXNE ISR: rd data2


Example I2C controller receiver 2 bytes, software end mode (RESTART)

legend:
  transmission
  reception
— SCL stretch

NBYTES: xx | 2 | N

INIT: program target address, program NBYTES = 2, AUTOEND=0, set START
EV1: RXNE ISR: rd data1
EV2: RXNE ISR: read data2
EV3: TC ISR: program target address, program NBYTES = N, set START

MSv19865V2

Diagram of I2C controller receiver 2 bytes, automatic end mode (STOP). The bus sequence is: S (START), Address (transmission), A (ACK, reception), data1 (reception), A (ACK, reception), data2 (reception), NA (NOT ACK, reception), P (STOP, transmission). Events: INIT at S, EV1 at data1, EV2 at data2. RXNE events are at the end of data1 and data2. NBYTES register shows xx for address and 2 for data bytes. Diagram of I2C controller receiver 2 bytes, software end mode (RESTART). The bus sequence is: S (START), Address (transmission), A (ACK, reception), data1 (reception), A (ACK, reception), data2 (reception), NA (NOT ACK, reception), TC (SCL stretch), ReS (RESTART), Address (transmission). Events: INIT at S, EV1 at data1, EV2 at data2. RXNE events are at the end of data1 and data2. NBYTES register shows xx for address, 2 for data bytes, and N for the next address.

50.4.10 I2C_TIMINGR register configuration examples

The following tables provide examples of how to program the I2C_TIMINGR register to obtain timings compliant with the I2C-bus specification. To get more accurate configuration values, use the STM32CubeMX tool (I2C Configuration window).

Table 352. Timing settings for\(f_{I2CCLK}\) of 8 MHz
Standard-mode (Sm)Fast-mode (Fm)Fast-mode PlusFast-mode PlusFast-mode Plus
PRESC[3:0]0x10x10x00x0
SCLL[7:0]0xC70x130x90x6
tSCLL200 x 250 ns = 50 µs20 x 250 ns = 5.0 µs10 x 125 ns = 1250 ns7 x 125 ns = 875 ns
SCLH[7:0]0xC30xF0x30x3
tSCLH196 x 250 ns = 49 µs16 x 250 ns = 4.0 µs4 x 125 ns = 500 ns4 x 125 ns = 500 ns
tSCL(1)~100 µs (2)~10 µs (2)~2.5 µs(3)~2.0 µs (4)
SDADEL[3:0]0x20x20x10x0
tSDADEL2 x 250 ns = 500 ns2 x 250 ns = 500 ns1 x 125 ns = 125 ns0 ns
SCLDEL[3:0]0x40x40x30x1
tSCLDEL5 x 250 ns = 1250 ns5 x 250 ns = 1250 ns4 x 125 ns = 500 ns2 x 125 ns = 250 ns
2. tSYNC1 +tSYNC2 minimum value is 4 x tI2CCLK = 500 ns. Example with tSYNC1 +tSYNC2 = 1000 ns.
3. tSYNC1 + 4. tSYNC1 +tSYNC2 minimum value is 4 x tI2CCLK = 500 ns. Example with tSYNC1 +tSYNC2 = 750 ns.
Table 353. Timing settings for fI2CCLK of 16 MHz Standard-mode (Sm)Fast-mode (Fm)Fast-mode Plus (Fm+)
10 kHz100 kHz400 kHz1000 kHz
PRESC[3:0]0x30x30x10x0
SCLL[7:0]0xC70x130x90x4
tSCLL200 x 250 ns = 50 µs 20 x 250 ns = 5.0 µs10 x 125 ns = 1250 ns5 x 62.5 ns = 312.5 ns
SCLH[7:0]0xC30xF0x30x2
tSCLH196 x 250 ns = 49 µs 16 x 250 ns = 4.0 µs4 x 125 ns = 500 ns3 x 62.5 ns = 187.5 ns
tSCL(1)~100 µs (2)~10 µs (2)~2.5 µs(3)~1.0 µs (4)
SDADEL[3:0]0x20x20x20x0
tSDADEL2 x 250 ns = 500 ns2 x 250 ns = 500 ns2 x 125 ns = 250 ns0 ns
SCLDEL[3:0]0x40x40x30x2
tSCLDEL5 x 250 ns = 1250 ns 5 x 250 ns = 1250 ns4 x 125 ns = 500 ns3 x 62.5 ns = 187.5 ns
  1. 1. \(t_{SCL}\) is greater than \(t_{SCLL} + t_{SCLH}\) due to SCL internal detection delay. Values provided for \(t_{SCL}\) are examples only.
  2. 2. \(t_{SYNC1} + t_{SYNC2}\) minimum value is \(4 \times t_{I2CCLK} = 500\) ns. Example with \(t_{SYNC1} + t_{SYNC2} = 1000\) ns.
  3. 3. \(t_{SYNC1} + t_{SYNC2}\) minimum value is \(4 \times t_{I2CCLK} = 500\) ns. Example with \(t_{SYNC1} + t_{SYNC2} = 750\) ns.
  4. 4. \(t_{SYNC1} + t_{SYNC2}\) minimum value is \(4 \times t_{I2CCLK} = 500\) ns. Example with \(t_{SYNC1} + t_{SYNC2} = 655\) ns.
Table 353. Timing settings for\(f_{I2CCLK}\) of 16 MHz
  1. 1. \(t_{SCL}\) is greater than \(t_{SCLL} + t_{SCLH}\) due to SCL internal detection delay. Values provided for \(t_{SCL}\) are examples only.
  2. 2. \(t_{SYNC1} + t_{SYNC2}\) minimum value is \(4 \times t_{I2CCLK} = 250\) ns. Example with \(t_{SYNC1} + t_{SYNC2} = 1000\) ns.
  3. 3. \(t_{SYNC1} + t_{SYNC2}\) minimum value is \(4 \times t_{I2CCLK} = 250\) ns. Example with \(t_{SYNC1} + t_{SYNC2} = 750\) ns.
  4. 4. \(t_{SYNC1} + t_{SYNC2}\) minimum value is \(4 \times t_{I2CCLK} = 250\) ns. Example with \(t_{SYNC1} + t_{SYNC2} = 500\) ns.
Table 354. Timing settings for\(f_{I2CCLK}\) of 48 MHz
Standard-mode (Sm)Fast-mode (Fm)Fast-mode Plus (Fm+)Fast-mode Plus (Fm+)Fast-mode Plus (Fm+)
PRESC[3:0]0xB0xB0x50x5
SCLL[7:0]0xC70x130x90x3
tSCLL200 x 250 ns = 50 µs20 x 250 ns = 5.0 µs10 x 125 ns = 1250 ns4 x 125 ns = 500 ns
SCLH[7:0]0xC30xF0x30x1
tSCLH196 x 250 ns = 49 µs16 x 250 ns = 4.0 µs4 x 125 ns = 500 ns2 x 125 ns = 250 ns
tSCL(1)~100 µs (2)~10 µs (2)~2.5 µs (3)~875 ns (4)
SDADEL[3:0]0x20x20x30x0
tSDADEL2 x 250 ns = 500 ns2 x 250 ns = 500 ns3 x 125 ns = 375 ns0 ns
SCLDEL[3:0]0x40x40x30x1
tSCLDEL5 x 250 ns = 1250 ns5 x 250 ns = 1250 ns4 x 125 ns = 500 ns2 x 125 ns = 250 ns
• Target is a device that receives or responds to a command.
• Controller is a device that issues commands, generates clocks, and terminates the transfer.
• Host is a specialized controller that provides the main interface to the system CPU. A
host must be a controller-target and must support the SMBus one host is allowed in a system.host notifyprotocol. Only
or all of them to communicate. These are:Quick Command, Send Byte, Receive Byte , Write
Byte, Write Word , Read Byte Write-Block Read Process Call, Read Word , Process Call, Block Read, Block Write , and Block
  1. 1. \(t_{SCL}\) is greater than \(t_{SCLL} + t_{SCLH}\) due to the SCL internal detection delay. Values provided for \(t_{SCL}\) are only examples.
  2. 2. \(t_{SYNC1} + t_{SYNC2}\) minimum value is \(4 \times t_{I2CCLK} = 83.3\) ns. Example with \(t_{SYNC1} + t_{SYNC2} = 1000\) ns
  3. 3. \(t_{SYNC1} + t_{SYNC2}\) minimum value is \(4 \times t_{I2CCLK} = 83.3\) ns. Example with \(t_{SYNC1} + t_{SYNC2} = 750\) ns
  4. 4. \(t_{SYNC1} + t_{SYNC2}\) minimum value is \(4 \times t_{I2CCLK} = 83.3\) ns. Example with \(t_{SYNC1} + t_{SYNC2} = 250\) ns

50.4.11 SMBus specific features

Introduction

The system management bus (SMBus) is a two-wire interface through which various devices can communicate with each other and with the rest of the system. It is based on operation principles of the I2C-bus. The SMBus provides a control bus for system and power management related tasks.

The I2C peripheral is compatible with the SMBus specification (http://smbus.org).

The system management bus specification refers to three types of devices:

The I2C peripheral can be configured as a controller or a target device, and also as a host.

Bus protocols

There are eleven possible command protocols for any given device. The device can use any or all of them to communicate. These are: Quick Command, Send Byte, Receive Byte, Write Byte, Write Word, Read Byte, Read Word, Process Call, Block Read, Block Write, and Block Write-Block Read Process Call. The protocols must be implemented by the user software.

For more details on these protocols, refer to the SMBus specification (http://smbus.org). STM32CubeMX implements an SMBus stack thanks to X-CUBE-SMBUS, a downloadable software pack that allows basic SMBus configuration per I2C instance.

Address resolution protocol (ARP)

SMBus target address conflicts can be resolved by dynamically assigning a new unique address to each target device. To provide a mechanism to isolate each device for the purpose of address assignment, each device must implement a unique 128-bit device identifier (UDID). In the I2C peripheral, it is implemented by software.

The I2C peripheral supports the Address resolution protocol (ARP). The SMBus device default address (0b1100 001) is enabled by setting the SMBDEN bit of the I2C_CR1 register. The ARP commands must be implemented by the user software.

Arbitration is also performed in target mode for ARP support.

For more details on the SMBus address resolution protocol, refer to the SMBus specification (http://smbus.org).

Received command and data acknowledge control

An SMBus receiver must be able to NACK each received command or data. In order to allow the ACK control in target mode, the target byte control mode must be enabled, by setting the SBC bit of the I2C_CR1 register. Refer to Target byte control mode for more details.

Host notify protocol

To enable the host notify protocol, set the SMBHEN bit of the I2C_CR1 register. The I2C peripheral then acknowledges the SMBus host address (0b0001 000).

When this protocol is used, the device acts as a controller and the host as a target.

SMBus alert

The I2C peripheral supports the SMBALERT# optional signal through the SMBA pin. With the SMBALERT# signal, an SMBus target device can signal to the SMBus host that it wants to talk. The host processes the interrupt and simultaneously accesses all SMBALERT# devices through the alert response address (0b0001 100). Only the device/devices which pulled SMBALERT# low acknowledges/acknowledge the alert response address.

When the I2C peripheral is configured as an SMBus target device (SMBHEN = 0), the SMBA pin is pulled low by setting the ALERTEN bit of the I2C_CR1 register. The alert response address is enabled at the same time.

When the I2C peripheral is configured as an SMBus host (SMBHEN = 1), the ALERT flag of the I2C_ISR register is set when a falling edge is detected on the SMBA pin and ALERTEN = 1. An interrupt is generated if the ERRIE bit of the I2C_CR1 register is set. When ALERTEN = 0, the alert line is considered high even if the external SMBA pin is low.

Note: If the SMBus alert pin is not required, keep the ALERTEN bit cleared. The SMBA pin can then be used as a standard GPIO.

Packet error checking

A packet error checking mechanism introduced in the SMBus specification improves reliability and communication robustness. The packet error checking is implemented by

appending a packet error code (PEC) at the end of each message transfer. The PEC is calculated by using the C(x) = x⁸+x²+x+1 CRC-8 polynomial on all the message bytes (including addresses and read/write bits).

The I2C peripheral embeds a hardware PEC calculator and allows a not acknowledge to be sent automatically when the received byte does not match the hardware calculated PEC.

Timeouts

To comply with the SMBus timeout specifications, the I2C peripheral embeds hardware timers.

Table 355. SMBus timeout specifications

SymbolParameterLimitsUnit
MinMax
\(t_{\text{TIMEOUT}}\)Detect clock low timeout2535ms
\(t_{\text{LOW:SEXT}}^{(1)}\)Cumulative clock low extend time (target device)-25
\(t_{\text{LOW:MEXT}}^{(2)}\)Cumulative clock low extend time (controller device)-10
  1. 1. \(t_{\text{LOW:SEXT}}\) is the cumulative time a given target device is allowed to extend the clock cycles in one message from the initial START to the STOP. It is possible that another target device or the controller also extends the clock causing the combined clock low extend time to be greater than \(t_{\text{LOW:SEXT}}\). The value provided applies to a single target device connected to a full-target controller.
  2. 2. \(t_{\text{LOW:MEXT}}\) is the cumulative time a controller device is allowed to extend its clock cycles within each byte of a message as defined from START-to-ACK, ACK-to-ACK, or ACK-to-STOP. It is possible that a target device or another controller also extends the clock, causing the combined clock low time to be greater than \(t_{\text{LOW:MEXT}}\) on a given byte. The value provided applies to a single target device connected to a full-target controller.

Figure 537. Timeout intervals for \(t_{\text{LOW:SEXT}}\), \(t_{\text{LOW:MEXT}}\)

Timing diagram for SMBus showing SMBCLK and SMBDAT signals. The diagram illustrates the timeout intervals t_LOW:SEXT and t_LOW:MEXT. t_LOW:SEXT is the total time from Start to Stop. t_LOW:MEXT is the cumulative time a controller device is allowed to extend its clock cycles within each byte of a message, measured from the start of a byte to the end of the byte, including the ACK clock. The diagram shows three bytes of data transfer, each with an ACK clock (Clk_Ack) and a data byte (SMBDAT). The SMBCLK signal is shown as a square wave, and the SMBDAT signal is shown as a square wave. The diagram is labeled MS19866V1.

The diagram illustrates the timing relationships for SMBus transactions, specifically focusing on the timeout intervals \(t_{\text{LOW:SEXT}}\) and \(t_{\text{LOW:MEXT}}\). It shows two signals: SMBCLK (SMBus Clock) and SMBDAT (SMBus Data). The transaction begins with a Start condition and ends with a Stop condition. \(t_{\text{LOW:SEXT}}\) is the total time from the Start to the Stop. \(t_{\text{LOW:MEXT}}\) is the cumulative time a controller device is allowed to extend its clock cycles within each byte of a message, measured from the start of a byte to the end of the byte, including the ACK clock. The diagram shows three bytes of data transfer, each with an ACK clock (\(\text{Clk}_{\text{Ack}}\)) and a data byte (SMBDAT). The SMBCLK signal is shown as a square wave, and the SMBDAT signal is shown as a square wave. The diagram is labeled MS19866V1.

Timing diagram for SMBus showing SMBCLK and SMBDAT signals. The diagram illustrates the timeout intervals t_LOW:SEXT and t_LOW:MEXT. t_LOW:SEXT is the total time from Start to Stop. t_LOW:MEXT is the cumulative time a controller device is allowed to extend its clock cycles within each byte of a message, measured from the start of a byte to the end of the byte, including the ACK clock. The diagram shows three bytes of data transfer, each with an ACK clock (Clk_Ack) and a data byte (SMBDAT). The SMBCLK signal is shown as a square wave, and the SMBDAT signal is shown as a square wave. The diagram is labeled MS19866V1.

Bus idle detection

A controller can assume that the bus is free if it detects that the clock and data signals have been high for \(t_{IDLE} > t_{HIGH}(max)\) (refer to the table in Section 50.4.9).

This timing parameter covers the condition where a controller is dynamically added to the bus, and may not have detected a state transition on the SMBCLK or SMBDAT lines. In this case, the controller must wait long enough to ensure that a transfer is not currently in progress. The I2C peripheral supports a hardware bus idle detection.

50.4.12 SMBus initialization

In addition to the I2C initialization for the I2C-bus, the use of the peripheral for the SMBus communication requires some extra initialization steps.

Received command and data acknowledge control (target mode)

An SMBus receiver must be able to NACK each received command or data. To allow ACK control in target mode, the target byte control mode must be enabled, by setting the SBC bit of the I2C_CR1 register. Refer to Target byte control mode for more details.

Specific addresses (target mode)

The specific SMBus addresses must be enabled if required. Refer to Bus idle detection for more details.

The SMBus device default address (0b1100 001) is enabled by setting the SMBDEN bit of the I2C_CR1 register.

The SMBus host address (0b0001 000) is enabled by setting the SMBHEN bit of the I2C_CR1 register.

The alert response address (0b0001100) is enabled by setting the ALERTEN bit of the I2C_CR1 register.

Packet error checking

PEC calculation is enabled by setting the PECEN bit of the I2C_CR1 register. Then the PEC transfer is managed with the help of the hardware byte counter associated with the NBYTES[7:0] bitfield of the I2C_CR2 register. The PECEN bit must be configured before enabling the I2C.

The PEC transfer is managed with the hardware byte counter, so the SBC bit must be set when interfacing the SMBus in target mode. The PEC is transferred after transferring NBYTES[7:0] - 1 data bytes, if the PECBYTE bit is set and the RELOAD bit is cleared. If RELOAD is set, PECBYTE has no effect.

Caution: Changing the PECEN configuration is not allowed when the I2C peripheral is enabled.

Table 356. SMBus with PEC configuration

ModeSBC bitRELOAD bitAUTOEND bitPECBYTE bit
Controller Tx/Rx NBYTES + PEC+ STOPX011
Controller Tx/Rx NBYTES + PEC + ReSTARTX001
Target Tx/Rx with PEC10X1

Timeout detection

The timeout detection is enabled by setting the TIMOUTEN and TEXTEN bits of the I2C_TIMEOUTR register. The timers must be programmed in such a way that they detect a timeout before the maximum time given in the SMBus specification.

\(t_{TIMEOUT}\) check

To check the \(t_{TIMEOUT}\) parameter, load the 12-bit TIMEOUTA[11:0] bitfield with the timer reload value. Keep the TIDLE bit at 0 to detect the SCL low level timeout.

Then set the TIMOUTEN bit of the I2C_TIMEOUTR register, to enable the timer.

If SCL is tied low for longer than the \((TIMEOUTA + 1) \times 2048 \times t_{I2CCLK}\) period, the TIMEOUT flag of the I2C_ISR register is set.

Refer to Table 357.

Caution: Changing the TIMEOUTA[11:0] bitfield and the TIDLE bit values is not allowed when the TIMOUTEN bit is set.

\(t_{LOW:SEXT}\) and \(t_{LOW:MEXT}\) check

A 12-bit timer associated with the TIMEOUTB[11:0] bitfield allows checking \(t_{LOW:SEXT}\) for the I2C peripheral operating as a target, or \(t_{LOW:MEXT}\) when it operates as a controller. As the standard only specifies a maximum, the user can choose the same value for both. The timer is then enabled by setting the TEXTEN bit in the I2C_TIMEOUTR register.

If the SMBus peripheral performs a cumulative SCL stretch for longer than the \((TIMEOUTB + 1) \times 2048 \times t_{I2CCLK}\) period, and within the timeout interval described in Bus idle detection section, the TIMEOUT flag of the I2C_ISR register is set.

Refer to Table 358.

Caution: Changing the TIMEOUTB[11:0] bitfield value is not allowed when the TEXTEN bit is set.

Bus idle detection

To check the \(t_{IDLE}\) period, the TIMEOUTA[11:0] bitfield associated with 12-bit timer must be loaded with the timer reload value. Keep the TIDLE bit at 1 to detect both SCL and SDA high level timeout. Then set the TIMOUTEN bit of the I2C_TIMEOUTR register to enable the timer.

If both the SCL and SDA lines remain high for longer than the \((TIMEOUTA + 1) \times 4 \times t_{I2CCLK}\) period, the TIMEOUT flag of the I2C_ISR register is set.

Refer to Table 359.

Caution: Changing the TIMEOUTA[11:0] bitfield and the TIDLE bit values is not allowed when the TIMOUTEN bit is set.

50.4.13 SMBus I2C_TIMEOUTR register configuration examples

The following tables provide examples of settings to reach desired \(t_{TIMEOUT}\), \(t_{LOW:SEXT}\), \(t_{LOW:MEXT}\), and \(t_{IDLE}\) timings at different \(f_{I2CCLK}\) frequencies.

Table 357. TIMEOUTA[11:0] for maximum \(t_{TIMEOUT}\) of 25 ms

\(f_{I2CCLK}\)TIMEOUTA[11:0]TIDLETIMEOUTEN\(t_{TIMEOUT}\)
8 MHz0x6101\(98 \times 2048 \times 125 \text{ ns} = 25 \text{ ms}\)
16 MHz0xC301\(196 \times 2048 \times 62.5 \text{ ns} = 25 \text{ ms}\)
48 MHz0x24901\(586 \times 2048 \times 20.08 \text{ ns} = 25 \text{ ms}\)

Table 358. TIMEOUTB[11:0] for maximum \(t_{LOW:SEXT}\) and \(t_{LOW:MEXT}\) of 8 ms

\(f_{I2CCLK}\)TIMEOUTB[11:0]TEXTEN\(t_{LOW:SEXT}\)
\(t_{LOW:MEXT}\)
8 MHz0x1F1\(32 \times 2048 \times 125 \text{ ns} = 8 \text{ ms}\)
16 MHz0x3F1\(64 \times 2048 \times 62.5 \text{ ns} = 8 \text{ ms}\)
48 MHz0xBB1\(188 \times 2048 \times 20.08 \text{ ns} = 8 \text{ ms}\)

Table 359. TIMEOUTA[11:0] for maximum \(t_{IDLE}\) of 50 μs

\(f_{I2CCLK}\)TIMEOUTA[11:0]TIDLETIMEOUTEN\(t_{IDLE}\)
8 MHz0x6311\(100 \times 4 \times 125 \text{ ns} = 50 \mu\text{s}\)
16 MHz0xC711\(200 \times 4 \times 62.5 \text{ ns} = 50 \mu\text{s}\)
48 MHz0x25711\(600 \times 4 \times 20.08 \text{ ns} = 50 \mu\text{s}\)

50.4.14 SMBus target mode

In addition to I2C target transfer management (refer to Section 50.4.8: I2C target mode), this section provides extra software flowcharts to support SMBus.

SMBus target transmitter

When using the I2C peripheral in SMBus mode, set the SBC bit to enable the PEC transmission at the end of the programmed number of data bytes. When the PECBYTE bit is set, the number of bytes programmed in NBYTES[7:0] includes the PEC transmission. In that case, the total number of TXIS interrupts is NBYTES[7:0] - 1, and the content of the I2C_PECR register is automatically transmitted if the controller requests an extra byte after the transfer of the NBYTES[7:0] - 1 data bytes.

Caution: The PECBYTE bit has no effect when the RELOAD bit is set.

Figure 538. Transfer sequence flow for SMBus target transmitter N bytes + PEC

Flowchart for SMBus target transmission sequence. It starts with 'SMBus target transmission' leading to 'Target initialization'. A decision diamond 'I2C_ISR.ADDR = 1?' loops back to initialization if 'No'. If 'Yes', it proceeds to a box: 'Read ADDCODE and DIR in I2C_ISR', 'I2C_CR2.NBYTES = N + 1', 'PECBYTE = 1', 'Set I2C_ICR.ADDRCF'. A vertical double-headed arrow labeled 'SCL stretched' is next to this box. Then a decision diamond 'I2C_ISR.TXIS = 1?' loops back to the previous box if 'No'. If 'Yes', it proceeds to 'Write I2C_TXDR.TXDATA' and loops back to the TXIS decision.
graph TD
    Start([SMBus target transmission]) --> Init[Target initialization]
    Init --> AddrCheck{I2C_ISR.ADDR = 1?}
    AddrCheck -- No --> Init
    AddrCheck -- Yes --> Config["Read ADDCODE and DIR in I2C_ISR
I2C_CR2.NBYTES = N + 1
PECBYTE = 1
Set I2C_ICR.ADDRCF"] Config --> TXISCheck{I2C_ISR.TXIS = 1?} TXISCheck -- No --> TXISCheck TXISCheck -- Yes --> WriteData[Write I2C_TXDR.TXDATA] WriteData --> TXISCheck

MSv19867V3

Flowchart for SMBus target transmission sequence. It starts with 'SMBus target transmission' leading to 'Target initialization'. A decision diamond 'I2C_ISR.ADDR = 1?' loops back to initialization if 'No'. If 'Yes', it proceeds to a box: 'Read ADDCODE and DIR in I2C_ISR', 'I2C_CR2.NBYTES = N + 1', 'PECBYTE = 1', 'Set I2C_ICR.ADDRCF'. A vertical double-headed arrow labeled 'SCL stretched' is next to this box. Then a decision diamond 'I2C_ISR.TXIS = 1?' loops back to the previous box if 'No'. If 'Yes', it proceeds to 'Write I2C_TXDR.TXDATA' and loops back to the TXIS decision.

Figure 539. Transfer bus diagram for SMBus target transmitter (SBC = 1)

Timing diagram for SMBus target transmitter showing a sequence of bytes: S, Address, A, data1, A, data2, A, PEC, NA, P. It highlights events EV1 (ADDR ISR), EV2 (TXIS ISR), and EV3 (TXIS ISR). A legend indicates transmission (white box), reception (yellow box), and SCL stretch (blue line). A table below shows NBYTES = 3.

Example SMBus target transmitter 2 bytes + PEC

legend:
  transmission
  reception
— SCL stretch

NBYTES3

EV1: ADDR ISR: check ADDCODE, program NBYTES = 3, set PECBYTE, set ADDRCF
EV2: TXIS ISR: wr data1
EV3: TXIS ISR: wr data2

MSv19869V3

Timing diagram for SMBus target transmitter showing a sequence of bytes: S, Address, A, data1, A, data2, A, PEC, NA, P. It highlights events EV1 (ADDR ISR), EV2 (TXIS ISR), and EV3 (TXIS ISR). A legend indicates transmission (white box), reception (yellow box), and SCL stretch (blue line). A table below shows NBYTES = 3.

SMBus target receiver

When using the I2C peripheral in SMBus mode, set the SBC bit to enable the PEC checking at the end of the programmed number of data bytes. To allow the ACK control of each byte, the reload mode must be selected (RELOAD = 1). Refer to Target byte control mode for more details.

To check the PEC byte, the RELOAD bit must be cleared and the PECBYTE bit must be set. In this case, after the receipt of NBYTES[7:0] - 1 data bytes, the next received byte is compared with the internal I2C_PECR register content. A NACK is automatically generated if the comparison does not match, and an ACK is automatically generated if the comparison matches, whatever the ACK bit value. Once the PEC byte is received, it is copied into the I2C_RXDR register like any other data, and the RXNE flag is set.

Upon a PEC mismatch, the PECERR flag is set and an interrupt is generated if the ERRIE bit of the I2C_CR1 register is set.

If no ACK software control is required, the user can set the PECBYTE bit and, in the same write operation, load NBYTES[7:0] with the number of bytes to receive in a continuous flow. After the receipt of NBYTES[7:0] - 1 bytes, the next received byte is checked as being the PEC.

Caution: The PECBYTE bit has no effect when the RELOAD bit is set.

Figure 540. Transfer sequence flow for SMBus target receiver N bytes + PEC

Flowchart for SMBus target reception. It starts with 'SMBus target reception', followed by 'Target initialization'. A loop checks 'I2C_ISR.ADDR = 1?'. If yes, it reads ADDCODE and DIR, sets NBYTES=1, RELOAD=1, PECBYTE=1, and sets ADDRCF. Then it enters a loop checking 'I2C_ISR.RXNE = 1? I2C_ISR.TCR = 1?'. If yes, it reads RXDATA, programs NACK=0, NBYTES=1, and decrements N. If N=1, it reads RXDATA, programs RELOAD=0, NACK=0, and NBYTES=1, then loops back to check RXNE. If yes, it reads RXDATA and ends. A vertical double-headed arrow labeled 'SCL stretched' spans the RXNE loop.
graph TD; Start([SMBus target reception]) --> Init[Target initialization]; Init --> AddrCheck{I2C_ISR.ADDR = 1?}; AddrCheck -- No --> AddrCheck; AddrCheck -- Yes --> ReadAddr[Read ADDCODE and DIR in I2C_ISR
I2C_CR2.NBYTES = 1, RELOAD = 1
PECBYTE = 1
Set I2C_ICR.ADDRCF]; ReadAddr --> RXNECheck{I2C_ISR.RXNE = 1?
I2C_ISR.TCR = 1?}; RXNECheck -- No --> RXNECheck; RXNECheck -- Yes --> ReadData1[Read I2C_RXDR.RXDATA
Program I2C_CR2.NACK = 0
I2C_CR2.NBYTES = 1
N = N - 1]; ReadData1 --> NCheck{N = 1?}; NCheck -- No --> RXNECheck; NCheck -- Yes --> ReadData2[Read I2C_RXDR.RXDATA
Program RELOAD = 0
NACK = 0 and NBYTES = 1]; ReadData2 --> RXNECheck2{I2C_ISR.RXNE = 1?}; RXNECheck2 -- No --> RXNECheck2; RXNECheck2 -- Yes --> ReadData3[Read I2C_RXDR.RXDATA]; ReadData3 --> End([End]);

SCL stretched

MSv19868V3

Flowchart for SMBus target reception. It starts with 'SMBus target reception', followed by 'Target initialization'. A loop checks 'I2C_ISR.ADDR = 1?'. If yes, it reads ADDCODE and DIR, sets NBYTES=1, RELOAD=1, PECBYTE=1, and sets ADDRCF. Then it enters a loop checking 'I2C_ISR.RXNE = 1? I2C_ISR.TCR = 1?'. If yes, it reads RXDATA, programs NACK=0, NBYTES=1, and decrements N. If N=1, it reads RXDATA, programs RELOAD=0, NACK=0, and NBYTES=1, then loops back to check RXNE. If yes, it reads RXDATA and ends. A vertical double-headed arrow labeled 'SCL stretched' spans the RXNE loop.

Figure 541. Bus transfer diagrams for SMBus target receiver (SBC = 1)

Two bus transfer diagrams for SMBus target receiver. The first shows a standard reception of 2 bytes + PEC with NBYTES=3. The second shows reception with ACK control (RELOAD=1/0) where NBYTES=1. Both diagrams show the sequence: Start, Address, Ack, data1, Ack, data2, Ack, PEC, Ack, Stop. Events EV1 through EV4 are marked at specific points in the sequence.

Example SMBus target receiver 2 bytes + PEC

legend:
□ transmission
□ reception
— SCL stretch

EV1: ADDR ISR: check ADDCODE and DIR, program NBYTES = 3, PECBYTE = 1, RELOAD = 0, set ADDRCF
EV2: RXNE ISR: rd data1
EV3: RXNE ISR: rd data2
EV4: RXNE ISR: rd PEC

Example SMBus target receiver 2 bytes + PEC, with ACK control (RELOAD = 1/0)

legend :
□ transmission
□ reception
— SCL stretch

EV1: ADDR ISR: check ADDCODE and DIR, program NBYTES = 1, PECBYTE = 1, RELOAD = 1, set ADDRCF
EV2: RXNE-TCR ISR: rd data1, program NACK=0 and NBYTES = 1
EV3: RXNE-TCR ISR: rd data2, program NACK=0, NBYTES = 1 and RELOAD = 0
EV4: RXNE-TCR ISR: rd PEC

MSv19870V3

Two bus transfer diagrams for SMBus target receiver. The first shows a standard reception of 2 bytes + PEC with NBYTES=3. The second shows reception with ACK control (RELOAD=1/0) where NBYTES=1. Both diagrams show the sequence: Start, Address, Ack, data1, Ack, data2, Ack, PEC, Ack, Stop. Events EV1 through EV4 are marked at specific points in the sequence.

50.4.15 SMBus controller mode

In addition to I2C controller transfer management (refer to Section 50.4.9: I2C controller mode), this section provides extra software flowcharts to support SMBus.

SMBus controller transmitter

When the SMBus controller wants to transmit the PEC, the PECBYTE bit must be set and the number of bytes must be loaded in the NBYTES[7:0] bitfield, before setting the START bit. In this case, the total number of TXIS interrupts is NBYTES[7:0] - 1. So if the PECBYTE bit is set when NBYTES[7:0] = 0x1, the content of the I2C_PECR register is automatically transmitted.

If the SMBus controller wants to send a STOP condition after the PEC, the automatic end mode must be selected (AUTOEND = 1). In this case, the STOP condition automatically follows the PEC transmission.

When the SMBus controller wants to send a RESTART condition after the PEC, the software mode must be selected (AUTOEND = 0). In this case, once NBYTES[7:0] - 1 are transmitted, the I2C_PECR register content is transmitted. The TC flag is set after the PEC transmission, stretching the SCL line low. The RESTART condition must be programmed in the TC interrupt subroutine.

Caution: The PECBYTE bit has no effect when the RELOAD bit is set.

Figure 542. Bus transfer diagrams for SMBus controller transmitter

Figure 542: Bus transfer diagrams for SMBus controller transmitter. The diagram shows two examples: 1) Automatic end mode (STOP) for 2 bytes + PEC, and 2) Software end mode (RESTART) for 2 bytes + PEC. It includes timing diagrams for TXE, NBYTES, TXIS, and TC interrupts, along with a legend for transmission, reception, and SCL stretch.

Example SMBus controller transmitter 2 bytes + PEC, automatic end mode (STOP)

Legend:
□ transmission
□ reception
— SCL stretch

INIT: program target address, program NBYTES = 3, AUTOEND=1, set PECBYTE, set START
EV1: TXIS ISR: wr data1
EV2: TXIS ISR: wr data2

Example SMBus controller transmitter 2 bytes + PEC, software end mode (RESTART)

Legend:
□ transmission
□ reception
— SCL stretch

INIT: program target address, program NBYTES = 3, AUTOEND=0, set PECBYTE, set START
EV1: TXIS ISR: wr data1
EV2: TXIS ISR: wr data2
EV3: TC ISR: program target address, program NBYTES = N, set START

MSv19871V3

Figure 542: Bus transfer diagrams for SMBus controller transmitter. The diagram shows two examples: 1) Automatic end mode (STOP) for 2 bytes + PEC, and 2) Software end mode (RESTART) for 2 bytes + PEC. It includes timing diagrams for TXE, NBYTES, TXIS, and TC interrupts, along with a legend for transmission, reception, and SCL stretch.

SMBus controller receiver

When the SMBus controller wants to receive, at the end of the transfer, the PEC followed by a STOP condition, the automatic end mode can be selected (AUTOEND = 1). The PECBYTE bit must be set and the target address programmed before setting the START bit. In this case, after the receipt of NBYTES[7:0] - 1 data bytes, the next received byte is automatically checked versus the I2C_PECR register content. A NACK response is given to the PEC byte, followed by a STOP condition.

When the SMBus controller receiver wants to receive, at the end of the transfer, the PEC byte followed by a RESTART condition, the software mode must be selected (AUTOEND = 0). The PECBYTE bit must be set and the target address programmed before setting the START bit. In this case, after the receipt of NBYTES[7:0] - 1 data bytes, the next received byte is automatically checked versus the I2C_PECR register content. The TC flag is set after the PEC byte reception, stretching the SCL line low. The RESTART condition can be programmed in the TC interrupt subroutine.

Caution: The PECBYTE bit has no effect when the RELOAD bit is set.

Figure 543. Bus transfer diagrams for SMBus controller receiver

Diagram of SMBus controller receiver in automatic end mode (STOP). The sequence shows a START condition (S), address reception (A), data1 reception (data1), address reception (A), data2 reception (data2), address reception (A), PEC reception (PEC), Not Acknowledge (NA), and STOP condition (P). Events are marked: INIT at S, EV1 at data1, EV2 at data2, and EV3 at PEC. RXNE events are indicated above the data and PEC fields. A legend shows transmission as a white box, reception as a yellow box, and SCL stretch as a blue line. The NBYTES register is set to 3. Diagram of SMBus controller receiver in software end mode (RESTART). The sequence shows a START condition (S), address reception (A), data1 reception (data1), address reception (A), data2 reception (data2), address reception (A), PEC reception (PEC), Not Acknowledge (NA), a Restart condition (Restart), and address reception (Address). Events are marked: INIT at S, EV1 at data1, EV2 at data2, EV3 at PEC, and EV4 at the Restart condition. RXNE events are indicated above the data and PEC fields, and a TC event is indicated above the Restart condition. A legend shows transmission as a white box, reception as a yellow box, and SCL stretch as a blue line. The NBYTES register is set to 3, and a separate field N is shown for the restart address.

Example SMBus controller receiver 2 bytes + PEC, automatic end mode (STOP)

INIT: program target address, program NBYTES = 3, AUTOEND=1, set PECBYTE, set START
EV1: RXNE ISR: rd data1
EV2: RXNE ISR: rd data2
EV3: RXNE ISR: rd PEC

Example SMBus controller receiver 2 bytes + PEC, software end mode (RESTART)

INIT: program target address, program NBYTES = 3, AUTOEND = 0, set PECBYTE, set START
EV1: RXNE ISR: rd data1
EV2: RXNE ISR: rd data2
EV3: RXNE ISR: read PEC
EV4: TC ISR: program target address, program NBYTES = N, set START

MSv19872V3

Diagram of SMBus controller receiver in automatic end mode (STOP). The sequence shows a START condition (S), address reception (A), data1 reception (data1), address reception (A), data2 reception (data2), address reception (A), PEC reception (PEC), Not Acknowledge (NA), and STOP condition (P). Events are marked: INIT at S, EV1 at data1, EV2 at data2, and EV3 at PEC. RXNE events are indicated above the data and PEC fields. A legend shows transmission as a white box, reception as a yellow box, and SCL stretch as a blue line. The NBYTES register is set to 3. Diagram of SMBus controller receiver in software end mode (RESTART). The sequence shows a START condition (S), address reception (A), data1 reception (data1), address reception (A), data2 reception (data2), address reception (A), PEC reception (PEC), Not Acknowledge (NA), a Restart condition (Restart), and address reception (Address). Events are marked: INIT at S, EV1 at data1, EV2 at data2, EV3 at PEC, and EV4 at the Restart condition. RXNE events are indicated above the data and PEC fields, and a TC event is indicated above the Restart condition. A legend shows transmission as a white box, reception as a yellow box, and SCL stretch as a blue line. The NBYTES register is set to 3, and a separate field N is shown for the restart address.

50.4.16 Wake-up from Stop mode on address match

The I2C peripheral is able to wake up the device from Stop mode (APB clock is off), when the device is addressed. All addressing modes are supported.

The wake-up from Stop mode is enabled by setting the WUPEN bit of the I2C_CR1 register. The HSI or CSI oscillator must be selected as the clock source for i2c_ker_ck to allow the wake-up from Stop mode.

In Stop mode, the HSI or CSI oscillator is stopped. Upon detecting START condition, the I2C interface starts the HSI or CSI oscillator and stretches SCL low until the oscillator wakes up.

HSI or CSI is then used for the address reception.

If the received address matches the device own address, I2C stretches SCL low until the device wakes up. The stretch is released when the ADDR flag is cleared by software. Then the transfer goes on normally.

If the address does not match, the HSI or CSI oscillator is stopped again and the device does not wake up.

Note: When the system clock is used as I2C clock, or when WUPEN = 0, the HSI or CSI oscillator does not start upon receiving START condition.

Only an ADDR interrupt can wake the device up. Therefore, do not enter Stop mode when I2C is performing a transfer, either as a controller or as an addressed target after the ADDR flag is set. This can be managed by clearing the SLEEPDEEP bit in the ADDR interrupt routine and setting it again only after the STOPF flag is set.

Caution: The digital filter is not compatible with the wake-up from Stop mode feature. Before entering Stop mode with the WUPEN bit set, deactivate the digital filter, by writing zero to the DNF[3:0] bitfield.

Caution: The feature is only available when the HSI or CSI oscillator is selected as the I2C clock.

Caution: Clock stretching must be enabled (NOSTRETCH = 0) to ensure proper operation of the wake-up from Stop mode feature.

Caution: If the wake-up from Stop mode is disabled (WUPEN = 0), the I2C peripheral must be disabled before entering Stop mode (PE = 0).

50.4.17 Error conditions

The following errors are the conditions that can cause the communication to fail.

Bus error (BERR)

A bus error is detected when a START or a STOP condition is detected and is not located after a multiple of nine SCL clock pulses. START or STOP condition is detected when an SDA edge occurs while SCL is high.

The bus error flag is set only if the I2C peripheral is involved in the transfer as controller or addressed target (that is, not during the address phase in target mode).

In case of a misplaced START or RESTART detection in target mode, the I2C peripheral enters address recognition state like for a correct START condition.

When a bus error is detected, the BERR flag of the I2C_ISR register is set, and an interrupt is generated if the ERRIE bit of the I2C_CR1 register is set.

Arbitration loss (ARLO)

An arbitration loss is detected when a high level is sent on the SDA line, but a low level is sampled on the SCL rising edge.

In controller mode, arbitration loss is detected during the address phase, data phase and data acknowledge phase. In this case, the SDA and SCL lines are released, the START control bit is cleared by hardware and the controller switches automatically to target mode.

In target mode, arbitration loss is detected during data phase and data acknowledge phase. In this case, the transfer is stopped and the SCL and SDA lines are released.

When an arbitration loss is detected, the ARLO flag of the I2C_ISR register is set and an interrupt is generated if the ERRIE bit of the I2C_CR1 register is set.

Overrun/underrun error (OVR)

An overrun or underrun error is detected in target mode when NOSTRETCH = 1 and:

When an overrun or underrun error is detected, the OVR flag of the I2C_ISR register is set and an interrupt is generated if the ERRIE bit of the I2C_CR1 register is set.

Packet error checking error (PECERR)

A PEC error is detected when the received PEC byte does not match the I2C_PECR register content. A NACK is automatically sent after the wrong PEC reception.

When a PEC error is detected, the PECERR flag of the I2C_ISR register is set and an interrupt is generated if the ERRIE bit of the I2C_CR1 register is set.

Timeout error (TIMEOUT)

A timeout error occurs for any of these conditions:

When a timeout violation is detected in controller mode, a STOP condition is automatically sent.

When a timeout violation is detected in target mode, the SDA and SCL lines are automatically released.

When a timeout error is detected, the TIMEOUT flag is set in the I2C_ISR register and an interrupt is generated if the ERRIE bit of the I2C_CR1 register is set.

Alert (ALERT)

The ALERT flag is set when the I2C peripheral is configured as a host (SMBHEN = 1), the SMBALERT# signal detection is enabled (ALERTEN = 1), and a falling edge is detected on the SMBA pin. An interrupt is generated if the ERRIE bit of the I2C_CR1 register is set.

50.5 I2C in low-power modes

Table 360. Effect of low-power modes to I2C

ModeDescription
SleepNo effect. I2C interrupts cause the device to exit the Sleep mode.
Stop(1)The contents of I2C registers are kept.
– WUPEN = 1 and I2C is clocked by an internal oscillator (HSI or CSI). The address recognition is functional. The I2C address match condition causes the device to exit the Stop mode.
– WUPEN = 0: the I2C must be disabled before entering Stop mode.
StandbyThe I2C peripheral is powered down. It must be reinitialized after exiting Standby mode.

50.6 I2C interrupts

The following table gives the list of I2C interrupt requests.

Table 361. I2C interrupt requests

Interrupt acronymInterrupt eventEvent flagEnable control bitInterrupt clear methodExit Sleep modeExit Stop modesExit Standby modes
I2C_EVReceive buffer not emptyRXNERXIERead I2C_RXDR registerYesNoNo
Transmit buffer interrupt statusTXISTXIEWrite I2C_TXDR register
STOP detection interrupt flagSTOPFSTOPIEWrite STOPCF = 1
Transfer complete reloadTCRTCIEWrite I2C_CR2 with NBYTES[7:0] ≠ 0
Transfer completeTCWrite START = 1 or STOP = 1Yes(1)
Address matchedADDRADDRIEWrite ADDRCF = 1
NACK receptionNACKFNACKIEWrite NACKCF = 1No
I2C_ERRBus errorBERRERRIEWrite BERRCF = 1YesNoNo
Arbitration lossARLOWrite ARLOCF = 1
Overrun/underrunOVRWrite OVRCF = 1
I2C_ERRPEC errorPECERRERRIEWrite PECERRCF = 1YesNoNo
Timeout/
tLOW error
TIMEOUTWrite TIMEOUTCF = 1
SMBus alertALERTWrite ALERTCF = 1

50.7 I2C DMA requests

50.7.1 Transmission using DMA

DMA (direct memory access) can be enabled for transmission by setting the TXDMAEN bit of the I2C_CR1 register. Data is loaded from an SRAM area configured through the DMA peripheral (see Section 18: Direct memory access controller (DMA)) to the I2C_TXDR register whenever the TXIS bit is set.

Only the data are transferred with DMA.

In controller mode, the initialization, the target address, direction, number of bytes and START bit are programmed by software (the transmitted target address cannot be transferred with DMA). When all data are transferred using DMA, DMA must be initialized before setting the START bit. The end of transfer is managed with the NBYTES counter. Refer to Controller transmitter.

In target mode:

The PEC transfer is managed with the counter associated to the NBYTES[7:0] bitfield. Refer to SMBus target transmitter and SMBus controller transmitter.

Note: If DMA is used for transmission, it is not required to set the TXIE bit.

50.7.2 Reception using DMA

DMA (direct memory access) can be enabled for reception by setting the RXDMAEN bit of the I2C_CR1 register. Data is loaded from the I2C_RXDR register to an SRAM area configured through the DMA peripheral (refer to Section 18: Direct memory access controller (DMA)) whenever the RXNE bit is set. Only the data (including PEC) are transferred with DMA.

In controller mode, the initialization, the target address, direction, number of bytes and START bit are programmed by software. When all data are transferred using DMA, DMA must be initialized before setting the START bit. The end of transfer is managed with the NBYTES counter.

In target mode with NOSTRETCH = 0, when all data are transferred using DMA, DMA must be initialized before the address match event, or in the ADDR interrupt subroutine, before clearing the ADDR flag.

The PEC transfer is managed with the counter associated to the NBYTES[7:0] bitfield. Refer to SMBus target receiver and SMBus controller receiver.

Note: If DMA is used for reception, it is not required to set the RXIE bit.

50.8 I2C debug modes

When the device enters debug mode (core halted), the SMBus timeout either continues working normally or stops, depending on the I2Cx bits in the DBG block.

50.9 I2C registers

Refer to Section 1.2 for the list of abbreviations used in register descriptions.

The registers are accessed by words (32-bit).

50.9.1 I2C control register 1 (I2C_CR1)

Address offset: 0x00

Reset value: 0x0000 0000

Access: no wait states, except if a write access occurs while a write access is ongoing. In this case, wait states are inserted in the second write access, until the previous one is completed. The latency of the second write access can be up to \(2 \times i2c\_pclk + 6 \times i2c\_ker\_ck\).

column_1Refer toRM0442 Section 1.2
31 30 292827 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res.Res.Res. Res. Res. Res. PECEN ALERT SMBD SMBH NOSTR
E N GCEN WUPE
EN EN N ETCH SBC
rw rw rw rw rw rw rw rw
15 14 131211 10 9 8 7 6 5 4 3 2 1 0
RXDM TXDMANACKI ADDRI
EN Res.ANF
OFFDNF[3:0] ERRIE TCIE STOP
AENIE E E RXIE TXIE PE
rw rwrwrw rw rw rw rw rw rw rw rw rw rw rw
Bit 23PECEN:PEC enable
Bit 22ALERTEN: SMBus alert enable
Bit 21SMBDEN: SMBus device default address enable
Bit 20SMBHEN: SMBus host address enable
Bit 19GCEN: General call enable
Bit 18WUPEN: Wake-up from Stop mode enable

Bits 31:24 Reserved, must be kept at reset value.

Bit 23 PECEN: PEC enable

Bit 22 ALERTEN: SMBus alert enable

Note: When ALERTEN = 0, the SMBA pin can be used as a standard GPIO.

Bit 21 SMBDEN: SMBus device default address enable

Bit 20 SMBHEN: SMBus host address enable

Bit 19 GCEN: General call enable

Bit 18 WUPEN: Wake-up from Stop mode enable

Note: WUPEN can be set only when DNF[3:0] = 0000.

Bit 5 STOPIE: STOP detection interrupt enable

Bit 4 NACKIE: Not acknowledge received interrupt enable

Bit 3 ADDRIE: Address match interrupt enable (target only)

Bit 2 RXIE: RX interrupt enable

Bit 1 TXIE: TX interrupt enable

Bit 0 PE: Peripheral enable

Note: When PE = 0, the I2C SCL and SDA lines are released. Internal state machines and status bits are put back to their reset value. When cleared, PE must be kept low for at least three APB clock cycles.

50.9.2 I2C control register 2 (I2C_CR2)

Address offset: 0x04

Reset value: 0x0000 0000

Access: no wait states, except if a write access occurs while a write access is ongoing. In this case, wait states are inserted in the second write access until the previous one is completed. The latency of the second write access can be up to \(2 \times i2c\_pclk + 6 \times i2c\_ker\_ck\).

50.9.2column_2Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0STOPIE NACKIE ADDRIE RXIE TXIE PE 6 x i2c_ker_ck.column_5column_6column_7column_8column_9column_10column_11column_12column_13column_14column_15RM0442
31302928272625242322212019181716
Res.Res.Res.Res.Res.PECBYAUTOERELOA
TENDDNBYTES[7:0]
rsrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
0R HEAD1ADD10RD_W
RN RNSADD[9:0]
rsrsrsrwrwrwrwrwrwrwrwrwrwrwrwrw
Bit 26PECBYTE:Packet error checking byte

Bits 31:27 Reserved, must be kept at reset value.

Bit 26 PECBYTE: Packet error checking byte

This bit is set by software, and cleared by hardware when the PEC is transferred, or when a STOP condition or an Address matched is received, also when PE = 0.

Note: Writing 0 to this bit has no effect.

This bit has no effect when RELOAD is set, and in target mode when SBC = 0.

Bit 25 AUTOEND: Automatic end mode (controller mode)

This bit is set and cleared by software.

0: software end mode: TC flag is set when NBYTES data are transferred, stretching SCL low.

1: Automatic end mode: a STOP condition is automatically sent when NBYTES data are transferred.

Note: This bit has no effect in target mode or when the RELOAD bit is set.

Bit 24 RELOAD: NBYTES reload mode

This bit is set and cleared by software.

0: The transfer is completed after the NBYTES data transfer (STOP or RESTART follows).

1: The transfer is not completed after the NBYTES data transfer (NBYTES is reloaded). TCR flag is set when NBYTES data are transferred, stretching SCL low.

Bits 23:16 NBYTES[7:0]: Number of bytes

The number of bytes to be transmitted/received is programmed there. This field is don't care in target mode with SBC = 0.

Note: Changing these bits when the START bit is set is not allowed.

Bit 15 NACK: NACK generation (target mode)

The bit is set by software, cleared by hardware when the NACK is sent, or when a STOP condition or an Address matched is received, or when PE = 0.

0: an ACK is sent after current received byte.

1: a NACK is sent after current received byte.

Note: Writing 0 to this bit has no effect.

This bit is used only in target mode: in controller receiver mode, NACK is automatically generated after last byte preceding STOP or RESTART condition, whatever the NACK bit value.

When an overrun occurs in target receiver NOSTRETCH mode, a NACK is automatically generated, whatever the NACK bit value.

When hardware PEC checking is enabled (PECBYTE = 1), the PEC acknowledge value does not depend on the NACK value.

Bit 14 STOP: STOP condition generation

This bit only pertains to controller mode. It is set by software and cleared by hardware when a STOP condition is detected or when PE = 0.

0: No STOP generation

1: STOP generation after current byte transfer

Note: Writing 0 to this bit has no effect.

Bit 13 START: START condition generation

This bit is set by software. It is cleared by hardware after the START condition followed by the address sequence is sent, by an arbitration loss, by a timeout error detection, or when PE = 0. It can also be cleared by software, by setting the ADDRCONF bit of the I2C_ICR register.

0: No START generation

1: RESTART/START generation:

If the I2C is already in controller mode with AUTOEND = 0, setting this bit generates a repeated START condition when RELOAD = 0, after the end of the NBYTES transfer.

Otherwise, setting this bit generates a START condition once the bus is free.

Note: Writing 0 to this bit has no effect.

The START bit can be set even if the bus is BUSY or I2C is in target mode.

This bit has no effect when RELOAD is set.

50.9.3 I2C own address 1 register (I2C_OAR1)

Address offset: 0x08

Reset value: 0x0000 0000

Access: no wait states, except if a write access occurs while a write access is ongoing. In this case, wait states are inserted in the second write access until the previous one is completed. The latency of the second write access can be up to \(2 \times i2c\_pclk + 6 \times i2c\_ker\_ck\).

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
OA1ENRes.Res.Res.Res.OA1M
ODE
OA1[9:0]
rwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:16 Reserved, must be kept at reset value.

Bits 14:11 Reserved, must be kept at reset value.

Bit 10 OA1MODE: Own address 1 10-bit mode

0: Own address 1 is a 7-bit address.

1: Own address 1 is a 10-bit address.

Note: This bit can be written only when OA1EN = 0.

Bits 9:0 OA1[9:0]: Interface own target address

7-bit addressing mode: OA1[7:1] contains the 7-bit own target address. Bits OA1[9], OA1[8] and OA1[0] are don't care.

10-bit addressing mode: OA1[9:0] contains the 10-bit own target address.

Note: These bits can be written only when OA1EN = 0.

50.9.4 I2C own address 2 register (I2C_OAR2)

Address offset: 0x0C

Reset value: 0x0000 0000

Access: no wait states, except if a write access occurs while a write access is ongoing. In this case, wait states are inserted in the second write access, until the previous one is completed. The latency of the second write access can be up to 2x i2c_pclk + 6 x i2c_ker_ck.

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
OA2ENRes.Res.Res.Res.OA2MSK[2:0]OA2[7:1]Res.
rwrwrwrwrwrwrwrwrwrwrw

Bits 31:16 Reserved, must be kept at reset value.

Bit 15 OA2EN: Own address 2 enable

0: Own address 2 disabled. The received target address OA2 is NACKed.

1: Own address 2 enabled. The received target address OA2 is ACKed.

Bits 14:11 Reserved, must be kept at reset value.

Bits 10:8 OA2MSK[2:0]: Own address 2 masks

000: No mask

001: OA2[1] is masked and don't care. Only OA2[7:2] are compared.

010: OA2[2:1] are masked and don't care. Only OA2[7:3] are compared.

011: OA2[3:1] are masked and don't care. Only OA2[7:4] are compared.

100: OA2[4:1] are masked and don't care. Only OA2[7:5] are compared.

101: OA2[5:1] are masked and don't care. Only OA2[7:6] are compared.

110: OA2[6:1] are masked and don't care. Only OA2[7] is compared.

111: OA2[7:1] are masked and don't care. No comparison is done, and all (except reserved) 7-bit received addresses are acknowledged.

Note: These bits can be written only when OA2EN = 0.

As soon as OA2MSK ≠ 0, the reserved I2C addresses (0b0000xxx and 0b1111xxx) are not acknowledged, even if the comparison matches.

Bits 7:1 OA2[7:1]: Interface address

7-bit addressing mode: 7-bit address

Note: These bits can be written only when OA2EN = 0.

Bit 0 Reserved, must be kept at reset value.

50.9.5 I2C timing register (I2C_TIMINGR)

Address offset: 0x10

Reset value: 0x0000 0000

Access: no wait states

31302928272625242322212019181716
PRESC[3:0]Res.Res.Res.Res.SCLDEL[3:0]SDADEL[3:0]
rwrwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
SCLH[7:0]SCLL[7:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:28 PRESC[3:0]: Timing prescaler

This field is used to prescale i2c_ker_ck to generate the clock period \(t_{\text{PRESC}}\) used for data setup and hold counters (refer to section I2C timings), and for SCL high and low level counters (refer to section I2C controller initialization).

\[t_{\text{PRESC}} = (\text{PRESC} + 1) \times t_{\text{I2CCLK}}\]

Bits 27:24 Reserved, must be kept at reset value.

Bits 23:20 SCLDEL[3:0]: Data setup time

This field is used to generate a delay \(t_{\text{SCLDEL}} = (\text{SCLDEL} + 1) \times t_{\text{PRESC}}\) between SDA edge and SCL rising edge. In controller and in target modes with NOSTRETCH = 0, the SCL line is stretched low during \(t_{\text{SCLDEL}}\).

Note: \(t_{\text{SCLDEL}}\) is used to generate \(t_{\text{SU:DAT}}\) timing.

Bits 19:16 SDADEL[3:0]: Data hold time

This field is used to generate the delay \(t_{\text{SDADEL}}\) between SCL falling edge and SDA edge. In controller and in target modes with NOSTRETCH = 0, the SCL line is stretched low during \(t_{\text{SDADEL}}\).

\[t_{\text{SDADEL}} = \text{SDADEL} \times t_{\text{PRESC}}\]

Note: SDADEL is used to generate \(t_{\text{HD:DAT}}\) timing.

Bits 15:8 SCLH[7:0]: SCL high period (controller mode)

This field is used to generate the SCL high period in controller mode.

\[t_{\text{SCLH}} = (\text{SCLH} + 1) \times t_{\text{PRESC}}\]

Note: SCLH is also used to generate \(t_{\text{SU:STO}}\) and \(t_{\text{HD:STA}}\) timing.

Bits 7:0 SCLL[7:0]: SCL low period (controller mode)

This field is used to generate the SCL low period in controller mode.

\[t_{\text{SCLL}} = (\text{SCLL} + 1) \times t_{\text{PRESC}}\]

Note: SCLL is also used to generate \(t_{\text{BUF}}\) and \(t_{\text{SU:STA}}\) timings.

Note: This register must be configured when the I2C peripheral is disabled (PE = 0).

Note: The STM32CubeMX tool calculates and provides the I2C_TIMINGR content in the I2C Configuration window.

50.9.6 I2C timeout register (I2C_TIMEOUTR)

Address offset: 0x14

Reset value: 0x0000 0000

Access: no wait states, except if a write access occurs while a write access is ongoing. In this case, wait states are inserted in the second write access until the previous one is completed. The latency of the second write access can be up to \(2 \times i2c\_pclk + 6 \times i2c\_ker\_ck\).

31302928272625242322212019181716
TEXTENRes.Res.Res.TIMEOUTB[11:0]
rwrwrwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
TIMOUTENRes.Res.TIDLETIMEOUTA[11:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bit 31 TEXTEN: Extended clock timeout enable

0: Extended clock timeout detection is disabled

1: Extended clock timeout detection is enabled. When a cumulative SCL stretch for more than \(t_{LOW:EXT}\) is done by the I2C interface, a timeout error is detected (TIMEOUT = 1).

Bits 30:28 Reserved, must be kept at reset value.

Bits 27:16 TIMEOUTB[11:0]: Bus timeout B

This field is used to configure the cumulative clock extension timeout:

– Controller mode: the controller cumulative clock low extend time (\(t_{LOW:MEXT}\)) is detected

– Target mode: the target cumulative clock low extend time (\(t_{LOW:SEXT}\)) is detected

\(t_{LOW:EXT} = (TIMEOUTB + TIDLE = 01) \times 2048 \times t_{I2CCLK}\)

Note: These bits can be written only when TEXTEN = 0.

Bit 15 TIMOUTEN: Clock timeout enable

0: SCL timeout detection is disabled

1: SCL timeout detection is enabled. When SCL is low for more than \(t_{TIMEOUT}\) (TIDLE = 0) or high for more than \(t_{IDLE}\) (TIDLE = 1), a timeout error is detected (TIMEOUT = 1).

Bits 14:13 Reserved, must be kept at reset value.

Bit 12 TIDLE: Idle clock timeout detection

0: TIMEOUTA is used to detect SCL low timeout

1: TIMEOUTA is used to detect both SCL and SDA high timeout (bus idle condition)

Note: This bit can be written only when TIMOUTEN = 0.

Bits 11:0 TIMEOUTA[11:0]: Bus timeout A

This field is used to configure:

The SCL low timeout condition \(t_{TIMEOUT}\) when TIDLE = 0

\(t_{TIMEOUT} = (TIMEOUTA + 1) \times 2048 \times t_{I2CCLK}\)

The bus idle condition (both SCL and SDA high) when TIDLE = 1

\(t_{IDLE} = (TIMEOUTA + 1) \times 4 \times t_{I2CCLK}\)

Note: These bits can be written only when TIMOUTEN = 0.

50.9.7 I2C interrupt and status register (I2C_ISR)

Address offset: 0x18

Reset value: 0x0000 0001

Access: no wait states

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.ADDCODE[6:0]DIR
rrrrrrrr
1514131211109876543210
BUSYRes.ALERTTIMEOUTPECERROVRARLOBERRTCRTCSTOPFNACKFADDRRXNETXISTXE
rrrrrrrrrrrrrrsrs

Bits 31:24 Reserved, must be kept at reset value.

Bits 23:17 ADDCODE[6:0]: Address match code (target mode)

These bits are updated with the received address when an address match event occurs (ADDR = 1). In the case of a 10-bit address, ADDCODE provides the 10-bit header followed by the two MSBs of the address.

Bit 16 DIR: Transfer direction (target mode)

This flag is updated when an address match event occurs (ADDR = 1).

0: Write transfer, target enters receiver mode.

1: Read transfer, target enters transmitter mode.

Bit 15 BUSY: Bus busy

This flag indicates that a communication is in progress on the bus. It is set by hardware when a START condition is detected, and cleared by hardware when a STOP condition is detected, or when PE = 0.

Bit 14 Reserved, must be kept at reset value.

Bit 13 ALERT: SMBus alert

This flag is set by hardware when SMBHEN = 1 (SMBus host configuration), ALERTEN = 1 and an SMBALERT# event (falling edge) is detected on SMBA pin. It is cleared by software by setting the ALERTCF bit.

Note: This bit is cleared by hardware when PE = 0.

Bit 12 TIMEOUT: Timeout or tLOW detection flag

This flag is set by hardware when a timeout or extended clock timeout occurred. It is cleared by software by setting the TIMEOUTCF bit.

Note: This bit is cleared by hardware when PE = 0.

Bit 11 PECERR: PEC error in reception

This flag is set by hardware when the received PEC does not match with the PEC register content. A NACK is automatically sent after the wrong PEC reception. It is cleared by software by setting the PECCF bit.

Note: This bit is cleared by hardware when PE = 0.

Bit 10 OVR: Overrun/underrun (target mode)

This flag is set by hardware in target mode with NOSTRETCH = 1, when an overrun/underrun error occurs. It is cleared by software by setting the OVRCF bit.

Note: This bit is cleared by hardware when PE = 0.

Bit 9 ARLO: Arbitration lost

This flag is set by hardware in case of arbitration loss. It is cleared by software by setting the ARLOCF bit.

Note: This bit is cleared by hardware when PE = 0.

Bit 8 BERR: Bus error

This flag is set by hardware when a misplaced START or STOP condition is detected whereas the peripheral is involved in the transfer. The flag is not set during the address phase in target mode. It is cleared by software by setting the BERRCF bit.

Note: This bit is cleared by hardware when PE = 0.

Bit 7 TCR: Transfer complete reload

This flag is set by hardware when RELOAD = 1 and NBYTES data have been transferred. It is cleared by software when NBYTES is written to a non-zero value.

Note: This bit is cleared by hardware when PE = 0.

This flag is only for controller mode, or for target mode when the SBC bit is set.

Bit 6 TC: Transfer complete (controller mode)

This flag is set by hardware when RELOAD = 0, AUTOEND = 0 and NBYTES data have been transferred. It is cleared by software when START bit or STOP bit is set.

Note: This bit is cleared by hardware when PE = 0.

Bit 5 STOPF: STOP detection flag

This flag is set by hardware when a STOP condition is detected on the bus and the peripheral is involved in this transfer:

It is cleared by software by setting the STOPCF bit.

Note: This bit is cleared by hardware when PE = 0.

Bit 4 NACKF: Not acknowledge received flag

This flag is set by hardware when a NACK is received after a byte transmission. It is cleared by software by setting the NACKCF bit.

Note: This bit is cleared by hardware when PE = 0.

Bit 3 ADDR: Address matched (target mode)

This bit is set by hardware as soon as the received target address matched with one of the enabled target addresses. It is cleared by software by setting ADDRCF bit.

Note: This bit is cleared by hardware when PE = 0.

Bit 2 RXNE: Receive data register not empty (receivers)

This bit is set by hardware when the received data is copied into the I2C_RXDR register, and is ready to be read. It is cleared when I2C_RXDR is read.

Note: This bit is cleared by hardware when PE = 0.

Bit 1 TXIS: Transmit interrupt status (transmitters)

This bit is set by hardware when the I2C_TXDR register is empty and the data to be transmitted must be written in the I2C_TXDR register. It is cleared when the next data to be sent is written in the I2C_TXDR register.

This bit can be written to 1 by software only when NOSTRETCH = 1, to generate a TXIS event (interrupt if TXIE = 1 or DMA request if TXDMAEN = 1).

Note: This bit is cleared by hardware when PE = 0.

Bit 0 TXE: Transmit data register empty (transmitters)

This bit is set by hardware when the I2C_TXDR register is empty. It is cleared when the next data to be sent is written in the I2C_TXDR register.

This bit can be written to 1 by software in order to flush the transmit data register I2C_TXDR.

Note: This bit is set by hardware when PE = 0.

50.9.8 I2C interrupt clear register (I2C_ICR)

Address offset: 0x1C

Reset value: 0x0000 0000

Access: no wait states

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.ALERT
CF
TIMOU
TCF
PECCFOVRCFARLOC
F
BERRC
F
Res.Res.STOPC
F
NACKC
F
ADDR
CF
Res.Res.Res.
wwwwwwwww

Bits 31:14 Reserved, must be kept at reset value.

Bit 13 ALERTCF: Alert flag clear

Writing 1 to this bit clears the ALERT flag in the I2C_ISR register.

Bit 12 TIMOUTCF: Timeout detection flag clear

Writing 1 to this bit clears the TIMEOUT flag in the I2C_ISR register.

Bit 11 PECCF: PEC error flag clear

Writing 1 to this bit clears the PECERR flag in the I2C_ISR register.

Bit 10 OVRCF: Overrun/underrun flag clear

Writing 1 to this bit clears the OVR flag in the I2C_ISR register.

Bit 9 ARLOCF: Arbitration lost flag clear

Writing 1 to this bit clears the ARLO flag in the I2C_ISR register.

Bit 8 BERRCF: Bus error flag clear

Writing 1 to this bit clears the BERRF flag in the I2C_ISR register.

Bits 7:6 Reserved, must be kept at reset value.

Bit 5 STOPCF: STOP detection flag clear

Writing 1 to this bit clears the STOPF flag in the I2C_ISR register.

Bit 4 NACKCF: Not acknowledge flag clear

Writing 1 to this bit clears the NACKF flag in I2C_ISR register.

Bit 3 ADDRCF: Address matched flag clear

Writing 1 to this bit clears the ADDR flag in the I2C_ISR register. Writing 1 to this bit also clears the START bit in the I2C_CR2 register.

Bits 2:0 Reserved, must be kept at reset value.

50.9.9 I2C PEC register (I2C_PECR)

Address offset: 0x20

Reset value: 0x0000 0000

Access: no wait states

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.PEC[7:0]
rrrrrrrr

Bits 31:8 Reserved, must be kept at reset value.

Bits 7:0 PEC[7:0]: Packet error checking register

This field contains the internal PEC when PECEN=1.

The PEC is cleared by hardware when PE = 0.

50.9.10 I2C receive data register (I2C_RXDR)

Address offset: 0x24

Reset value: 0x0000 0000

Access: no wait states

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.RXDATA[7:0]
rrrrrrrr

Bits 31:8 Reserved, must be kept at reset value.

Bits 7:0 RXDATA[7:0]: 8-bit receive data

Data byte received from the I2C-bus.

50.9.11 I2C transmit data register (I2C_TXDR)

Address offset: 0x28

Reset value: 0x0000 0000

Access: no wait states

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.TXDATA[7:0]
rwrwrwrwrwrwrwrw

Bits 31:8 Reserved, must be kept at reset value.

Bits 7:0 TXDATA[7:0]: 8-bit transmit data

Data byte to be transmitted to the I2C-bus

Note: These bits can be written only when TXE = 1.

50.9.12 I2C hardware configuration register (I2C_HWCFGR)

Address offset: 0x3F0

Reset value: 0x0000 0111

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.WKP[3:0]ASYN[3:0]SMBUS[3:0]
rrrrrrrrrrrr

Bits 31:12 Reserved, must be kept at reset value.

Bits 11:8 WKP[3:0]:

Bits 7:4 ASYN[3:0]:

Bits 3:0 SMBUS[3:0]:

50.9.13 I2C version register (I2C_VERR)

Address offset: 0x3F4

Reset value: 0x0000 0013

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.MAJREV[3:0]MINREV[3:0]
rrrrrrrr

Bits 31:8 Reserved, must be kept at reset value.

Bits 7:4 MAJREV[3:0]: Major revision

Bits 3:0 MINREV[3:0]: Minor revision

50.9.14 I2C identification register (I2C_IPIDR)

Address offset: 0x3F8

Reset value: 0x0013 0012

31302928272625242322212019181716
ID[31:16]
rrrrrrrrrrrrrrrr
1514131211109876543210
ID[15:0]
rrrrrrrrrrrrrrrr

Bits 31:0 ID[31:0]: Identifier.

50.9.15 I2C size identification register (I2C_SIDR)

Address offset: 0x3FC

Reset value: 0xA3C5 DD01

31302928272625242322212019181716
SID[31:16]
rrrrrrrrrrrrrrrr
1514131211109876543210
SID[15:0]
rrrrrrrrrrrrrrrr

Bits 31:0 SID[31:0]: Size identifier.

50.9.16 I2C register map

The table below provides the I2C register map and the reset values.

Table 362. I2C register map and reset values

OffsetRegister name313029282726252423222120191817161514131211109876543210
0x00I2C_CR1Res.Res.Res.Res.Res.Res.Res.Res.PECENALERTENSMBDENSMBHENGCENWUPENNOSTRETCHSBCRXDMAENTXDMAENRes.ANFOFFDNF[3:0]ERRIETCIESTOPIENACKIEADDRIERXIETXIEPE
Reset value0000000000000000000000
0x04I2C_CR2Res.Res.Res.Res.Res.PECBYTEAUTOENDRELOADNBYTES[7:0]NACKSTOPSTARTHEAD10RADD10RD_WRNSADD[9:0]
Reset value00000000000000000000000000
0x08I2C_OAR1Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.OA1ENRes.Res.Res.Res.OA1MODEOA1[9:0]
Reset value00000000000
0x0CI2C_OAR2Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.OA2ENRes.Res.Res.Res.OA2MSK [2:0]OA2[7:1]Res.
Reset value0000000000
0x10I2C_TIMINGRPRESC[3:0]Res.Res.Res.Res.SCLDEL [3:0]SDADEL [3:0]SCLH[7:0]SCLL[7:0]
Reset value000000000000000000000000000
0x14I2C_TIMEOUTRTEXTENRes.Res.Res.TIMEOUTB[11:0]TIMOUTENRes.Res.TIDLETIMEOUTA[11:0]
Reset value00000000000000000000000000
0x18I2C_ISRRes.Res.Res.Res.Res.Res.Res.Res.ADDCODE[6:0]DIRBUSYRes.ALERTTIMEOUTPECERROVRARLOBERRTCRTCSTOPFNACKFADDRFRXNETXISTXE
Reset value000000000000000000001
0x1CI2C_ICRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.ALERTCFTIMOUTCFPECCFOVRCFARLOCFBERRCFRes.Res.STOPCFNACKCFADDRCFRes.Res.Res.
Reset value000000000
0x20I2C_PECRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.PEC[7:0]
Reset value000000000
0x24I2C_RXDRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.RXDATA[7:0]
Reset value000000000
0x28I2C_TXDRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.TXDATA[7:0]
Reset value000000000
0x030-0x03ECReserved

Table 362. I2C register map and reset values (continued)

OffsetRegister name313029282726252423222120191817161514131211109876543210
0x03F0I2C_HWCFGRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.WKP[3:0]ASYN[3:0]SMBUS[3:0]
Reset value000100010001
0x03F4I2C_VERRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.MAJREV[3:0]MINREV[3:0]
Reset value00010011
0x03F8I2C_IPIDRID[31:16]ID[15:0]
Reset value00000000000100110000000000010010
0x03FCI2C_SIDRSID[31:16]SID[15:0]
Reset value10100011110001011101110100000001

Refer to Section 2.5 for the register boundary addresses.