21. Inter-integrated circuit (I 2 C) interface

21.1 Introduction

The I 2 C (inter-integrated circuit) bus interface handles communications between the microcontroller and the serial I 2 C bus. It provides multimaster capability, and controls all I 2 C bus-specific sequencing, protocol, arbitration and timing. It supports standard-mode (Sm), fast-mode (Fm) and fast-mode plus (Fm+).

It is also SMBus (system management bus) and PMBus (power management bus) compatible.

DMA can be used to reduce CPU overload.

21.2 I 2 C main features

The following additional features are also available depending on the product implementation (see Section 21.3: I 2 C implementation ):

Note: For the fast-mode plus mode, it is strongly recommended to use I 2 C pins mentioned as open-drain capable (embedding a 10ns/50ns filter).

21.3 I 2 C implementation

This manual describes the full set of features implemented in I2C1.

Table 85. STM32WB05xZ I 2 C implementation

I 2 C features (1)I2C1
7-bit addressing modeX
10-bit addressing modeX
Standard-mode (up to 100 kbit/s)X
Fast-mode (up to 400 kbit/s)X
Fast-mode plus with 20 mA output drive I/Os (up to 1 Mbit/s)X
Independent clockX
SMBusX

1. X=supported

21.4 I 2 C functional description

In addition to receiving and transmitting data, this interface converts it from serial to parallel format and vice versa. The interrupts are enabled or disabled by software. The interface is connected to the I 2 C bus by a data pin (SDA) and by a clock pin (SCL). It can be connected with a standard (up to 100 kHz), fast-mode (up to 400 kHz) or fast-mode plus (up to 1 MHz) I 2 C bus.

This interface can also be connected to an SMBus with the data pin (SDA) and clock pin (SCL).

If SMBus feature is supported: the additional optional SMBus alert pin (SMBA) is also available.

21.4.1 I 2 C block diagram

The block diagram of the I 2 C interface is shown below.

Figure 94. I 2 C block diagram

I2C block diagram showing internal components like Data control, Clock control, and Registers connected to an APB bus, with external pins I2Cx_SDA, I2Cx_SCL, and I2Cx_SMBA.

The block diagram illustrates the internal architecture of the I 2 C interface. At the bottom, an APB bus connects to a 'Registers' block, which is also connected to a 'PCLK' input. Above the registers are three main functional blocks: 'Data control', 'Clock control', and 'SMBus Alert control & status'. The 'Data control' block contains a 'Shift register' and 'SMBus PEC generation / check'. The 'Clock control' block contains 'Master clock generation', 'Slave clock stretching', and 'SMBus Timeout check'. The 'SMBus Alert control & status' block is connected to the 'I2Cx_SMBA' pin. The 'Data control' and 'Clock control' blocks are connected to 'Digital noise filter' blocks, which in turn connect to 'Analog noise filter' blocks. These analog filters connect to 'GPIO logic' blocks that drive the external pins 'I2Cx_SDA' and 'I2Cx_SCL'. These pins are also connected to 'From system configuration controller (SYSCFG) FM+ drive' inputs. The 'I2CCLK' input is connected to the 'Clock control' block.

I2C block diagram showing internal components like Data control, Clock control, and Registers connected to an APB bus, with external pins I2Cx_SDA, I2Cx_SCL, and I2Cx_SMBA.

The I 2 C is clocked by an independent clock source which allows the I 2 C to operate independently from the PCLK frequency.

This independent clock source is a fixed 16-MHz clock. Refer to Section 6: Reset and clock controller (RCC) for more details.

I 2 C I/Os supports 20 mA output current drive for fast-mode plus operation. This is enabled by setting the driving capability control bits for SCL and SDA in Section 8.2.3: I2C Fast-Mode Plus pin capability control register (I2C_FMP_CTRL) .

21.4.2 I 2 C clock requirements

The I 2 C kernel is clocked by I2CCLK.

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

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

with:

\( t_{LOW} \) : SCL low time and \( t_{HIGH} \) : SCL high time

\( t_{filters} \) : when enabled, sum of the delays brought by the analog filter and by the digital filter. Analog filter delay is maximum 260 ns. Digital filter delay is \( DNF \times t_{I2CCLK} \) .

The PCLK clock period \( t_{PCLK} \) must respect the following condition:

\[ t_{PCLK} < 4/3 t_{SCL} \]

with \( t_{SCL} \) : SCL period.

21.4.3 Mode selection

The interface can operate in one of the four following modes:

By default, it operates in target mode. The interface automatically switches from target to controller when it generates a START condition, and from controller to target if an arbitration loss or a STOP generation occurs, allowing multicontroller capability.

Communication flow

In controller mode, the I 2 C interface initiates a data transfer and generates the clock signal. A serial data transfer always begins with a START condition and ends with a STOP condition. Both START and STOP conditions are generated in controller mode by software.

In target mode, the interface is capable of recognizing its own addresses (7 or 10-bit), 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 first byte(s) following the START condition contain the address (one in 7-bit mode, two in 10-bit mode). The address is always transmitted in controller mode.

A 9 th clock pulse follows the 8 clock cycles of a byte transfer, during which the receiver must send an acknowledge bit to the transmitter. Refer to the following figure.

Figure 95. I 2 C bus protocol

Timing diagram of the I2C bus protocol showing SDA and SCL lines. The SDA line starts high and is pulled low to indicate a start condition. The SCL line is initially high and then pulled low. The SDA line then shows the Most Significant Bit (MSB) of a byte, followed by a gap (indicated by a dashed line), and then an Acknowledge (ACK) signal. The SCL line is shown as a series of pulses labeled 1, 2, ..., 8, 9. The SDA line returns to high at the stop condition, and the SCL line returns to high at the same time. Double-headed arrows indicate the start and stop conditions.
Timing diagram of the I2C bus protocol showing SDA and SCL lines. The SDA line starts high and is pulled low to indicate a start condition. The SCL line is initially high and then pulled low. The SDA line then shows the Most Significant Bit (MSB) of a byte, followed by a gap (indicated by a dashed line), and then an Acknowledge (ACK) signal. The SCL line is shown as a series of pulses labeled 1, 2, ..., 8, 9. The SDA line returns to high at the stop condition, and the SCL line returns to high at the same time. Double-headed arrows indicate the start and stop conditions.

Acknowledge can be enabled or disabled by software. The I 2 C interface addresses can be selected by software.

21.4.4

I 2 C initialization

Enabling and disabling the peripheral

The I 2 C peripheral clock must be configured and enabled in the clock controller (refer to Section 6: Reset and clock controller (RCC) ).

Then the I 2 C can be enabled by setting the PE bit in the I2C_CR1 register. When the I 2 C is disabled (PE=0), the I 2 C performs a software reset. Refer to Section 21.4.5: Software reset for more details.

Noise filters

Before you enable the I 2 C peripheral by setting the PE bit in the I2C_CR1 register, you must configure the noise filters, if needed. By default, an analog noise filter is present on the SDA and SCL inputs. This analog filter is compliant with the I 2 C specification which requires the suppression of spikes with a pulse width up to 50 ns in fast-mode and fast-mode plus. You can disable this analog filter by setting the ANFOFF bit, and/or select a digital filter by configuring the DNF[3:0] bit in the I2C_CR1 register.

When the digital filter is enabled, the level of the SCL or the SDA line is internally changed only if it remains stable for more than DNF x I2CCLK periods. This allows spikes to be suppressed with a programmable length of 1 to 15 I2CCLK periods.

Caution: Changing the filter configuration is not allowed when the I 2 C is enabled.

I 2 C timings

The timings must be configured in order to guarantee a correct data hold and set-up time, used in controller and target modes. This is done by programming the PRESC[3:0], SCLDEL[3:0] and SDADEL[3:0] bits in the I2C_TIMINGR register.

Figure 96. Setup and hold timings

Timing diagram for Data Hold Time showing SCL and SDA waveforms. It illustrates the relationship between the SCL falling edge and SDA data change. Key parameters shown are tSYNC1 (synchronization time), SDADEL (SDA delay), SDA output delay, and tHD;DAT (Data hold time). Timing diagram for Data Setup Time showing SCL and SDA waveforms. It illustrates the relationship between the SDA data change and the SCL rising edge. Key parameters shown are SCLDEL (SCL delay) and tSU;DAT (Data setup time).

DATA HOLD TIME

SCL falling edge internal detection

SCL

SDA

\( t_{SYNC1} \) \( SDADEL \)

SDA output delay

\( t_{HD;DAT} \)

Data hold time


DATA SETUP TIME

SCLDEL
SCL stretched low by the target transmitter

SCL

SDA

\( t_{SU;DAT} \)

Data setup time

Timing diagram for Data Hold Time showing SCL and SDA waveforms. It illustrates the relationship between the SCL falling edge and SDA data change. Key parameters shown are tSYNC1 (synchronization time), SDADEL (SDA delay), SDA output delay, and tHD;DAT (Data hold time). Timing diagram for Data Setup Time showing SCL and SDA waveforms. It illustrates the relationship between the SDA data change and the SCL rising edge. Key parameters shown are SCLDEL (SCL delay) and tSU;DAT (Data setup time).

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

\( t_{SDADEL} \) and impacts the hold time \( t_{HD;DAT} \) .

The total SDA output delay is:

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

\( t_{SYNC1} \) duration depends on these parameters:

In order to bridge the undefined region of the SCL falling edge, you must program SDADEL in such a way that:

\[ \{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)} \) / \( t_{AF(max)} \) are part of the equation only when the analog filter is enabled. Refer to device datasheet for \( t_{AF} \) values.

The maximum \( t_{HD;DAT} \) could be 3.45 µs, 0.9 µs and 0.45 µs for standard-mode, fast-mode and fast-mode plus, but must be less 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. If the clock stretches the SCL, the data must be validated by the set-up time before it releases the clock.

The SDA rising edge is usually the worst case, so in this case the previous equation becomes:

\[ SDADEL \leq \{t_{VD;DAT(max)} - t_{r(max)} - 260 \text{ ns} - [(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 value.

Refer to Table 86. I 2 C-SMBUS specification data setup and hold times for \( t_r \) , \( t_f \) , \( t_{HD;DAT} \) and \( t_{VD;DAT} \) standard values.

In order to bridge the undefined region of the SDA transition (rising edge usually worst case), you must program SCLDEL in such a way that:

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

Refer to Table 86. I 2 C-SMBUS specification data setup and hold times for \( t_r \) and \( t_{SU;DAT} \) standard values.

The SDA and SCL transition time values to be used are the ones in the application. Using the maximum values from the standard increases the constraints for the SDADEL and SCLDEL calculation, but ensures the feature whatever the application.

Table 86. I 2 C-SMBUS specification data setup and hold times

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

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] bits in the I2C_TIMINGR register.

\( t_{SCLL} \) impacts the SCL low time \( t_{LOW} \) .

Refer to Section 21.4.8: I2C controller mode for more details.

Caution: Changing the timing configuration is not allowed when the I 2 C is enabled.

The I 2 C target NOSTRETCH mode must also be configured before enabling the peripheral.

Caution: Changing the NOSTRETCH configuration is not allowed when the I 2 C is enabled.

Figure 97. I 2 C initialization flowchart

I2C initialization flowchart
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],
SCLL[7:0] in I2C_TIMINGR"] D --> E[Configure NOSTRETCH in I2C_CR1] E --> F[Set PE bit in I2C_CR1] F --> G([End])
I2C initialization flowchart

21.4.5 Software reset

A software reset can be performed by clearing the PE bit in the I2C_CR1 register. In that case I 2 C lines SCL and SDA are released. Internal state machines are reset and communication control bits, as well as status bits come back to their reset value. The configuration registers are not impacted.

Here is the list of impacted register bits:

    1. 1. I2C_CR2 register: START, STOP, NACK
    2. 2. I2C_ISR register: BUSY, TXE, TXIS, RXNE, ADDR, NACKF, TCR, TC, STOPF, BERR, ARLO, OVR
  1. and in addition when the SMBus feature is supported:
  1. 1. I2C_CR2 register: PECBYTE
  2. 2. I2C_ISR register: PECERR, TIMEOUT, ALERT

PE must be kept low during at least 3 APB clock cycles in order to perform the software reset. This is ensured by writing the following software sequence: - Write PE=0 - Check PE=0 - Write PE=1.

21.4.6 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 8 th 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, meaning that the previous received data byte has not yet been read, the SCL line is stretched low until I2C_RXDR is read. The stretch is inserted between the 8 th and 9 th SCL pulse (before the acknowledge pulse).

Figure 98. Data reception

Timing diagram for data reception showing SCL, Shift register, RXNE, and I2C_RXDR signals over time. It illustrates the flow of data bytes (data0, data1, data2) from the shift register to the I2C_RXDR register, triggered by ACK pulses and RXNE status. A legend indicates SCL stretch with a blue line.

The diagram shows the timing for data reception. The SCL line is a periodic clock. The Shift register contains 'xx', 'data1', 'xx', 'data2', 'xx'. The RXNE line is high when the shift register is not empty. The I2C_RXDR register contains 'data0', 'data1', 'data2'. Arrows show data being read from the shift register to I2C_RXDR ('rd data0', 'rd data1') when RXNE is high and an ACK pulse is received. A blue line on the SCL signal indicates a stretch between the 8th and 9th pulses.

Timing diagram for data reception showing SCL, Shift register, RXNE, and I2C_RXDR signals over time. It illustrates the flow of data bytes (data0, data1, data2) from the shift register to the I2C_RXDR register, triggered by ACK pulses and RXNE status. A legend indicates SCL stretch with a blue line.

Transmission

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

Figure 99. Data transmission

Timing diagram for data transmission showing SCL, Shift register, TXE, and I2C_TXDR signals over time. It illustrates the flow of data bytes (data0, data1, data2) from the I2C_TXDR register to the shift register, triggered by TXE status and ACK pulses. A legend indicates SCL stretch with a blue line.

The diagram shows the timing for data transmission. The SCL line is a periodic clock. The Shift register contains 'xx', 'data1', 'xx', 'data2', 'xx'. The TXE line is high when the shift register is empty. The I2C_TXDR register contains 'data0', 'data1', 'data2'. Arrows show data being written from I2C_TXDR to the shift register ('wr data1', 'wr data2') when TXE is high and an ACK pulse is received. A blue line on the SCL signal indicates a stretch after the 9th pulse.

Timing diagram for data transmission showing SCL, Shift register, TXE, and I2C_TXDR signals over time. It illustrates the flow of data bytes (data0, data1, data2) from the I2C_TXDR register to the shift register, triggered by TXE status and ACK pulses. A legend indicates SCL stretch with a blue line.

Hardware transfer management

The I 2 C has a byte counter embedded in hardware in order to manage byte transfer and to close the communication in various modes such as:

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

The number of bytes to be transferred is programmed in the NBBYTES[7:0] bit field in the I2C_CR2 register. If the number of bytes to be transferred (NBBYTES) 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 in the I2C_CR2 register. In this mode, TCR flag is set when the number of bytes programmed in NBBYTES has been transferred, and an interrupt is generated if TCIE is set. SCL is stretched as long as TCR flag is set. TCR is cleared by software when NBBYTES is written to a non-zero value.

When the NBBYTES counter is reloaded with the last number of bytes, RELOAD bit must be cleared.

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

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

Table 87. I 2 C configurable table

FunctionSBC bitRELOAD bitAUTOEND bit
Controller Tx/Rx NBBYTES + STOPx01
Controller Tx/Rx + NBBYTES + RESTARTx00
Target Tx/Rx
all received bytes ACKed
0xx
Target Rx with ACK control11x

21.4.7 I2C target mode

I 2 C target initialization

In order to work in target mode, you must enable at least one target address. Two registers, I2C_OAR1 and I2C_OAR2, are available in order to program the target own addresses OA1 and OA2.

When the I 2 C 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 needed, in order to perform software actions. If the controller does not support clock stretching, the I 2 C must be configured with NOSTRETCH=1 in the I2C_CR1 register.

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

Target clock stretching (NOSTRETCH = 0)

In default mode, the I 2 C target stretches the SCL clock in the following situations:

Target without clock stretching (NOSTRETCH = 1)

When NOSTRETCH = 1 in the I2C_CR1 register, the I 2 C target does not stretch the SCL signal.

Target byte control mode

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

Reload mode must be selected in order to allow byte ACK control in target reception mode (RELOAD=1). To get control of each byte, NBBYTES 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 8 th and 9 th SCL pulses. You can read the data from the I2C_RXDR register, and then decide to acknowledge it or not by configuring the ACK bit in the I2C_CR2 register. The SCL stretch is released by programming NBBYTES to a non-zero value: the acknowledge or not- acknowledge is sent and the next byte can be received.

NBYTES can be loaded with a value greater than 0x1, and in this case, the reception flow is continuous during NBBYTES data reception.

Note: The SBC bit must be configured when the I 2 C is disabled, or 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: Target byte control mode is not compatible with NOSTRETCH mode. Setting SBC when NOSTRETCH=1 is not allowed.

Figure 100. Target initialization flowchart

Flowchart for Target initialization. Steps: Target initialization (oval) -> Initial settings (rectangle) -> Clear {OA1EN, OA2EN} in I2C_CR1 (rectangle) -> Configure {OA1[9:0], OA1MODE, OA1EN, OA2[6:0], OA2MSK[2:0], OA2EN, GCEN} (rectangle) -> Configure SBC in I2C_CR1* (rectangle) -> Enable interrupts and/or DMA in I2C_CR1 (rectangle) -> End (oval).
graph TD
    A([Target initialization]) --> B[Initial settings]
    B --> C[Clear {OA1EN, OA2EN} in I2C_CR1]
    C --> D["Configure {OA1[9:0], OA1MODE, OA1EN, OA2[6:0], OA2MSK[2:0], OA2EN, GCEN}"]
    D --> E[Configure SBC in I2C_CR1*]
    E --> F[Enable interrupts and/or DMA in I2C_CR1]
    F --> G([End])
  
Flowchart for Target initialization. Steps: Target initialization (oval) -> Initial settings (rectangle) -> Clear {OA1EN, OA2EN} in I2C_CR1 (rectangle) -> Configure {OA1[9:0], OA1MODE, OA1EN, OA2[6:0], OA2MSK[2:0], OA2EN, GCEN} (rectangle) -> Configure SBC in I2C_CR1* (rectangle) -> Enable interrupts and/or DMA in I2C_CR1 (rectangle) -> End (oval).

*SBC must be set to support SMBus features

Target transmitter

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

The TXIS bit is cleared when the I2C_TXDR register is written with the next data byte to be transmitted.

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

When a STOP is received and the STOPIE bit is set in the I2C_CR1 register, the STOPF flag is set in the I2C_ISR register 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), you 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 be transmitted must be programmed in NBBYTES 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 NBBYTES.

Caution: When NOSTRETCH=1, the SCL clock is not stretched while the ADDR flag is set, so you cannot flush the I2C_TXDR register content in the ADDR subroutine, in order to program the first data byte. The first data byte to be sent 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 you need a TXIS event, (Transmit Interrupt or Transmit DMA request), you must set the TXIS bit in addition to the TXE bit, in order to generate a TXIS event.

Figure 101. Transfer sequence flowchart for I2C target transmitter, NOSTRETCH=0

graph TD;
    Start([Target transmission]) --> Init[Target initialization];
    Init --> AddrCheck{I2C_ISR.ADDR = 1?};
    AddrCheck -- No --> AddrCheck;
    AddrCheck -- Yes --> ReadAddr[Read ADDCODE and DIR in I2C_ISR
Optional: Set I2C_ISR.TXE = 1
Set I2C_ICR.ADDRCF]; ReadAddr --> TxisCheck{I2C_ISR.TXIS = 1?}; TxisCheck -- No --> TxisCheck; TxisCheck -- Yes --> WriteData[Write I2C_TXDR.TXDATA]; WriteData --> TxisCheck; subgraph SCL_Stretched [SCL stretched] AddrCheck ReadAddr TxisCheck end

The flowchart describes the process for target transmission when clock stretching is enabled (NOSTRETCH=0). It starts with Target transmission followed by Target initialization . The system waits for I2C_ISR.ADDR = 1 . Once detected, it reads ADDCODE and DIR , optionally sets I2C_ISR.TXE = 1 , and sets I2C_ICR.ADDRCF . Then, it enters a loop waiting for I2C_ISR.TXIS = 1 to Write I2C_TXDR.TXDATA . A vertical arrow indicates that SCL is stretched from the address match until the first data is written.

Figure 102. Transfer sequence flowchart for I2C target transmitter, NOSTRETCH=1

graph TD;
    Start([Target transmission]) --> Init[Target initialization];
    Init --> TxisCheck{I2C_ISR.TXIS = 1?};
    Init --> StopfCheck{I2C_ISR.STOPF = 1?};
    
    TxisCheck -- No --> TxisCheck;
    TxisCheck -- Yes --> WriteData[Write I2C_TXDR.TXDATA];
    WriteData --> TxisCheck;
    
    StopfCheck -- No --> StopfCheck;
    StopfCheck -- Yes --> OptSet[Optional: Set I2C_ISR.TXE = 1
and I2C_ISR.TXIS=1]; OptSet --> Stopcf[Set I2C_ICR.STOPCF];

The flowchart describes the process for target transmission when clock stretching is disabled (NOSTRETCH=1). After Target initialization , two parallel paths are followed. The left path handles data transmission by waiting for I2C_ISR.TXIS = 1 and then performing Write I2C_TXDR.TXDATA . The right path monitors for the stop condition: when I2C_ISR.STOPF = 1 , it optionally sets I2C_ISR.TXE = 1 and I2C_ISR.TXIS = 1 , then sets I2C_ICR.STOPCF .

Figure 103. Transfer bus diagram for I2C target transmitter

Flowchart for I2C target transmitter. It starts with 'Target reception' (oval), followed by 'Target initialization' (rectangle). A loop begins with a decision 'I2C_ISR.RXNE = 1?'. If 'Yes', it goes to 'Read I2C_RXDR.RXDATA' (rectangle) and loops back. If 'No', it goes to another decision 'I2C_ISR.STOPF = 1?'. If 'Yes', it goes to 'Set I2C_ICR.STOPCF' (rectangle) and loops back. If 'No', it loops back directly.
graph TD
    Start([Target reception]) --> Init[Target initialization]
    Init --> RXNE{I2C_ISR.RXNE = 1?}
    RXNE -- Yes --> Read[Read I2C_RXDR.RXDATA]
    Read --> RXNE
    RXNE -- No --> STOPF{I2C_ISR.STOPF = 1?}
    STOPF -- Yes --> StopCF[Set I2C_ICR.STOPCF]
    StopCF --> RXNE
    STOPF -- No --> RXNE
  
Flowchart for I2C target transmitter. It starts with 'Target reception' (oval), followed by 'Target initialization' (rectangle). A loop begins with a decision 'I2C_ISR.RXNE = 1?'. If 'Yes', it goes to 'Read I2C_RXDR.RXDATA' (rectangle) and loops back. If 'No', it goes to another decision 'I2C_ISR.STOPF = 1?'. If 'Yes', it goes to 'Set I2C_ICR.STOPCF' (rectangle) and loops back. If 'No', it loops back directly.

Target receiver

RXNE is set in I2C_ISR when the I2C_RXDR is full, and generates an interrupt if RXIE is set in I2C_CR1. RXNE is cleared when I2C_RXDR is read.

When a STOP is received and STOPIE is set in I2C_CR1, STOPF is set in I2C_ISR and an interrupt is generated.

Figure 104. Transfer sequence flowchart for target receiver with NOSTRETCH=0

Flowchart for I2C target receiver with NOSTRETCH=0. It starts with 'Target reception' (oval), followed by 'Target initialization' (rectangle). A loop begins with a decision 'I2C_ISR.ADDR = 1?'. If 'Yes', it goes to 'Read ADDCODE and DIR in I2C_ISR' and 'Set I2C_ICR.ADDRCF' (rectangle). A vertical double-headed arrow labeled 'SCL stretched' is next to this block. After this, it goes to a decision 'I2C_ISR.RXNE = 1?'. If 'Yes', it goes to 'Write I2C_RXDR.RXDATA' (rectangle) and loops back to the 'I2C_ISR.RXNE = 1?' decision. If 'No', it loops back to the 'I2C_ISR.ADDR = 1?' decision.
graph TD
    Start([Target reception]) --> Init[Target initialization]
    Init --> ADDR{I2C_ISR.ADDR = 1?}
    ADDR -- Yes --> ReadAddr[Read ADDCODE and DIR in I2C_ISR
Set I2C_ICR.ADDRCF] ReadAddr --> RXNE{I2C_ISR.RXNE = 1?} RXNE -- Yes --> Write[Write I2C_RXDR.RXDATA] Write --> RXNE RXNE -- No --> ADDR
Flowchart for I2C target receiver with NOSTRETCH=0. It starts with 'Target reception' (oval), followed by 'Target initialization' (rectangle). A loop begins with a decision 'I2C_ISR.ADDR = 1?'. If 'Yes', it goes to 'Read ADDCODE and DIR in I2C_ISR' and 'Set I2C_ICR.ADDRCF' (rectangle). A vertical double-headed arrow labeled 'SCL stretched' is next to this block. After this, it goes to a decision 'I2C_ISR.RXNE = 1?'. If 'Yes', it goes to 'Write I2C_RXDR.RXDATA' (rectangle) and loops back to the 'I2C_ISR.RXNE = 1?' decision. If 'No', it loops back to the 'I2C_ISR.ADDR = 1?' decision.

Figure 105. Transfer sequence flowchart for target receiver with NOSTRETCH=1

Flowchart for target receiver with NOSTRETCH=1. It starts with 'Target reception' (oval), followed by 'Target initialization' (rectangle). A decision diamond 'I2C_ISR.RXNE = 1?' follows. If 'Yes', it goes to 'Read I2C_RXDR.RXDATA' (rectangle) and loops back to the decision. If 'No', it goes to another decision diamond 'I2C_ISR.STOPF = 1?'. If 'Yes', it goes to 'Set I2C_ICR.STOPCF' (rectangle). If 'No', it loops back to the 'I2C_ISR.RXNE = 1?' decision.
graph TD
    Start([Target reception]) --> Init[Target initialization]
    Init --> RXNE{I2C_ISR.RXNE = 1?}
    RXNE -- Yes --> Read[Read I2C_RXDR.RXDATA]
    Read --> RXNE
    RXNE -- No --> STOPF{I2C_ISR.STOPF = 1?}
    STOPF -- Yes --> Stop[Set I2C_ICR.STOPCF]
    STOPF -- No --> RXNE
  
Flowchart for target receiver with NOSTRETCH=1. It starts with 'Target reception' (oval), followed by 'Target initialization' (rectangle). A decision diamond 'I2C_ISR.RXNE = 1?' follows. If 'Yes', it goes to 'Read I2C_RXDR.RXDATA' (rectangle) and loops back to the decision. If 'No', it goes to another decision diamond 'I2C_ISR.STOPF = 1?'. If 'Yes', it goes to 'Set I2C_ICR.STOPCF' (rectangle). If 'No', it loops back to the 'I2C_ISR.RXNE = 1?' decision.

Figure 106. Transfer bus diagrams for I2C target receiver

Example I2C target receiver 3 bytes, NOSTRETCH=0:

Timing diagram for I2C target receiver, 3 bytes, NOSTRETCH=0. The top part shows the bus sequence: S (Start), Address (transmission), A (ACK), data1 (reception), A (ACK), data2 (reception), A (ACK), data3 (reception), A (ACK), and a blank reception block. Event markers EV1 (ADDR), EV2 (RXNE), EV3 (RXNE), and EV4 (RXNE) are shown. The bottom part shows the RXNE signal line with pulses corresponding to EV2, EV3, and EV4.

bus sequence: S Address A data1 A data2 A data3 A [ ]

events: EV1(ADDR) EV2(RXNE) EV3(RXNE) EV4(RXNE)

RXNE signal: [Pulse] [Pulse] [Pulse]

Timing diagram for I2C target receiver, 3 bytes, NOSTRETCH=0. The top part shows the bus sequence: S (Start), Address (transmission), A (ACK), data1 (reception), A (ACK), data2 (reception), A (ACK), data3 (reception), A (ACK), and a blank reception block. Event markers EV1 (ADDR), EV2 (RXNE), EV3 (RXNE), and EV4 (RXNE) are shown. The bottom part shows the RXNE signal line with pulses corresponding to EV2, EV3, and EV4.

legend:

Example I2C target receiver 3 bytes, NOSTRETCH=1:

Timing diagram for I2C target receiver, 3 bytes, NOSTRETCH=1. The top part shows the bus sequence: S (Start), Address (transmission), A (ACK), data1 (reception), data2 (reception), data3 (reception), A (ACK), and P (Stop). Event markers EV1 (RXNE), EV2 (RXNE), and EV3 (RXNE) are shown. The bottom part shows the RXNE signal line with pulses corresponding to EV1, EV2, and EV3.

bus sequence: S Address A data1 data2 data3 A P

events: EV1(RXNE) EV2(RXNE) EV3(RXNE)

RXNE signal: [Pulse] [Pulse] [Pulse]

Timing diagram for I2C target receiver, 3 bytes, NOSTRETCH=1. The top part shows the bus sequence: S (Start), Address (transmission), A (ACK), data1 (reception), data2 (reception), data3 (reception), A (ACK), and P (Stop). Event markers EV1 (RXNE), EV2 (RXNE), and EV3 (RXNE) are shown. The bottom part shows the RXNE signal line with pulses corresponding to EV1, EV2, and EV3.

legend:

21.4.8 I2C controller mode
I2C controller initialization

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

A clock synchronization mechanism is implemented in order to support multi-controller environment and target clock stretching.

In order to allow clock synchronization:

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

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

Consequently the controller clock period is:

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

The duration of \( t_{\text{SYNC1}} \) depends on these parameters:

The duration of \( t_{\text{SYNC2}} \) depends on these parameters:

Figure 107. Controller clock generation

Timing diagram for SCL controller clock generation. It shows the SCL signal transitioning from a released state to driven low, then to a high level. The high level duration is SCLH, and the low level duration is SCLL. The time from the start of the high level to the start of the low level is tSYNC1. The time from the start of the low level to the start of the next high level is tSYNC2. The SCLH counter starts when the high level is detected, and the SCLL counter starts when the low level is detected. Timing diagram for SCL controller clock synchronization. It shows a continuous SCL signal with multiple high (SCLH) and low (SCLL) periods. The controller's SCLH counter starts when a high level is detected, and the SCLL counter starts when a low level is detected. The diagram also shows instances where the signal is driven low by another device, causing the controller's SCLL counter to start prematurely. The controller releases the signal when the SCLL counter expires.

SCL controller clock generation

SCL controller clock synchronization

Timing diagram for SCL controller clock generation. It shows the SCL signal transitioning from a released state to driven low, then to a high level. The high level duration is SCLH, and the low level duration is SCLL. The time from the start of the high level to the start of the low level is tSYNC1. The time from the start of the low level to the start of the next high level is tSYNC2. The SCLH counter starts when the high level is detected, and the SCLL counter starts when the low level is detected. Timing diagram for SCL controller clock synchronization. It shows a continuous SCL signal with multiple high (SCLH) and low (SCLL) periods. The controller's SCLH counter starts when a high level is detected, and the SCLL counter starts when a low level is detected. The diagram also shows instances where the signal is driven low by another device, causing the controller's SCLL counter to start prematurely. The controller releases the signal when the SCLL counter expires.

Caution: In order to be I 2 C or SMBus compliant, the controller clock must respect the timings given below:

Table 88. I 2 C-SMBUS specification clock timings

SymbolParameterStandard-mode (Sm)Fast-mode (Fm)Fast-mode Plus (Fm+)SMBUSUnit
Min.Max.Min.Max.Min.Max.Min.Max.
f SCLSCL clock frequency1004001000100kHz
t HD:STAHold time (repeated) START condition4.0-0.6-0.26-4.0-µs
t SU:STASet-up time for a repeated START condition4.7-0.6-0.26-4.7-µs
t SU:STOSet-up time for STOP condition4.0-0.6-0.26-4.0-µs
t BUFBus free time between a STOP and START condition4.7-1.3-0.5-4.7-µs
t LOWLow period of the SCL clock4.7-1.3-0.5-4.7-µs
t HIGHPeriod of the SCL clock4.0-0.6-0.26-4.050µs
t rRise time of both SDA and SCL signals-1000-300-120-1000ns
t fFall time of both SDA and SCL signals-300-300-120-300ns

Note: SCLL is also used to generate the t BUF and t SU:STA timings.

SCLH is also used to generate the t HD:STA and t SU:STO timings.

Refer to Section 21.4.9: I2C_TIMINGR register configuration examples for examples of I2C_TIMINGR settings vs. I2CCLK frequency.

Controller communication initialization (address phase)

In order to initiate the communication, you must program the following parameters for the addressed target in the I2C_CR2 register:

You must then set the START bit in the I2C_CR2 register. Changing all the above bits is not allowed when START bit is set.

Then the controller automatically sends the START condition followed by the target address as soon as it detects that the bus is free (BUSY = 0) and after a delay of t BUF .

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 has been sent on the bus, whatever the received acknowledge value. The START bit is also reset by hardware if an arbitration loss occurs. If the I 2 C is addressed as a target (ADDR=1) while the START bit is set, the I 2 C 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 108. Controller initialization flowchart

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

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

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

Timing diagram for 10-bit address read access. The diagram shows two sequences. The first sequence, labeled 'Write', starts with a START bit (S) followed by '11110XX 0' (Target address 1st 7 bits + R/W bit), an Acknowledge (A), the 'Target address 2nd byte', another Acknowledge (A), and then DATA bytes with Acknowledge (A). A ReStart (Sr) follows. The second sequence, labeled 'Read', starts with '11110XX 1' (Target address 1st 7 bits + R/W bit), an Acknowledge (A), DATA bytes with Acknowledge (A), a Not Acknowledge (A-bar), and a Stop (P) bit.
Timing diagram for 10-bit address read access. The diagram shows two sequences. The first sequence, labeled 'Write', starts with a START bit (S) followed by '11110XX 0' (Target address 1st 7 bits + R/W bit), an Acknowledge (A), the 'Target address 2nd byte', another Acknowledge (A), and then DATA bytes with Acknowledge (A). A ReStart (Sr) follows. The second sequence, labeled 'Read', starts with '11110XX 1' (Target address 1st 7 bits + R/W bit), an Acknowledge (A), DATA bytes with Acknowledge (A), a Not Acknowledge (A-bar), and a Stop (P) bit.

Controller transmitter

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

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

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

The TXIS flag is not set when a NACK is received.

Figure 110. Transfer sequence flowchart for I2C controller transmitter for N 255 bytes

Flowchart for I2C controller transmitter. It starts with 'Controller transmission' (oval), followed by 'Controller initialization' (rectangle), and then a configuration block: 'NBYTES = N, AUTOEND = 0 for RESTART; 1 for STOP, Configure target address, Set I2C_CR2.START'. A loop begins with a decision 'I2C_ISR.TXIS = 1?'. If 'No', it goes to 'I2C_ISR.NACKF = 1?'. If 'Yes', it goes to 'Write I2C_TXDR'. From 'Write I2C_TXDR', it goes to 'NBYTES transmitted?'. If 'No', it loops back to the start of the loop. If 'Yes', it goes to 'I2C_ISR.TC = 1?'. If 'Yes', it goes to 'Set I2C_CR2.START with target address NBYTES ...'. If 'No', it goes to 'End'. Both 'Set I2C_CR2.START...' and 'End' lead to a dashed line indicating continuation.
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 --> LoopStart(( )) LoopStart --> TXIS{I2C_ISR.TXIS = 1?} TXIS -- No --> NACKF{I2C_ISR.NACKF = 1?} NACKF -- Yes --> End1([End]) NACKF -- No --> LoopStart TXIS -- Yes --> Write[Write I2C_TXDR] Write --> Transmitted{NBYTES transmitted?} Transmitted -- No --> LoopStart Transmitted -- Yes --> TC{I2C_ISR.TC = 1?} TC -- Yes --> SetStart["Set I2C_CR2.START with
target address NBYTES ..."] TC -- No --> End2([End]) SetStart -.-> DashedLine[⋮] End2 -.-> DashedLine
Flowchart for I2C controller transmitter. It starts with 'Controller transmission' (oval), followed by 'Controller initialization' (rectangle), and then a configuration block: 'NBYTES = N, AUTOEND = 0 for RESTART; 1 for STOP, Configure target address, Set I2C_CR2.START'. A loop begins with a decision 'I2C_ISR.TXIS = 1?'. If 'No', it goes to 'I2C_ISR.NACKF = 1?'. If 'Yes', it goes to 'Write I2C_TXDR'. From 'Write I2C_TXDR', it goes to 'NBYTES transmitted?'. If 'No', it loops back to the start of the loop. If 'Yes', it goes to 'I2C_ISR.TC = 1?'. If 'Yes', it goes to 'Set I2C_CR2.START with target address NBYTES ...'. If 'No', it goes to 'End'. Both 'Set I2C_CR2.START...' and 'End' lead to a dashed line indicating continuation.

Figure 111. Transfer sequence flowchart for I2C controller transmitter for N>255 bytes

Flowchart for I2C controller transmitter for N>255 bytes. The process starts with 'Controller Transmission' (oval), followed by 'Controller initialization' (rectangle). Then, a configuration block sets NBYTES = 0xFF, N = N-255, RELOAD = 1, configures the target address, and sets I2C_CR2.START. A loop begins with two parallel decision diamonds: 'I2C_ISR.NACKF = 1?' and 'I2C_ISR.TXIS = 1?'. If NACKF is yes, it ends. If TXIS is yes, it writes to I2C_TXDR. A 'NBYTES transmitted?' decision follows. If no, it loops back to the start of the loop. If yes, it checks 'I2C_ISR.TC = 1?'. If no, it checks 'I2C_ISR.TCR = 1?'. If TCR is yes, it enters a block with IF/ELSE logic for N < 256 or not. Finally, it calls 'Set I2C_CCR.START' and ends.
graph TD
    Start([Controller Transmission]) --> Init[Controller initialization]
    Init --> Config["NBYTES = 0xFF; N=N-255
RELOAD = 1
Configure target address
Set I2C_CR2.START"] Config --> LoopStart(( )) LoopStart --> NACKF{I2C_ISR.NACKF
= 1?} LoopStart --> TXIS{I2C_ISR.TXIS
= 1?} NACKF -- Yes --> End1([End]) NACKF -- No --> LoopStart TXIS -- Yes --> Write[Write I2C_TXDR] TXIS -- No --> LoopStart Write --> Transmitted{NBYTES
transmitted?} Transmitted -- Yes --> TC{I2C_ISR.TC
= 1?} Transmitted -- No --> LoopStart TC -- Yes --> CCR[Set I2C_CCR.START
with target address
NBYTES..] TC -- No --> TCR{I2C_ISR.TCR
= 1?} TCR -- Yes --> Logic["IF N < 256
NBYTES = N; N = 0; RELOAD = 0
AUTOEND = 0 for RESTART; 1 for STOP
ELSE
NBYTES = 0xFF; N = N-255
RELOAD = 1"] TCR -- No --> LoopStart CCR -.-> End2([End]) Logic --> End2
Flowchart for I2C controller transmitter for N>255 bytes. The process starts with 'Controller Transmission' (oval), followed by 'Controller initialization' (rectangle). Then, a configuration block sets NBYTES = 0xFF, N = N-255, RELOAD = 1, configures the target address, and sets I2C_CR2.START. A loop begins with two parallel decision diamonds: 'I2C_ISR.NACKF = 1?' and 'I2C_ISR.TXIS = 1?'. If NACKF is yes, it ends. If TXIS is yes, it writes to I2C_TXDR. A 'NBYTES transmitted?' decision follows. If no, it loops back to the start of the loop. If yes, it checks 'I2C_ISR.TC = 1?'. If no, it checks 'I2C_ISR.TCR = 1?'. If TCR is yes, it enters a block with IF/ELSE logic for N < 256 or not. Finally, it calls 'Set I2C_CCR.START' and ends.

Figure 112. Transfer bus diagrams for I2C controller transmitter

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

Timing diagram for I2C controller transmitter in automatic end mode (STOP). The diagram shows a sequence of events: INIT (Start condition S, Address), EV1 (TXIS ISR: write data1), EV2 (TXIS ISR: write data2), and P (Stop condition). The bus state is shown as TXE (transmit enable) and NBYES (number of bytes to be transmitted) registers. The legend indicates transmission (white), reception (green), and SCL stretch (blue line).

The diagram illustrates the transfer bus for an I2C controller transmitter in automatic end mode (STOP). The sequence of events is as follows:

The TXE register is shown as a high level, indicating the transmit enable. The NBYES register is shown as 'xx' followed by '2', indicating the number of bytes to be transmitted. The legend indicates transmission (white), reception (green), and SCL stretch (blue line).

Timing diagram for I2C controller transmitter in automatic end mode (STOP). The diagram shows a sequence of events: INIT (Start condition S, Address), EV1 (TXIS ISR: write data1), EV2 (TXIS ISR: write data2), and P (Stop condition). The bus state is shown as TXE (transmit enable) and NBYES (number of bytes to be transmitted) registers. The legend indicates transmission (white), reception (green), and SCL stretch (blue line).

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

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

Timing diagram for I2C controller transmitter in software end mode (RESTART). The diagram shows a sequence of events: INIT (Start condition S, Address), EV1 (TXIS ISR: write data1), EV2 (TXIS ISR: write data2), EV3 (TC ISR: program target address, program NBBYTES = N, set START), and Res (Restart condition). The bus state is shown as TXE (transmit enable) and NBYES (number of bytes to be transmitted) registers. The legend indicates transmission (white), reception (green), and SCL stretch (blue line).

The diagram illustrates the transfer bus for an I2C controller transmitter in software end mode (RESTART). The sequence of events is as follows:

The TXE register is shown as a high level, indicating the transmit enable. The NBYES register is shown as 'xx' followed by '2', indicating the number of bytes to be transmitted. The legend indicates transmission (white), reception (green), and SCL stretch (blue line).

Timing diagram for I2C controller transmitter in software end mode (RESTART). The diagram shows a sequence of events: INIT (Start condition S, Address), EV1 (TXIS ISR: write data1), EV2 (TXIS ISR: write data2), EV3 (TC ISR: program target address, program NBBYTES = N, set START), and Res (Restart condition). The bus state is shown as TXE (transmit enable) and NBYES (number of bytes to be transmitted) registers. The legend indicates transmission (white), reception (green), and SCL stretch (blue line).

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

Controller receiver

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

If the total number of data bytes to be received is greater than 255, reload mode must be selected by setting the RELOAD bit in the I2C_CR2 register. In this case, when NBBYTES[7:0] data have been transferred, the TCR flag is set and the SCL line is stretched low until NBBYTES[7:0] is written to a non-zero value.

Figure 113. Transfer sequence flowchart for I 2 C controller receiver for 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 a block to set NBYTES = N, configure target address, and set I2C_CR2.START. A loop begins with a decision 'I2C_ISR.RXNE = 1?'. If 'No', it loops back to the start of the loop. If 'Yes', it proceeds to 'Read I2C_RXDR'. Next is a decision 'NBYTES received?'. If 'No', it loops back to the start of the loop. If 'Yes', it proceeds to a decision 'I2C_ISR.TC = 1?'. If 'Yes', it proceeds to 'Set I2C_CR2.START with target address NBYTES...'. If 'No', it proceeds to 'End'. A dashed line indicates continuation from the 'Set I2C_CR2.START' block.
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 --> Received{NBYTES received?} Received -- No --> RXNE Received -- Yes --> TC{I2C_ISR.TC = 1?} TC -- Yes --> SetStart["Set I2C_CR2.START with
target address NBYTES..."] TC -- No --> End([End]) SetStart -.-> Dots[⋮]
Flowchart for I2C controller receiver transfer sequence for N > 255 bytes. The process starts with 'Controller reception', followed by 'Controller initialization', then a block to set NBYTES = N, configure target address, and set I2C_CR2.START. A loop begins with a decision 'I2C_ISR.RXNE = 1?'. If 'No', it loops back to the start of the loop. If 'Yes', it proceeds to 'Read I2C_RXDR'. Next is a decision 'NBYTES received?'. If 'No', it loops back to the start of the loop. If 'Yes', it proceeds to a decision 'I2C_ISR.TC = 1?'. If 'Yes', it proceeds to 'Set I2C_CR2.START with target address NBYTES...'. If 'No', it proceeds to 'End'. A dashed line indicates continuation from the 'Set I2C_CR2.START' block.

Figure 114. Transfer sequence flowchart for I 2 C controller receiver for N >255 bytes

Flowchart for I2C controller receiver for N >255 bytes. The process starts with 'Controller reception', followed by 'Controller initialization', then a block with 'NBYS = 0xFF; N=N-255', 'RELOAD =1', 'Configure target address', and 'Set I2C_CR2.START'. It then enters a loop: 'I2C_ISR.RXNE =1?' (No leads to 'NBYS received?'), 'Read I2C_RXDR', 'NBYS received?' (No leads to 'I2C_ISR.RXNE =1?'). If 'NBYS received?' is Yes, it checks 'I2C_ISR.TC = 1?'. If Yes, it goes to 'Set I2C_CR2.START with target address NBYS ...'. If No, it checks 'I2C_ISR.TCR = 1?'. If Yes, it goes to a block with 'IF N < 256', 'NBYS = N; N=0; RELOAD=0', 'AUTOEND=0 for RESTART; 1 for STOP', 'ELSE', 'NBYS = 0xFF; N=N-255', 'RELOAD=1'. Both 'Set I2C_CR2.START...' and the 'IF N < 256' block lead to 'End'.
graph TD
    Start([Controller reception]) --> Init[Controller initialization]
    Init --> Setup["NBYS = 0xFF; N=N-255
RELOAD =1
Configure target address
Set I2C_CR2.START"] Setup --> RXNE{"I2C_ISR.RXNE =1?"} RXNE -- No --> NBYS_RECV{"NBYS received?"} RXNE -- Yes --> ReadRXDR[Read I2C_RXDR] ReadRXDR --> NBYS_RECV NBYS_RECV -- No --> RXNE NBYS_RECV -- Yes --> TC{"I2C_ISR.TC = 1?"} TC -- Yes --> SetStart["Set I2C_CR2.START with
target address NBYS ..."] TC -- No --> TCR{"I2C_ISR.TCR = 1?"} TCR -- Yes --> EndCond["IF N < 256
NBYS = N; N=0; RELOAD=0
AUTOEND=0 for RESTART; 1 for STOP
ELSE
NBYS = 0xFF; N=N-255
RELOAD=1"] SetStart --> End([End]) EndCond --> End
Flowchart for I2C controller receiver for N >255 bytes. The process starts with 'Controller reception', followed by 'Controller initialization', then a block with 'NBYS = 0xFF; N=N-255', 'RELOAD =1', 'Configure target address', and 'Set I2C_CR2.START'. It then enters a loop: 'I2C_ISR.RXNE =1?' (No leads to 'NBYS received?'), 'Read I2C_RXDR', 'NBYS received?' (No leads to 'I2C_ISR.RXNE =1?'). If 'NBYS received?' is Yes, it checks 'I2C_ISR.TC = 1?'. If Yes, it goes to 'Set I2C_CR2.START with target address NBYS ...'. If No, it checks 'I2C_ISR.TCR = 1?'. If Yes, it goes to a block with 'IF N < 256', 'NBYS = N; N=0; RELOAD=0', 'AUTOEND=0 for RESTART; 1 for STOP', 'ELSE', 'NBYS = 0xFF; N=N-255', 'RELOAD=1'. Both 'Set I2C_CR2.START...' and the 'IF N < 256' block lead to 'End'.

Figure 115. Transfer bus diagrams for I 2 C controller receiver

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

Timing diagram for I2C controller receiver in automatic end mode (STOP). The sequence starts with INIT (S, Address), followed by reception of data1 (RXNE) and data2 (RXNE), ending with a Stop (P) condition. The NBBYTES register is set to 2.

The diagram shows the following sequence of events:

NBYTES register: xx | 2

legend:

Timing diagram for I2C controller receiver in automatic end mode (STOP). The sequence starts with INIT (S, Address), followed by reception of data1 (RXNE) and data2 (RXNE), ending with a Stop (P) condition. The NBBYTES register is set to 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)

Timing diagram for I2C controller receiver in software end mode (RESTART). The sequence starts with INIT (S, Address), followed by reception of data1 (RXNE) and data2 (RXNE), then a Not Acknowledge (NA) and a Restart (ReS) condition. The NBBYTES register is set to 2, and the TC flag is set at the NA condition.

The diagram shows the following sequence of events:

NBYTES register: xx | 2 | N

legend:

Timing diagram for I2C controller receiver in software end mode (RESTART). The sequence starts with INIT (S, Address), followed by reception of data1 (RXNE) and data2 (RXNE), then a Not Acknowledge (NA) and a Restart (ReS) condition. The NBBYTES register is set to 2, and the TC flag is set at the NA condition.

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

21.4.9 I2C_TIMINGR register configuration examples

The tables below provide examples of how to program the I2C_TIMINGR to obtain timings compliant with the I 2 C specifications.

Table 89. Examples of timings settings for \( f_{I2CCLK} = 16 \) MHz

ParameterStandard-mode (Sm)Fast-mode (Fm)Fast-mode Plus (Fm+)
10 kHz100 kHz400 kHz1000 kHz
PRESC3310
SCLL0xC70x130x90x4
\( t_{SCLL} \)\( 200 \times 250 \text{ ns} = 50 \text{ } \mu\text{s} \)\( 20 \times 250 \text{ ns} = 5.0 \text{ } \mu\text{s} \)\( 10 \times 125 \text{ ns} = 1250 \text{ ns} \)\( 5 \times 62.5 \text{ ns} = 312.5 \text{ ns} \)
SCLH0xC30xF0x30x2
\( t_{SCLH} \)\( 196 \times 250 \text{ ns} = 49 \text{ } \mu\text{s} \)\( 16 \times 250 \text{ ns} = 4.0 \text{ } \mu\text{s} \)\( 4 \times 125 \text{ ns} = 500 \text{ ns} \)\( 3 \times 62.5 \text{ ns} = 187.5 \text{ ns} \)
\( t_{SCL}^{(1)} \)\( \sim 100 \text{ } \mu\text{s}^{(2)} \)\( \sim 10 \text{ } \mu\text{s}^{(2)} \)\( \sim 2500 \text{ ns}^{(3)} \)\( \sim 1000 \text{ ns}^{(4)} \)
SDADEL0x20x20x20x0
\( t_{SDADEL} \)\( 2 \times 250 \text{ ns} = 500 \text{ ns} \)\( 2 \times 250 \text{ ns} = 500 \text{ ns} \)\( 2 \times 125 \text{ ns} = 250 \text{ ns} \)0 ns
SCLDEL0x40x40x30x2
\( t_{SCLDEL} \)\( 5 \times 250 \text{ ns} = 1250 \text{ ns} \)\( 5 \times 250 \text{ ns} = 1250 \text{ ns} \)\( 4 \times 125 \text{ ns} = 500 \text{ ns} \)\( 3 \times 62.5 \text{ ns} = 187.5 \text{ ns} \)
  1. 1. SCL period \( 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 f_{I2CCLK} = 250 \text{ ns} \) . Example with \( t_{SYNC1} + t_{SYNC2} = 1000 \text{ ns} \)
  3. 3. \( t_{SYNC1} + t_{SYNC2} \) minimum value is \( 4 \times f_{I2CCLK} = 250 \text{ ns} \) . Example with \( t_{SYNC1} + t_{SYNC2} = 750 \text{ ns} \)
  4. 4. \( t_{SYNC1} + t_{SYNC2} \) minimum value is \( 4 \times f_{I2CCLK} = 250 \text{ ns} \) . Example with \( t_{SYNC1} + t_{SYNC2} = 500 \text{ ns} \)

21.4.10 SMBus specific features

This section is relevant only when SMBus feature is supported. Refer to Section 21.3: I 2 C implementation .

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 I 2 C principles of operation. SMBus provides a control bus for system and power management related tasks.

This peripheral is compatible with the SMBUS specification rev 2.0 ( http://smbus.org ).

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

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

SMBUS is based on I 2 C specification rev 2.1.

Bus protocols

There are eleven possible command protocols for any given device. A device may use any or all of the eleven protocols to communicate. The protocols 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. These protocols should be implemented by the user software.

For more details of these protocols, refer to SMBus specification version 2.0 ( http://smbus.org ).

Address resolution protocol (ARP)

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

This peripheral supports the address resolution protocol (ARP). The SMBus Device Default Address (0b1100 001) is enabled by setting the SMBDEN bit in the I2C_CR1 register. The ARP commands should be implemented by the user software.

Arbitration is also performed in target mode for ARP support.

For more details of the SMBus Address Resolution Protocol, refer to SMBus specification version 2.0 ( 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 SBC bit in I2C_CR1 register. Refer to Section 21.4.13: SMBus target mode for more details.

Host Notify protocol

This peripheral supports the Host Notify protocol by setting the SMBHEN bit in the I2C_CR1 register. In this case the host 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 SMBus ALERT optional signal is supported. A target-only device can signal the host through the SMBALERT# pin 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(s) which pulled SMBALERT# low acknowledges the Alert Response Address.

When configured as a target device (SMBHEN=0), the SMBA pin is pulled low by setting the ALERTEN bit in the I2C_CR1 register. The Alert Response Address is enabled at the same time.

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

If the SMBus ALERT pin is not needed, the SMBA pin can be used as a standard GPIO if ALERTEN=0.

Packet error checking

A packet error checking mechanism has been introduced in the SMBus specification to improve reliability and communication robustness. 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^8 + x^2 + x + 1 \) CRC-8 polynomial on all the message bytes (including addresses and read/write bits).

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

Timeouts

This peripheral embeds hardware timers in order to be compliant with the 3 timeouts defined in SMBus specification version 2.0.

Table 90. SMBus timeout specifications

SymbolParameterLimitsUnit
Min.Max.
\( t_{TIMEOUT} \)Detect clock low timeout2535ms
\( t_{LOW:SEXT}^{(1)} \)Cumulative clock low extend time (target device)25ms
\( t_{LOW:MEXT}^{(2)} \)Cumulative clock low extend time (controller device)10ms
  1. \( t_{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_{LOW:SEXT} \) . Therefore, this parameter is measured with the target device as the sole target of a full-speed controller.
  2. \( t_{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_{LOW:MEXT} \) on a given byte. Therefore, this parameter is measured with a full speed target device as the sole target of the controller.

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

Timing diagram showing SMBCLK and SMBDAT signals. The diagram illustrates the timeout intervals t_LOW:SEXT and t_LOW:MEXT. t_LOW:SEXT is the time from the start of a transmission to the stop, measured when the clock signal (SMBCLK) is high. t_LOW:MEXT is the time from the start of a transmission to the stop, measured when the data signal (SMBDAT) is high. The diagram shows the signals transitioning between high and low states, with 'Start' and 'Stop' markers at the beginning and end. Acknowledge signals (ClkAck) are shown at the rising edges of the clock signal.
Timing diagram showing SMBCLK and SMBDAT signals. The diagram illustrates the timeout intervals t_LOW:SEXT and t_LOW:MEXT. t_LOW:SEXT is the time from the start of a transmission to the stop, measured when the clock signal (SMBCLK) is high. t_LOW:MEXT is the time from the start of a transmission to the stop, measured when the data signal (SMBDAT) is high. The diagram shows the signals transitioning between high and low states, with 'Start' and 'Stop' markers at the beginning and end. Acknowledge signals (ClkAck) are shown at the rising edges of the clock signal.

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} \) greater than \( t_{HIGH, MAX} \) . (Refer to Table 88. I 2 C-SMBUS specification clock timings).

This timing parameter covers the condition where a controller has been 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 peripheral supports a hardware bus idle detection.

21.4.11 SMBus initialization

This section is relevant only when SMBus feature is supported. Refer to Section 21.3: I 2 C implementation.

In addition to I 2 C initialization, some other specific initializations must be done in order to perform SMBus communication:

Received command and data acknowledge control (target mode)

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

Specific address (target mode)

The specific SMBus addresses should be enabled if needed.

Packet error checking

PEC calculation is enabled by setting the PECEN bit in the I2C_CR1 register. Then the PEC transfer is managed with the help of a hardware byte counter: NBBYTES[7:0] in the I2C_CR2 register. The PECEN bit must be configured before enabling the I 2 C.

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 NBBYTES-1 data have been transferred when 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 I 2 C is enabled.

Table 91. 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 in 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 version 2.0.

In order to enable the \( t_{\text{TIMEOUT}} \) check, the 12-bit TIMEOUTA[11:0] bits must be programmed with the timer reload value in order to check the \( t_{\text{TIMEOUT}} \) parameter. The TIDLE bit must be configured to '0' in order to detect the SCL low level timeout.

Then the timer is enabled by setting the TIMOUTEN in the I2C_TIMEOUTR register.

If SCL is tied low for a time greater than \( (\text{TIMEOUTA}+1) \times 2048 \times t_{\text{I2CCLK}} \) , the TIMEOUT flag is set in the I2C_ISR register.

Refer to Table 92. Examples of TIMEOUTA settings (max. \( t_{\text{TIMEOUT}} = 25 \text{ ms} \) ).

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

Depending on whether the peripheral is configured as a controller or as a target, the 12-bit TIMEOUTB timer must be configured in order to check \( t_{\text{LOW:SEXT}} \) for a target and \( t_{\text{LOW:MEXT}} \) for a controller. As the standard specifies only a maximum, you can choose the same value for both.

Then the timer is enabled by setting the TEXTEN bit in the I2C_TIMEOUTR register.

If the SMBus peripheral performs a cumulative SCL stretch for a time greater than \( (\text{TIMEOUTB}+1) \times 2048 \times t_{\text{I2CCLK}} \) , the timeout interval, the TIMEOUT flag is set in the I2C_ISR register.

Refer to Table 93. Example of TIMEOUTB settings.

Caution: Changing the TIMEOUTB configuration is not allowed when the TEXTEN bit is set.

Bus idle detection

In order to enable the \( t_{\text{IDLE}} \) check, the 12-bit TIMEOUTA[11:0] field must be programmed with the timer reload value in order to obtain the \( t_{\text{IDLE}} \) parameter. The TIDLE bit must be configured to '1' in order to detect both SCL and SDA high level timeout.

Then the timer is enabled by setting the TIMOUTEN bit in the I2C_TIMEOUTR register.

If both the SCL and SDA lines remain high for a time greater than \( (\text{TIMEOUTA}+1) \times 4 \times t_{\text{I2CCLK}} \) , the TIMEOUT flag is set in the I2C_ISR register.

Refer to Table 94. Examples of TIMEOUTA settings (max. \( t_{\text{IDLE}} = 50 \text{ } \mu\text{s} \) ).

Caution: Changing the TIMEOUTA and TIDLE configuration is not allowed when the TIMOUTEN is set.

21.4.12 SMBus: I2C_TIMEOUTR register configuration examples

This section is relevant only when SMBus feature is supported. Refer to Section 21.3: I 2 C implementation .

Table 92. Examples of TIMEOUTA settings (max. \( t_{TIMEOUT} \) = 25 ms)

\( f_{I2CCLK} \)TIMEOUTA[11:0]bitsTIDLE bitTIMEOUTEN bit\( t_{TIMEOUT} \)
16 MHz0xC301\( 196 \times 2048 \times 62.5 \text{ ns} = 25 \text{ ms} \)

Table 93. Example of TIMEOUTB settings

\( f_{I2CCLK} \)TIMEOUTB[11:0]bitsTEXTEN bit\( t_{LOW:EXT} \)
16 MHz0x3F0\( 64 \times 2048 \times 62.5 \text{ ns} = 8 \text{ ms} \)

Table 94. Examples of TIMEOUTA settings (max. \( t_{IDLE} \) = 50 \( \mu\text{s} \) )

\( f_{I2CCLK} \)TIMEOUTA[11:0]bitsTIDLE bitTIMEOUTEN bit\( t_{IDLE} \)
16 MHz0xC701\( 200 \times 4 \times 62.5 \text{ ns} = 50 \mu\text{s} \)

21.4.13 SMBus target mode

This section is relevant only when SMBus feature is supported. Refer to Section 21.3: I 2 C implementation .

In addition to I 2 C target transfer management (refer to Section 21.4.7: I 2 C target mode ) some additional software flowcharts are provided to support SMBus.

SMBus target transmitter

When the IP is used in SMBus, SBC must be programmed to '1' in order to allow 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 NBBYTES[7:0] includes the PEC transmission. In that case the total number of TXIS interrupts is NBBYTES-1 and the content of the I2C_PECR register is automatically transmitted if the controller requests an extra byte after the NBBYTES-1 data transfer.

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

Figure 117. Transfer sequence flowchart for SMBus target transmitter N bytes + PEC

Flowchart for SMBus target transmitter N bytes + PEC. The process starts with 'SMBus target transmission', followed by 'Target initialization'. A loop exists if I2C_ISR.ADDR is not 1. Once ADDR is 1, it reads ADDCODE and DIR, sets I2C_CR2.NBYTES = N + 1, PECBYTE=1, and sets I2C_ICR.ADDRCF. Then it checks I2C_ISR.TXIS. If not 1, it loops back. If 1, it writes I2C_TXDR.TXDATA and loops back. A vertical double-headed arrow on the right indicates 'SCL stretched' during the TXIS loop.
graph TD
    Start([SMBus target transmission]) --> Init[Target initialization]
    Init --> ADDR{I2C_ISR.ADDR = 1?}
    ADDR -- No --> ADDR
    ADDR -- Yes --> Config[Read ADDCODE and DIR in I2C_ISR
I2C_CR2.NBYTES = N + 1
PECBYTE=1
Set I2C_ICR.ADDRCF] Config --> TXIS{I2C_ISR.TXIS = 1?} TXIS -- No --> TXIS TXIS -- Yes --> Write[Write I2C_TXDR.TXDATA] Write --> TXIS style ADDR fill:none,stroke:none style TXIS fill:none,stroke:none
Flowchart for SMBus target transmitter N bytes + PEC. The process starts with 'SMBus target transmission', followed by 'Target initialization'. A loop exists if I2C_ISR.ADDR is not 1. Once ADDR is 1, it reads ADDCODE and DIR, sets I2C_CR2.NBYTES = N + 1, PECBYTE=1, and sets I2C_ICR.ADDRCF. Then it checks I2C_ISR.TXIS. If not 1, it loops back. If 1, it writes I2C_TXDR.TXDATA and loops back. A vertical double-headed arrow on the right indicates 'SCL stretched' during the TXIS loop.

Figure 118. Transfer bus diagrams for SMBus target transmitter (SBC=1)

Example SMBus target transmitter 2 bytes + PEC,

Bus diagram for SMBus target transmitter with 2 data bytes and PEC. The sequence is: S (Start), Address, A (ACK), data1, A (ACK), data2, A (ACK), PEC, NA (NACK), P (Stop). Arrows labeled ADDR, TXIS, and TXIS point to the Address, data1, and data2 bytes respectively. EV1 points to the Address byte, EV2 to data1, and EV3 to data2. A legend indicates transmission (white), reception (green), and SCL stretch (blue line). Below the diagram, NBYTES is shown as 3 (2 data bytes + 1 PEC byte).

Legend:
transmission
reception
SCL stretch

Bus diagram for SMBus target transmitter with 2 data bytes and PEC. The sequence is: S (Start), Address, A (ACK), data1, A (ACK), data2, A (ACK), PEC, NA (NACK), P (Stop). Arrows labeled ADDR, TXIS, and TXIS point to the Address, data1, and data2 bytes respectively. EV1 points to the Address byte, EV2 to data1, and EV3 to data2. A legend indicates transmission (white), reception (green), and SCL stretch (blue line). Below the diagram, NBYTES is shown as 3 (2 data bytes + 1 PEC byte).

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

SMBus target receiver

When the I 2 C is used in SMBus mode, SBC must be programmed to '1' in order to allow the PEC checking at the end of the programmed number of data bytes. In order to allow the ACK control of each byte, the reload mode must be selected (RELOAD=1).

Refer to Section 21.4.7: I2C target mode "target bite control mode" for more details.

In order to check the PEC byte, the RELOAD bit must be cleared and the PECBYTE bit must be set. In this case, after NBBYTES-1 data have been received, 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.

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

If no ACK software control is needed, you can program PECBYTE=1 and, in the same write operation, program NBBYTES with the number of bytes to be received in a continuous flow. After NBBYTES-1 are received, the next received byte is checked as being the PEC.

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

Figure 119. Transfer sequence flowchart for SMBus target receiver N bytes + PEC

Flowchart for SMBus target receiver N bytes + PEC. The process starts with 'SMBus target reception', followed by 'Target initialization'. A loop begins with a decision 'I2C_ISR.ADDR = 1?'. If 'No', it loops back to 'Target initialization'. If 'Yes', it proceeds to 'Read ADDCODE and DIR in I2C_ISR', 'I2C_CR2.NBYTES = 1, RELOAD = 1', 'PECBYTE = 1', and 'Set I2C_ICR.ADDRCF'. A vertical double-headed arrow labeled 'SCL stretched' is next to this block. The next decision is 'I2C_ISR.RXNE = 1? / I2C_ISR.TCR = 1?'. If 'No', it loops back to the entry point of the loop. If 'Yes', it proceeds to 'Read I2C_RXDR.RXDATA', 'Program I2C_CR2.NACK = 0', 'I2C_CR2.NBYTES = 1', and 'N = N - 1'. The next decision is 'N = 1?'. If 'No', it loops back to the entry point. If 'Yes', it proceeds to 'Read I2C_RXDR.RXDATA', 'Program RELOAD = 0', and 'NACK = 0 and NBBYTES = 1'. The next decision is 'I2C_ISR.RXNE = 1?'. If 'No', it loops back to the entry point. If 'Yes', it proceeds to 'Read I2C_RXDR.RXDATA' and finally 'End'.
graph TD
    Start([SMBus target reception]) --> Init[Target initialization]
    Init --> Addr{I2C_ISR.ADDR = 1?}
    Addr -- No --> Init
    Addr -- Yes --> ReadAddr[Read ADDCODE and DIR in I2C_ISR
I2C_CR2.NBYTES = 1, RELOAD = 1
PECBYTE = 1
Set I2C_ICR.ADDRCF] ReadAddr --> Rxne{I2C_ISR.RXNE = 1?
I2C_ISR.TCR = 1?} Rxne -- No --> ReadAddr Rxne -- Yes --> ReadData1[Read I2C_RXDR.RXDATA
Program I2C_CR2.NACK = 0
I2C_CR2.NBYTES = 1
N = N - 1] ReadData1 --> N1{N = 1?} N1 -- No --> ReadAddr N1 -- Yes --> ReadData2[Read I2C_RXDR.RXDATA
Program RELOAD = 0
NACK = 0 and NBBYTES = 1] ReadData2 --> Rxne2{I2C_ISR.RXNE = 1?} Rxne2 -- No --> ReadData2 Rxne2 -- Yes --> ReadData3[Read I2C_RXDR.RXDATA] ReadData3 --> End([End])
Flowchart for SMBus target receiver N bytes + PEC. The process starts with 'SMBus target reception', followed by 'Target initialization'. A loop begins with a decision 'I2C_ISR.ADDR = 1?'. If 'No', it loops back to 'Target initialization'. If 'Yes', it proceeds to 'Read ADDCODE and DIR in I2C_ISR', 'I2C_CR2.NBYTES = 1, RELOAD = 1', 'PECBYTE = 1', and 'Set I2C_ICR.ADDRCF'. A vertical double-headed arrow labeled 'SCL stretched' is next to this block. The next decision is 'I2C_ISR.RXNE = 1? / I2C_ISR.TCR = 1?'. If 'No', it loops back to the entry point of the loop. If 'Yes', it proceeds to 'Read I2C_RXDR.RXDATA', 'Program I2C_CR2.NACK = 0', 'I2C_CR2.NBYTES = 1', and 'N = N - 1'. The next decision is 'N = 1?'. If 'No', it loops back to the entry point. If 'Yes', it proceeds to 'Read I2C_RXDR.RXDATA', 'Program RELOAD = 0', and 'NACK = 0 and NBBYTES = 1'. The next decision is 'I2C_ISR.RXNE = 1?'. If 'No', it loops back to the entry point. If 'Yes', it proceeds to 'Read I2C_RXDR.RXDATA' and finally 'End'.

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

Timing diagram for SMBus target receiver with 2 bytes and PEC. The sequence is: Start (S), Address (green), ACK (white), data1 (green), ACK (white), data2 (green), ACK (white), PEC (green), ACK (white), Stop (P). Event markers EV1, EV2, EV3, and EV4 are aligned with the ACKs. NBYTES is shown as 3. A legend indicates white boxes for transmission, green boxes for reception, and a blue line for SCL stretch.

Example SMBus target receiver 2 bytes + PEC

legend:

transmission

reception

SCL stretch

Timing diagram for SMBus target receiver with 2 bytes and PEC. The sequence is: Start (S), Address (green), ACK (white), data1 (green), ACK (white), data2 (green), ACK (white), PEC (green), ACK (white), Stop (P). Event markers EV1, EV2, EV3, and EV4 are aligned with the ACKs. NBYTES is shown as 3. A legend indicates white boxes for transmission, green boxes for reception, and a blue line for 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

Timing diagram for SMBus target receiver with 2 bytes, PEC, and ACK control. The sequence is: Start (S), Address (green), ACK (white), data1 (green), ACK (white), data2 (green), ACK (white), PEC (green), ACK (white), Stop (P). Event markers EV1, EV2, EV3, and EV4 are shown. SCL stretching occurs before each ACK. NBYTES starts at 1. Legend is identical to the previous diagram.

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

legend :

transmission

reception

SCL stretch

Timing diagram for SMBus target receiver with 2 bytes, PEC, and ACK control. The sequence is: Start (S), Address (green), ACK (white), data1 (green), ACK (white), data2 (green), ACK (white), PEC (green), ACK (white), Stop (P). Event markers EV1, EV2, EV3, and EV4 are shown. SCL stretching occurs before each ACK. NBYTES starts at 1. Legend is identical to the previous diagram.

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

This section is relevant only when SMBus feature is supported. Refer to Section 21.3: I 2 C implementation .

In addition to I 2 C controller transfer management (refer to Section 21.4.8: I2C controller mode ) some additional software flowcharts are provided 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 programmed in the NBYTES[7:0] field, before setting the START bit. In this case the total number of TXIS interrupts is NBYTES-1. So if the PECBYTE bit is set when NBYTES=0x1, the content of the I2C_PECR register is automatically transmitted.

If the SMBus controller wants to send a STOP condition after the PEC, automatic end mode should 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, software mode must be selected (AUTOEND=0). In this case, once NBYTES-1 have been transmitted, the I2C_PECR register content is transmitted and 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 121. Bus transfer diagrams for SMBus controller transmitter

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

Timing diagram for SMBus transmitter in automatic end mode (STOP). The diagram shows a sequence of bytes: S (Start), Address (green), A (Acknowledge), data1 (green), A, data2 (green), A, PEC (green), A, P (Stop). Events are marked: INIT at the start, EV1 (TXIS ISR: wr data1) after Address, EV2 (TXIS ISR: wr data2) after data1. The TXE line is shown with a pulse. The NBYTES register is set to 3. A legend indicates transmission (white), reception (green), and SCL stretch (blue line).
Timing diagram for SMBus transmitter in automatic end mode (STOP). The diagram shows a sequence of bytes: S (Start), Address (green), A (Acknowledge), data1 (green), A, data2 (green), A, PEC (green), A, P (Stop). Events are marked: INIT at the start, EV1 (TXIS ISR: wr data1) after Address, EV2 (TXIS ISR: wr data2) after data1. The TXE line is shown with a pulse. The NBYTES register is set to 3. A legend indicates transmission (white), reception (green), and SCL stretch (blue line).

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)

Timing diagram for SMBus transmitter in software end mode (RESTART). The diagram shows a sequence of bytes: S (Start), Address (green), A, data1 (green), A, data2 (green), A, PEC (green), A, TC (Transfer Complete), Rstart|Address (green), ... . Events are marked: INIT at the start, EV1 (TXIS ISR: wr data1) after Address, EV2 (TXIS ISR: wr data2) after data1, EV3 (TC ISR) after PEC. The TXE line is shown with a pulse. The NBYTES register is shown with 'xx' then '3' then 'N'. A legend indicates transmission (white), reception (green), and SCL stretch (blue line).
Timing diagram for SMBus transmitter in software end mode (RESTART). The diagram shows a sequence of bytes: S (Start), Address (green), A, data1 (green), A, data2 (green), A, PEC (green), A, TC (Transfer Complete), Rstart|Address (green), ... . Events are marked: INIT at the start, EV1 (TXIS ISR: wr data1) after Address, EV2 (TXIS ISR: wr data2) after data1, EV3 (TC ISR) after PEC. The TXE line is shown with a pulse. The NBYTES register is shown with 'xx' then '3' then 'N'. A legend indicates transmission (white), reception (green), and SCL stretch (blue line).

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

SMBus controller receiver

When the SMBus controller wants to receive the PEC followed by a STOP at the end of the transfer, automatic end mode can be selected (AUTOEND=1). The PECBYTE bit must be set and the target address must be programmed, before setting the START bit. In this case, after NBYTES-1 data have been received, 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 the PEC byte followed by a RESTART condition at the end of the transfer, software mode must be selected (AUTOEND=0). The PECBYTE bit must be set and the target address must be programmed, before setting the START bit. In this case, after NBYTES-1 data have been received, 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 122. Bus transfer diagrams for SMBus controller receiver

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

Timing diagram for SMBus controller receiver in automatic end mode (STOP). The sequence starts with INIT (S, Address, A), followed by data1 (RXNE), data2 (RXNE), PEC (RXNE), NA, and P. The NBYTES register is set to 3. The legend indicates transmission (white), reception (green), and SCL stretch (blue line).

The diagram shows a sequence of events: INIT (S, Address, A), data1 (RXNE), data2 (RXNE), PEC (RXNE), NA, and P. The NBYTES register is set to 3. The legend indicates transmission (white), reception (green), and SCL stretch (blue line).

Timing diagram for SMBus controller receiver in automatic end mode (STOP). The sequence starts with INIT (S, Address, A), followed by data1 (RXNE), data2 (RXNE), PEC (RXNE), NA, and P. The NBYTES register is set to 3. The legend indicates transmission (white), reception (green), and SCL stretch (blue line).

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)

Timing diagram for SMBus controller receiver in software end mode (RESTART). The sequence starts with INIT (S, Address, A), followed by data1 (RXNE), data2 (RXNE), PEC (RXNE), NA (TC), and Restart Address. The NBYTES register is set to 3. The legend indicates transmission (white), reception (green), and SCL stretch (blue line).

The diagram shows a sequence of events: INIT (S, Address, A), data1 (RXNE), data2 (RXNE), PEC (RXNE), NA (TC), and Restart Address. The NBYTES register is set to 3. The legend indicates transmission (white), reception (green), and SCL stretch (blue line).

Timing diagram for SMBus controller receiver in software end mode (RESTART). The sequence starts with INIT (S, Address, A), followed by data1 (RXNE), data2 (RXNE), PEC (RXNE), NA (TC), and Restart Address. The NBYTES register is set to 3. The legend indicates transmission (white), reception (green), and SCL stretch (blue line).

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

21.4.14 Error conditions

The following are error conditions which may cause 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 9 SCL clock pulses. A START or a STOP condition is detected when an SDA edge occurs while SCL is high.

The bus error flag is set only if the I 2 C is involved in the transfer as controller or addressed target (i.e not during the address phase in target mode).

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

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

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.

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

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 is set in the I2C_ISR register, and an interrupt is generated if the ERRIE bit is set in the I2C_CR1 register.

Packet Error Checking Error (PECERR)

This section is relevant only when the SMBus feature is supported. Refer to Section 21.3: I 2 C implementation .

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

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

Timeout Error (TIMEOUT)

This section is relevant only when the SMBus feature is supported. Refer to Section 21.3: I 2 C implementation .

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, 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 is set in the I2C_CR1 register.

Alert (ALERT)

This section is relevant only when the SMBus feature is supported. Refer to Section 21.3: I 2 C implementation .

The ALERT flag is set when the I 2 C interface is configured as a host (SMBHEN=1), the alert pin detection is enabled (ALERTEN=1) and a falling edge is detected on the SMBA pin. An interrupt is generated if the ERRIE bit is set in the I2C_CR1 register.

21.4.15 DMA requests

Transmission using DMA

DMA (Direct Memory Access) can be enabled for transmission by setting the TXDMAEN bit in the I2C_CR1 register. Data is loaded from an SRAM area configured using the DMA peripheral (see DMA controller (DMA)) to the I2C_TXDR register whenever the TXIS bit is set.

Only the data are transferred with DMA.

Refer to Section 21.4.13: SMBus target mode "SMBus target transmitter" and "SMBus controller transmitter" for more details.

Note: If DMA is used for transmission, the TXIE bit does not need to be enabled.

Reception using DMA

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

Note: If DMA is used for reception, the RXIE bit does not need to be enabled.

21.5 I2C interrupts

The table below gives the list of I 2 C interrupt requests.

Table 95. I 2 C interrupt requests

Interrupt eventEvent flagEvent flag/interrupt clearing methodInterrupt enable control bit
Receive buffer not emptyRXNERead I2C_RXDR registerRXIE
Transmit buffer interrupt statusTXISWrite I2C_TXDR registerTXIE
Stop detection interrupt flagSTOPFWrite STOPCF=1STOPIE
Transfer complete reloadTCRWrite I2C_CR2 with NBYTES[7:0] 1 0TCIE
Transfer completeTCWrite START=1 or STOP=1
Address matchedADDRWrite ADDRCF=1ADDRIE
NACK receptionNACKFWrite NACKCF=1NACKIE
Bus errorBERRWrite BERRCF=1ERRIE
Arbitration lossARLOWrite ARLOCF=1
Overrun/underrunOVRWrite OVRCF=1
PEC errorPECERRWrite PECERRCF=1
Timeout/t LOW errorTIMEOUTWrite TIMEOUTCF=1
SMBus alertALERTWrite ALERTCF=1

Depending on the product implementation, all these interrupt events can either share the same interrupt vector (I 2 C global interrupt), or be grouped into 2 interrupt vectors ( I 2 C event interrupt and I 2 C error interrupt, see Section 2.3.2: Interrupts ). In order to enable the I 2 C interrupts, the following sequence is required:

Figure 123. I 2 C interrupt mapping diagram

I2C interrupt mapping diagram showing the logic for generating I2C event, error, and global interrupts from various status flags.

The diagram illustrates the logic for generating I 2 C interrupts based on various status flags. It is divided into three main sections:

I2C interrupt mapping diagram showing the logic for generating I2C event, error, and global interrupts from various status flags.

21.6 I2C registers

Refer to Section 1.5: Acronyms for a list of abbreviations used in register descriptions. The peripheral registers are accessed by words (32-bit).

21.6.1 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 to this register is on-going. 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 PCLK1 + 6 \times I2CCLK \) .

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.PECENALERT ENSMBD ENSMBH ENGCENRes.NOSTR ETCHSBC
rwrwrwrwrwrwrw
1514131211109876543210
RXDMA ENTXDMA ENRes.ANF OFFDNFERRIETCIESTOP IENACK IEADDR IERXIETXIEPE
rwrwrwrwrwrwrwrwrwrwrwrw
Bits 31:24Reserved, must be kept at reset value.
Bit 23

PECEN: PEC enable.

0: PEC calculation disabled
1: PEC calculation enabled

Note: If the SMBus feature is not supported, this bit is reserved and forced by hardware to '0'.

Refer to Section 21.3: I 2 C implementation .

Bit 22

ALERTEN: SMBus alert enable.

Device mode (SMBHEN=0):

0: Releases SMBA pin high and alert response Address Header disabled: 0001100x followed by NACK
1: Drives SMBA pin low and alert response address Header enables: 0001100x followed by ACK

Host mode (SMBHEN=1):

0: SMBus alert pin (SMBA) not supported
1: SMBus Alert pin (SMBA) supported

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

If the SMBus feature is not supported, this bit is reserved and forced by hardware to '0'. Refer to Section 21.3: I 2 C implementation .

Bit 21

SMBDEN: SMBus Device Default address enable.

0: Device default address disabled. Address 0b1100001x is NACKed.
1: Device default address enabled. Address 0b1100001x is ACKed.

Note: If the SMBus feature is not supported, this bit is reserved and forced by hardware to '0'.

Refer to Section 21.3: I 2 C implementation .

Bit 20

SMBHEN: SMBus Host address enable.

0: Host address disabled. Address 0b0001000x is NACKed.
1: Host address enabled. Address 0b0001000x is ACKed.

Note: If the SMBus feature is not supported, this bit is reserved and forced by hardware to '0'.

Refer to Section 21.3: I 2 C implementation .

Bit 19

GCEN: General call enable.

0: General call disabled. Address 0b00000000 is NACKed.

1: General call enabled. Address 0b00000000 is ACKed.
Bit 18Reserved, must be kept at reset value.
Bit 17NOSTRETCH: Clock stretching disable.
This bit is used to disable clock stretching in target mode. It must be kept cleared in controller mode.
0: Clock stretching enabled
1: Clock stretching disabled
Note: This bit can only be programmed when the I 2 C is disabled (PE = 0).
Bit 16SBC: Target byte control.
This bit is used to enable hardware byte control in target mode.
0: Target byte control disabled
1: Target byte control enabled
Bit 15RXDMAEN: DMA reception requests enable
0: DMA mode disabled for reception
1: DMA mode enabled for reception
Bit 14TXDMAEN: DMA transmission requests enable.
0: DMA mode disabled for transmission
1: DMA mode enabled for transmission
Bit 13Reserved, must be kept at reset value.
Bit 12ANFOFF: Analog noise filter OFF.
0: Analog noise filter enabled
1: Analog noise filter disabled
Note: This bit can only be programmed when the I 2 C is disabled (PE = 0).
Bits 11:8DNF[3:0]: Digital noise filter.
These bits are used to configure the digital noise filter on SDA and SCL input. The digital filter filters spikes with a length of up to DNF[3:0] * t I2CCLK .
0000: Digital filter disabled
0001: Digital filter enabled and filtering capability up to 1 t I2CCLK
...
1111: Digital filter enabled and filtering capability up to 15 t I2CCLK
Note: If the analog filter is also enabled, the digital filter is added to the analog filter.
This filter can only be programmed when the I 2 C is disabled (PE = 0).
Bit 7ERRIE: Error interrupts enable.
0: Error detection interrupts disabled
1: Error detection interrupts enabled
Note: Any of these errors generate an interrupt:
Arbitration Loss (ARLO).
Bus Error detection (BERR)
Overrun/Underrun (OVR)
Timeout detection (TIMEOUT)
PEC error detection (PECERR)
Alert pin event detection (ALERT)
Bit 6TCIE: Transfer complete interruptenable.
0: Transfer complete interrupt disabled
1: Transfer complete interrupt enabled
Note: Any of these events generate an interrupt:
0: transfer complete (TC)
1: transfer complete reload (TCR).
Bit 5STOPIE : STOP detection Interrupt enable.
0: Stop detection (STOPF) interrupt disabled
1: Stop detection (STOPF) interrupt enabled
Bit 4NACKIE : Not acknowledge received interrupt enable.
0: Not acknowledge (NACKF) received interrupts disabled
1: Not acknowledge (NACKF) received interrupts enabled
Bit 3ADDRIE : Address match interrupt enable (target only).
0: Address match (ADDR) interrupts disabled
1: Address match (ADDR) interrupts enabled
Bit 2RXIE : RX Interrupt enable.
0: Receive (RXNE) interrupt disabled
1: Receive (RXNE) interrupt enabled
Bit 1TXIE : TX interrupt enable.
0: Transmit (TXIS) interrupt disabled
1: Transmit (TXIS) interrupt enabled
Bit 0PE : Peripheral enable.
0: Peripheral disable
1: Peripheral enable

Note: When PE=0, the I 2 C 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 3 APB clock cycles.

21.6.2 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 to this register is on-going. 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 PCLK1 + 6 \times I2CCLK \) .

31302928272625242322212019181716
Res.Res.Res.Res.Res.PEC BYTEAUTO ENDRE LOADNBBYTES[7:0]
rsrwrwrw
1514131211109876543210
NACKSTOPSTARTHEAD 10RADD10RD_W RNSADD[9:0]
rsrsrsrwrwrwrw
Bits 31:27Reserved, 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.

0: No PEC transfer

1: PEC transmission/reception is requested

Note: Writing '0' to this bit has no effect.

This bit has no effect when RELOAD is set.

This bit has no effect in target mode when SBC=0.

If the SMBus feature is not supported, this bit is reserved and forced by hardware to '0'. Refer to Section 21.3: I 2 C implementation .

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 NBBYTES data are transferred, stretching SCL low.

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

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

Bit 24

RELOAD : NBBYTES reload mode.

This bit is set and cleared by software.

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

1: The transfer is not completed after the NBBYTES data transfer (NBBYTES is reloaded). TCR flag is set when NBBYTES 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 have no effect 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 in target mode only: 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 generation (controller mode).

The bit is set by software, cleared by hardware when a Stop condition is detected, or when PE=0.

In controller Mode:

0: No stop generation

1: Stop generation after current byte transfer

Note: Writing '0' to this bit has no effect.

Bit 13

START: Start generation.

This bit is set by software, and cleared by hardware after the Start 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 writing '1' to the ADDRCF bit in the I2C_ICR register.

0: No start generation

1: Restart/start generation:

  • • If the I 2 C 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 I 2 C is in target mode. This bit has no effect when RELOAD is set.

Bit 12

HEAD10R: 10-bit address header only read direction (controller receiver mode).

0: The controller sends the complete 10 bit target address read sequence: start + 2 bytes 10-bit address in write direction + restart + 1 st 7 bits of the 10-bit address in read direction

1: The controller only sends the 1 st 7 bits of the 10-bit address, followed by Read direction

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

Bit 11

ADD10: 10-bit addressing mode (controller mode).

0: The controller operates in 7-bit addressing mode

1: The controller operates in 10-bit addressing mode

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

Bit 10

RD_WRN: Transfer direction (controller mode).

0: Controller requests a write transfer

1: Controller requests a read transfer

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

Bits 9:8

SADD[9:8]: Target address bit 9:8 (controller mode).

In 7-bit addressing mode (ADD10 = 0): These bits have no effect.

In 10-bit addressing mode (ADD10 = 1):

These bits should be written with bits 9:8 of the target address to be sent

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

Bits 7:1

SADD[7:1]: Target address bit 7:1 (controller mode).

In 7-bit addressing mode (ADD10 = 0):

These bits should be written with the 7-bit target address to be sent

In 10-bit addressing mode (ADD10 = 1):

These bits should be written with bits 7:1 of the target address to be sent

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

Bit 0

SADD0: Target address bit 0 (controller mode). In 7-bit addressing mode (ADD10 = 0): This bit is do not care

In 10-bit addressing mode (ADD10 = 1):

This bit should be written with bit 0 of the target address to be sent

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

21.6.3 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 to this register is on-going. 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 PCLK1 + 6 \times I2CCLK \) .

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
OA1ENRes.Res.Res.Res.OA1 MODEOA1[9:8]OA1[7:1]OA1[0]
r/wr/wr/wr/wr/w
Bits 31:16Reserved, must be kept at reset value.
Bit 15OA1EN: Own address 1 enable.
0: Own address 1 disabled. The received target address OA1 is NACKed.
1: Own address 1 enabled. The received target address OA1 is ACKed.
Bits 14:11Reserved, must be kept at reset value.
Bit 10OA1MODE 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:8OA1[9:8]: Interface address.
7-bit addressing mode: do not care
10-bit addressing mode: bits 9:8 of address
Note: These bits can be written only when OA1EN=0.
Bits 7:1OA1[7:1]: Interface address bits 7:1 of address.
Note: These bits can be written only when OA1EN=0.
Bit 0OA1[0]: Interface address.
7-bit addressing mode: do not care
10-bit addressing mode: bit 0 of address
Note: This bit can be written only when OA1EN=0.

21.6.4 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 to this register is on-going. 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 PCLK1 + 6 \times I2CCLK \) .

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.
rwrwrw
Bits 31:16Reserved, must be kept at reset value.
Bit 15OA2EN: 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:11Reserved, must be kept at reset value.
Bits 10:8OA2MSK[2:0]: Own Address 2 masks.
000: No mask
001: OA2[1] is masked and has no effect. Only OA2[7:2] are compared.
010: OA2[2:1] are masked and has no effect. Only OA2[7:3] are compared.
011: OA2[3:1] are masked and has no effect. Only OA2[7:4] are compared.
100: OA2[4:1] are masked and has no effect. Only OA2[7:5] are compared.
101: OA2[5:1] are masked and has no effect. Only OA2[7:6] are compared.
110: OA2[6:1] are masked and has no effect. Only OA2[7] is compared.
111: OA2[7:1] are masked and has no effect. 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 is not equal to 0, the reserved I 2 C addresses (0b0000xxx and 0b1111xxx) are not acknowledged even if the comparison matches.
Bits 7:1OA2[7:1]: Interface address bits 7:1 of address.
Note: These bits can be written only when OA2EN=0.
Bit 0Reserved, must be kept at reset value.

21.6.5 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]
rwrwrw
1514131211109876543210
SCLH[7:0]SCLL[7:0]
rwrw
Bits 31:28

PRESC[3:0]: Timing prescaler.

This field is used to prescale I2CCLK in order to generate the clock period \( t_{\text{PRESC}} \) used for data setup and hold counters and for SCL high and low level counters.

\[ t_{\text{PRESC}} = (\text{PRESC}+1) \times t_{\text{I2CCLK}} \]
Bits 27:24Reserved, 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}} \) between SDA edge and SCL rising edge in transmission mode.

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

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 SDA edge in transmission mode.

\[ 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:STA}} \) 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 I 2 C is disabled (PE = 0).

21.6.6 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 to this register is on-going. 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 PCLK1 + 6 \times I2CCLK \) .

31302928272625242322212019181716
TEXTENRes.Res.Res.TIMEOUTB [11:0]
rwrw
1514131211109876543210
TIMOUTENRes.Res.TIDLETIMEOUTA [11:0]
rwrwrw
Bit 31TEXTEN: 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 I 2 C interface, a timeout error is detected (TIMEOUT=1).
Bits 30:28Reserved, must be kept at reset value.
Bits 27:16TIMEOUTB[11:0]: Bus timeout B.
This field is used to configure the cumulative clock extension timeout:
In controller mode, the controller cumulative clock low extend time ( \( t_{LOW:MEXT} \) ) is detected in target mode, the target cumulative clock low extend time ( \( t_{LOW:SEXT} \) ) is detected \( t_{LOW:EXT} = (TIMEOUTB+1) \times 2048 \times t_{I2CCLK} \) .
Note: These bits can be written only when TEXTEN=0.
Bit 15TIMOUTEN: 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:13Reserved, must be kept at reset value.
Bit 12TIDLE: 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:0TIMEOUTA[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.

Note: If the SMBus feature is not supported, this register is reserved and forced by hardware to "0x00000000". Refer to Section 21.3: I 2 C implementation.

21.6.7 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
rr
1514131211109876543210
BUSYRes.ALERTTIME OUTPEC ERROVRARLOBERRTCRTCSTOPFNACKFADDRRXNETXISTXE
rrrrrrrrrrrrrrsrs
Bits 31:24Reserved, must be kept at reset value.
Bits 23:17ADDCODE[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 2 MSBs of the address.
Bit 16DIR: 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 15BUSY: 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. It is cleared by hardware when a stop condition is detected, or when PE=0.
Bit 14Reserved, must be kept at reset value.
Bit 13ALERT: 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.
If the SMBus feature is not supported, this bit is reserved and forced by hardware to '0'. Refer to Section 21.3: I 2 C implementation .
Bit 12TIMEOUT: Timeout or t LOW 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.
If the SMBus feature is not supported, this bit is reserved and forced by hardware to '0'. Refer to Section 21.3: I 2 C implementation .
Bit 11PECERR: 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.
If the SMBus feature is not supported, this bit is reserved and forced by hardware to '0'. Refer to Section 21.3: I 2 C implementation .
Bit 10OVR: 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 loss.

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

  • either as a controller, provided that the STOP condition is generated by the peripheral.
  • or as a target, provided that the peripheral has been addressed previously during 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 when NOSTRETCH=1 only, in order 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.

21.6.8 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
TIM
OUTCF
PEC CFOVR CFARLO
CF
BERR
CF
Res.Res.STOP
CF
NACK
CF
ADDR
CF
Res.Res.Res.
wwwwwwwww
Bits 31:14Reserved, must be kept at reset value.
Bit 13ALERTCF: Alert flag clear.
Writing 1 to this bit clears the ALERT flag in the I2C_ISR register.
Note: If the SMBus feature is not supported, this bit is reserved and forced by hardware to '0'.
Refer to Section 21.3: I2C implementation .
Bit 12TIMOUTCF: Timeout detection flag clear.
Writing 1 to this bit clears the TIMEOUT flag in the I2C_ISR register.
Note: If the SMBus feature is not supported, this bit is reserved and forced by hardware to '0'.
Refer to Section 21.3: I2C implementation .
Bit 11PEC CF: PEC Error flag clear.
Writing 1 to this bit clears the PECERR flag in the I2C_ISR register.
Note: If the SMBus feature is not supported, this bit is reserved and forced by hardware to '0'.
Refer to Section 21.3: I2C implementation .
Bit 10OVR CF: Overrun/underrun flag clear.
Writing 1 to this bit clears the OVR flag in the I2C_ISR register.
Bit 9ARLOCF: Arbitration loss flag clear.
Writing 1 to this bit clears the ARLO flag in the I2C_ISR register.
Bit 8BERRCF: Bus error flag clear.
Writing 1 to this bit clears the BERRF flag in the I2C_ISR register.
Bits 7:6Reserved, must be kept at reset value.
Bit 5STOPCF: Stop detection flag clear.
Writing 1 to this bit clears the STOPF flag in the I2C_ISR register.
Bit 4NACKCF: Not acknowledge flag clear.
Writing 1 to this bit clears the ACKF flag in I2C_ISR register.
Bit 3ADDRCF: 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:0Reserved, must be kept at reset value.

21.6.9 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]
r
Bits 31:8Reserved, must be kept at reset value.
Bits 7:0PEC[7:0] Packet error checking register.
This field contains the internal PEC when PECEN=1. The PEC is cleared by hardware when PE=0.

Note: If the SMBus feature is not supported, this register is reserved and forced by hardware to “0x00000000”. Refer to Section 21.3: I 2 C implementation.

21.6.10 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]
r
Bits 31:8Reserved, must be kept at reset value.
Bits 7:0RXDATA[7:0] 8-bit receive data.
Data byte received from the I 2 C bus.

21.6.11 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]
rw
Bits 31:8Reserved, must be kept at reset value.
Bits 7:0TXDATA[7:0] 8-bit transmit data.
Data byte to be transmitted to the I 2 C bus.
Note: These bits can be written only when TXE=1.

21.6.12 I2C register map

The table below provides the I 2 C register map and reset values.

Table 96. I 2 C register map

OffsetRegister313029282726252423222120191817161514131211109876543210
0x0I2C_CR1Res.Res.Res.Res.Res.Res.Res.Res.PECENALERTENSMBDENSMBHENGCENRes.NOSTRETCHSBCRXDMAENTXDMAENRes.ANFOFFDNF[3:0]ERRIETCIESTOPIENACKIEADDRIERXIETXIEPE
Reset value0000000000000000000000
0x4I2C_CR2Res.Res.Res.Res.Res.PECBYTEAUTOENDRELOADNACKSTOPSTARTHEAD10RADD10RD_WRN
Reset value000000000000000000000000000
0x8I2C_OAR1Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.OA1ENRes.Res.Res.Res.OA1MODE
Reset value000000000000
0xCI2C_OAR2Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.OA2ENRes.Res.Res.Res.Res.
Reset value00000000000
0x10I2C_TIMINGRPRESC[3:0]
Reset value0000000000000000000000000000
0x14I2C_TIMEOUTRTEXTENRes.Res.Res.
Reset value0
STMicroelectronics logo
STMicroelectronics logo
OffsetRegister313029282726252423222120191817161514131211109876543210
0x18I2C_ISRRes.Res.Res.Res.Res.Res.Res.Res.ADDCODE[6:0]DIRBUSYRes.ALERTTIMEOUTPECERROVRARLOBERRTCRTCSTOPFNACKFADDRRXNETXISTXE
Reset value00000000000000000000001
0x1CI2C_ICRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.ALERTCFTIMOUTCFPEC CFOVR CFARLO CFBERR CFRes.Res.STOP CFNACK CFADDR CFRes.Res.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.Res.Res.PEC[7:0]
Reset value00000000
0x24I2C_RXDRRes.Res.Res.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 value00000000
0x28I2C_TXDRRes.Res.Res.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 value00000000

Refer to Section 2.2.2: Memory map and register boundary addresses for the register boundary addresses.

STMicroelectronics logo
STMicroelectronics logo