33. Inter-integrated circuit interface (I2C)

33.1 Introduction

The I2C peripheral handles the interface between the device and the serial I 2 C (inter-integrated circuit) bus. It provides multicontroller 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+).

I2C peripheral can use DMA to reduce the CPU load.

33.2 I2C main features

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

33.3 I2C implementation

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

Table 186. I2C implementation

I2C features (1)I2C1I2C2I2C3I2C4 (2)
7-bit addressing modeXXXX
10-bit addressing modeXXXX
Standard-mode (up to 100 kbit/s)XXXX
Fast-mode (up to 400 kbit/s)XXXX

Table 186. I2C implementation (continued)

I2C features (1)I2C1I2C2I2C3I2C4 (2)
Fast-mode Plus with 20 mA output drive I/Os (up to 1 Mbit/s)XXXX
Independent clockX-X-
Wake-up from Stop 1 modeX-X-
Wake-up from Stop 2 mode--X-

1. X = supported.

2. I2C4 is only available on STM32U073xx and STM32U083xx devices.

33.4 I2C functional description

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

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

33.4.1 I2C block diagram

Figure 304. Block diagram

Block diagram of the I2C peripheral showing internal components and external connections.

The block diagram illustrates the internal architecture of the I2C peripheral. It shows the following components and connections:

MSv56357V2

Block diagram of the I2C peripheral showing internal components and external connections.

33.4.2 I2C pins and internal signals

Table 187. I2C input/output pins

Pin nameSignal typeDescription
I2C_SDABidirectionalI 2 C-bus data
I2C_SCLBidirectionalI 2 C-bus clock

Table 188. I2C internal input/output signals

Internal signal nameSignal typeDescription
i2c_ker_ckInputI2C kernel clock, also named I2CCLK in this document
i2c_pclkInputI2C APB clock
i2c_itOutputI2C interrupts, refer to Table 197 for the list of interrupt sources
i2c_rx_dmaOutputI2C receive data DMA request (I2C_RX)
i2c_tx_dmaOutputI2C transmit data DMA request (I2C_TX)

33.4.3 I2C clock requirements

The I2C kernel is clocked by I2CCLK.

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

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

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

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

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

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

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

33.4.4 I2C mode selection

The peripheral can operate as:

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

Communication flow

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

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

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

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

Figure 305. I 2 C-bus protocol

Timing diagram of the I2C-bus protocol showing SDA and SCL lines. The SDA line starts high, then drops to low for the Start condition. The SCL line is a square wave. The first eight SCL pulses (labeled 1 to 8) correspond to the transmission of eight data bits on the SDA line, starting with the MSB. The ninth SCL pulse (labeled 9) corresponds to the ACK (Acknowledge) bit. The SDA line then returns to high for the Stop condition. The diagram is labeled MS19854V1.
Timing diagram of the I2C-bus protocol showing SDA and SCL lines. The SDA line starts high, then drops to low for the Start condition. The SCL line is a square wave. The first eight SCL pulses (labeled 1 to 8) correspond to the transmission of eight data bits on the SDA line, starting with the MSB. The ninth SCL pulse (labeled 9) corresponds to the ACK (Acknowledge) bit. The SDA line then returns to high for the Stop condition. The diagram is labeled MS19854V1.

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

33.4.5 I2C initialization

Enabling and disabling the peripheral

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

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

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

Noise filters

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

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

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

The following table compares the two filters.

Table 189. Comparison of analog and digital filters

ItemAnalog filterDigital filter
Filtering capacity (1)≥ 50 nsOne to fifteen I2CCLK periods
BenefitsAvailable in Stop mode
  • – Programmable filtering capacity
  • – Extra filtering capability versus I 2 C-bus specification requirements
  • – Stable filtering capacity
DrawbacksFiltering capacity variation with temperature, voltage, and silicon processWake-up from Stop mode on address match not supported when the digital filter is enabled

1. Maximum duration of spikes that the filter can suppress

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

I2C timings

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

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

Figure 306. Setup and hold timings

Timing diagrams for I2C setup and hold times. The top diagram labeled 'DATA HOLD TIME' shows the SCL falling edge internal detection triggering a delay t_SYNC1 followed by SDADEL (SCL stretched low by the I2C). An SDA output delay is shown relative to the SCL falling edge, with t_HD;DAT marked. The bottom diagram labeled 'DATA SETUP TIME' shows SCLDEL (SCL stretched low by the I2C) and the setup time t_SU;DAT (labeled as t_SU;STA in the diagram, but likely a typo for t_SU;DAT based on context) relative to the SCL rising edge.

DATA HOLD TIME

SCL falling edge internal detection

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

SDA output delay

SCL

SDA

\( t_{HD;DAT} \)

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

DATA SETUP TIME

SCLDEL
SCL stretched low by the I2C

SCL

SDA

\( t_{SU;STA} \)

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

MSV40108V1

Timing diagrams for I2C setup and hold times. The top diagram labeled 'DATA HOLD TIME' shows the SCL falling edge internal detection triggering a delay t_SYNC1 followed by SDADEL (SCL stretched low by the I2C). An SDA output delay is shown relative to the SCL falling edge, with t_HD;DAT marked. The bottom diagram labeled 'DATA SETUP TIME' shows SCLDEL (SCL stretched low by the I2C) and the setup time t_SU;DAT (labeled as t_SU;STA in the diagram, but likely a typo for t_SU;DAT based on context) relative to the SCL rising edge.

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

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

The total SDA output delay is:

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Table 190. I 2 C-bus specification data setup and hold times

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

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

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

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

Refer to I2C controller initialization for more details.

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

Figure 307. I2C initialization flow

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

The flowchart illustrates the I2C initialization sequence. It begins with 'Initial settings' in an oval, followed by a rectangular box 'Clear PE bit in I2C_CR1'. This is followed by 'Configure ANFOFF and DNF[3:0] in I2C_CR1', then 'Configure PRESC[3:0], SDADEL[3:0], SCLDEL[3:0], SCLH[7:0], and SCLL[7:0] in I2C_TIMINGR', and 'Configure NOSTRETCH in I2C_CR1'. The next step is 'Set PE bit in I2C_CR1', and finally 'End' in an oval. The diagram is labeled with the code MS19847V3 in the bottom right corner.

Flowchart of I2C initialization flow

33.4.6 I2C reset

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

The impacted register bits are:

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

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

33.4.7 I2C data transfer

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

Reception

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

Figure 308. Data reception

Timing diagram for I2C data reception showing SCL, Shift register, RXNE, and I2C_RXDR signals over time.

The diagram illustrates the timing for I2C data reception. It shows four horizontal timelines: SCL (Serial Clock), Shift register, RXNE (Receive Not Empty), and I2C_RXDR (Receive Data Register). The SCL line shows a series of pulses. The Shift register contains 'xx' (don't care) and 'data1', 'data2' (received data). The RXNE line is high when the shift register is full and low when it is empty. The I2C_RXDR line shows 'data0', 'data1', and 'data2' (received data). Two 'ACK pulse' labels are shown above the SCL line, with circles around the falling edges. Vertical dashed lines indicate key timing points. A legend indicates that a blue line represents 'SCL stretch'. The diagram shows that after the eighth SCL pulse, the RXNE line goes high, and the SCL line is stretched low until the data is read from the I2C_RXDR register. Once read, the RXNE line goes low, and the SCL line resumes normal operation.

Timing diagram for I2C data reception showing SCL, Shift register, RXNE, and I2C_RXDR signals over time.

MS19848V1

Transmission

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

Figure 309. Data transmission

Timing diagram for I2C data transmission showing SCL, Shift register, TXE, and I2C_TXDR signals over time. The diagram illustrates the flow of data from the I2C_TXDR register through a shift register to the SDA line, synchronized with the SCL clock. It shows two ACK pulses and the corresponding data bytes (data0, data1, data2) being transferred. The TXE flag is shown toggling between 0 and 1 as data is written and shifted. The legend indicates that a blue line represents an SCL stretch.

The diagram illustrates the timing of data transmission in an I2C interface. It consists of four horizontal timelines:

Vertical dashed lines mark the falling edges of the SCL clock. A legend on the right shows a blue horizontal line labeled 'SCL stretch'.

Timing diagram for I2C data transmission showing SCL, Shift register, TXE, and I2C_TXDR signals over time. The diagram illustrates the flow of data from the I2C_TXDR register through a shift register to the SDA line, synchronized with the SCL clock. It shows two ACK pulses and the corresponding data bytes (data0, data1, data2) being transferred. The TXE flag is shown toggling between 0 and 1 as data is written and shifted. The legend indicates that a blue line represents an SCL stretch.

MS19849V1

Hardware transfer management

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

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

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

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

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

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

Table 191. I2C configuration

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

33.4.8 I2C target mode

I2C target initialization

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

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

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

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

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

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

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

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

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

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

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

Target with clock stretching

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

Target without clock stretching

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

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

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

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

Target byte control mode

To allow byte ACK control in target reception mode, the target byte control mode must be enabled, by setting the SBC bit of the I2C_CR1 register.

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

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

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

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

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

Figure 310. Target initialization flow

Flowchart of Target initialization flow
graph TD; A([Target initialization]) --> B[Initial settings]; B --> C[Clear OA1EN and OA2EN in I2C_OAR1/I2C_OAR2]; C --> D["Configure OA1[9:0], OA1MODE, OA1EN, OA2[6:0], OA2MSK[2:0], OA2EN, and GCEN"]; D --> E[Optional: Configure SBC in I2C_CR1]; E --> F[Enable interrupts and/or DMA in I2C_CR1]; F --> G([End]);

The flowchart illustrates the target initialization process. It begins with an oval labeled 'Target initialization', which points down to a rectangular box 'Initial settings'. This is followed by a sequence of rectangular boxes: 'Clear OA1EN and OA2EN in I2C_OAR1/I2C_OAR2', 'Configure OA1[9:0], OA1MODE, OA1EN, OA2[6:0], OA2MSK[2:0], OA2EN, and GCEN', 'Optional: Configure SBC in I2C_CR1', and 'Enable interrupts and/or DMA in I2C_CR1'. The process concludes with an oval labeled 'End'.

MSv56358V2

Flowchart of Target initialization flow

Target transmitter

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

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

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

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

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

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

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

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

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

Flowchart of I2C target transmitter transfer sequence. Steps: Target transmission -> Target initialization -> I2C_ISR.ADDR = 1? (No loop back, Yes proceeds) -> Read ADDCODE and DIR in I2C_ISR (Optional: Set I2C_ISR.TXE = 1, Set I2C_ICR.ADDRCF) -> I2C_ISR.TXIS = 1? (No loop back, Yes proceeds) -> Write I2C_TXDR.TXDATA. A vertical double-headed arrow on the right indicates 'SCL stretched' between the address and data phases.
graph TD; Start([Target transmission]) --> Init[Target initialization]; Init --> ADDR{I2C_ISR.ADDR = 1?}; ADDR -- No --> ADDR; ADDR -- Yes --> Read[Read ADDCODE and DIR in I2C_ISR<br/>Optional: Set I2C_ISR.TXE = 1<br/>Set I2C_ICR.ADDRCF]; Read --> TXIS{I2C_ISR.TXIS = 1?}; TXIS -- No --> TXIS; TXIS -- Yes --> Write[Write I2C_TXDR.TXDATA]; Write --> TXIS;

MSv19851V3

Flowchart of I2C target transmitter transfer sequence. Steps: Target transmission -> Target initialization -> I2C_ISR.ADDR = 1? (No loop back, Yes proceeds) -> Read ADDCODE and DIR in I2C_ISR (Optional: Set I2C_ISR.TXE = 1, Set I2C_ICR.ADDRCF) -> I2C_ISR.TXIS = 1? (No loop back, Yes proceeds) -> Write I2C_TXDR.TXDATA. A vertical double-headed arrow on the right indicates 'SCL stretched' between the address and data phases.

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

Flowchart for I2C target transmitter transfer sequence. It starts with 'Target transmission' (oval), followed by 'Target initialization' (rectangle). A loop begins with a decision 'I2C_ISR.TXIS = 1?'. If 'Yes', it goes to 'Write I2C_TXDR.TXDATA' (rectangle) and loops back. If 'No', it goes to another decision 'I2C_ISR.STOPF = 1?'. If 'Yes', it goes to 'Optional: Set I2C_ISR.TXE = 1 and I2C_ISR.TXIS=1' (rectangle) and then 'Set I2C_ICR.STOPCF' (rectangle). If 'No', it loops back to the start of the first decision.
graph TD; A([Target transmission]) --> B[Target initialization]; B --> C{I2C_ISR.TXIS = 1?}; C -- Yes --> D[Write I2C_TXDR.TXDATA]; D --> C; C -- No --> E{I2C_ISR.STOPF = 1?}; E -- Yes --> F[Optional: Set I2C_ISR.TXE = 1 and I2C_ISR.TXIS=1]; F --> G[Set I2C_ICR.STOPCF]; E -- No --> C;
Flowchart for I2C target transmitter transfer sequence. It starts with 'Target transmission' (oval), followed by 'Target initialization' (rectangle). A loop begins with a decision 'I2C_ISR.TXIS = 1?'. If 'Yes', it goes to 'Write I2C_TXDR.TXDATA' (rectangle) and loops back. If 'No', it goes to another decision 'I2C_ISR.STOPF = 1?'. If 'Yes', it goes to 'Optional: Set I2C_ISR.TXE = 1 and I2C_ISR.TXIS=1' (rectangle) and then 'Set I2C_ICR.STOPCF' (rectangle). If 'No', it loops back to the start of the first decision.

MSV19852V3

Figure 313. Transfer bus diagrams for I2C target transmitter (mandatory events only)

Timing diagram for I2C target transmitter with 3 bytes and 1st data flushed. The sequence starts with a Start (S) and Address (yellow, reception). EV1 (ADDR) occurs at the start. Then a blue line (SCL stretch) until EV2 (TXIS), where data1 (white, transmission) is sent. Then EV3 (TXIS) for data2, and EV4 (TXIS) for data3. EV5 (TXIS) occurs after data3, but data4 is not sent. The sequence ends with NA (yellow) and P (yellow). The TXE line is shown as a digital signal below the sequence. Timing diagram for I2C target transmitter with 3 bytes and no 1st data flush. The sequence starts with a Start (S) and Address (yellow, reception). EV1 (ADDR) occurs at the start. Then EV2 (TXIS) for data1, EV3 (TXIS) for data2, and EV4 (TXIS) for data3. EV4 (TXIS) occurs after data3, but data4 is not sent. The sequence ends with NA (yellow) and P (yellow). The TXE line is shown as a digital signal below the sequence. Timing diagram for I2C target transmitter with 3 bytes and NOSTRETCH=1. The sequence starts with a Start (S) and Address (yellow, reception). EV1 occurs at the start. Then EV2 (TXIS) for data1, EV3 (TXIS) for data2, and EV4 (TXIS) for data3. EV5 (STOPF) occurs after data3. The sequence ends with NA (yellow) and P (yellow). The TXE line is shown as a digital signal below the sequence.

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

legend:

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

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

legend :

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

Example I2C target transmitter 3 bytes, NOSTRETCH=1:

legend:

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

MSv19853V3

Timing diagram for I2C target transmitter with 3 bytes and 1st data flushed. The sequence starts with a Start (S) and Address (yellow, reception). EV1 (ADDR) occurs at the start. Then a blue line (SCL stretch) until EV2 (TXIS), where data1 (white, transmission) is sent. Then EV3 (TXIS) for data2, and EV4 (TXIS) for data3. EV5 (TXIS) occurs after data3, but data4 is not sent. The sequence ends with NA (yellow) and P (yellow). The TXE line is shown as a digital signal below the sequence. Timing diagram for I2C target transmitter with 3 bytes and no 1st data flush. The sequence starts with a Start (S) and Address (yellow, reception). EV1 (ADDR) occurs at the start. Then EV2 (TXIS) for data1, EV3 (TXIS) for data2, and EV4 (TXIS) for data3. EV4 (TXIS) occurs after data3, but data4 is not sent. The sequence ends with NA (yellow) and P (yellow). The TXE line is shown as a digital signal below the sequence. Timing diagram for I2C target transmitter with 3 bytes and NOSTRETCH=1. The sequence starts with a Start (S) and Address (yellow, reception). EV1 occurs at the start. Then EV2 (TXIS) for data1, EV3 (TXIS) for data2, and EV4 (TXIS) for data3. EV5 (STOPF) occurs after data3. The sequence ends with NA (yellow) and P (yellow). The TXE line is shown as a digital signal below the sequence.

Target receiver

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

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

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

Flowchart of I2C target receiver transfer sequence with NOSTRETCH = 0.
graph TD; A([Target reception]) --> B[Target initialization]; B --> C{I2C_ISR.ADDR = 1?}; C -- No --> B; C -- Yes --> D[Read ADDCODE and DIR in I2C_ISR<br/>Set I2C_ICR.ADDRCF]; D --> E{I2C_ISR.RXNE = 1?}; E -- No --> D; E -- Yes --> F[Write I2C_RXDR.RXDATA]; F --> E;

The flowchart illustrates the transfer sequence for an I2C target receiver when NOSTRETCH is set to 0. It begins with 'Target reception' (oval), followed by 'Target initialization' (rectangle). A decision diamond 'I2C_ISR.ADDR = 1?' follows. If 'No', it loops back to 'Target initialization'. If 'Yes', it proceeds to a rectangle 'Read ADDCODE and DIR in I2C_ISR' and 'Set I2C_ICR.ADDRCF'. To the right of this step, a vertical double-headed arrow is labeled 'SCL stretched'. Next is a decision diamond 'I2C_ISR.RXNE = 1?'. If 'No', it loops back to the 'Read ADDCODE...' step. If 'Yes', it proceeds to a rectangle 'Write I2C_RXDR.RXDATA', which then loops back to the 'I2C_ISR.RXNE = 1?' decision. The diagram is labeled 'MSV19855V3' in the bottom right corner.

Flowchart of I2C target receiver transfer sequence with NOSTRETCH = 0.

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

Flowchart for I2C target reception with NOSTRETCH = 1. The process starts at 'Target reception' (oval), then 'Target initialization' (rectangle). It splits into two parallel monitoring loops. Left loop: checks 'I2C_ISR.RXNE = 1?'. If Yes, 'Read I2C_RXDR.RXDATA' and loop back. If No, loop back. Right loop: checks 'I2C_ISR.STOPF = 1?'. If Yes, 'Set I2C_ICR.STOPCF' and loop back. If No, loop back.
graph TD
    Start([Target reception]) --> Init[Target initialization]
    Init --> RXNE_Check{I2C_ISR.RXNE = 1?}
    RXNE_Check -- Yes --> Read[Read I2C_RXDR.RXDATA]
    Read --> RXNE_Check
    RXNE_Check -- No --> RXNE_Check
    
    Init --> STOPF_Check{I2C_ISR.STOPF = 1?}
    STOPF_Check -- Yes --> Clear[Set I2C_ICR.STOPCF]
    Clear --> STOPF_Check
    STOPF_Check -- No --> STOPF_Check
  
Flowchart for I2C target reception with NOSTRETCH = 1. The process starts at 'Target reception' (oval), then 'Target initialization' (rectangle). It splits into two parallel monitoring loops. Left loop: checks 'I2C_ISR.RXNE = 1?'. If Yes, 'Read I2C_RXDR.RXDATA' and loop back. If No, loop back. Right loop: checks 'I2C_ISR.STOPF = 1?'. If Yes, 'Set I2C_ICR.STOPCF' and loop back. If No, loop back.

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

Timing diagram for I2C target receiver with NOSTRETCH = 0. Shows S, Address, A, data1, A, data2, A, data3, A. Blue lines indicate SCL stretching after Address (EV1) and after each data byte (EV2, EV3, EV4). RXNE signal goes high when data is received and low when read. Timing diagram for I2C target receiver with NOSTRETCH = 1. Shows S, Address, A, data 1, A, data 2, A, data 3, A, P. No blue SCL stretch lines are present. RXNE pulses high at EV1, EV2, and EV3 when data is ready.

Example I2C target receiver 3 bytes, NOSTRETCH = 0:

Legend

  • Transmission
  • Reception
  • SCL stretch

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


Example I2C target receiver 3 bytes, NOSTRETCH = 1:

Legend

  • Transmission
  • Reception
  • SCL stretch

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

Timing diagram for I2C target receiver with NOSTRETCH = 0. Shows S, Address, A, data1, A, data2, A, data3, A. Blue lines indicate SCL stretching after Address (EV1) and after each data byte (EV2, EV3, EV4). RXNE signal goes high when data is received and low when read. Timing diagram for I2C target receiver with NOSTRETCH = 1. Shows S, Address, A, data 1, A, data 2, A, data 3, A, P. No blue SCL stretch lines are present. RXNE pulses high at EV1, EV2, and EV3 when data is ready.

33.4.9 I2C controller mode

I2C controller initialization

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

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

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

In order to allow clock synchronization:

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

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

Consequently the controller clock period is:

\[ t_{\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 upon:

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

Figure 317. Controller clock generation

Timing diagram for SCL controller clock generation showing the SCL signal transitions. It labels 'SCL released', 'SCL high level detected SCLH counter starts', 'SCL driven low', and 'SCL low level detected SCLL counter starts'. Timing parameters tSYNC2, SCLH, tSYNC1, and SCLL are indicated with arrows. Timing diagram for SCL controller clock synchronization showing how the SCL signal is affected by other devices. It labels multiple instances of 'SCL high level detected SCLH counter starts' and 'SCL low level detected SCLL counter starts'. It also shows 'SCL driven low by another device' and 'SCL released' events, illustrating how the SCLL period is extended when the bus is held low by another device.

SCL controller clock generation

SCL controller clock synchronization

MSv19858V2

Timing diagram for SCL controller clock generation showing the SCL signal transitions. It labels 'SCL released', 'SCL high level detected SCLH counter starts', 'SCL driven low', and 'SCL low level detected SCLL counter starts'. Timing parameters tSYNC2, SCLH, tSYNC1, and SCLL are indicated with arrows. Timing diagram for SCL controller clock synchronization showing how the SCL signal is affected by other devices. It labels multiple instances of 'SCL high level detected SCLH counter starts' and 'SCL low level detected SCLL counter starts'. It also shows 'SCL driven low by another device' and 'SCL released' events, illustrating how the SCLL period is extended when the bus is held low by another device.

Caution: For compliance with the I 2 C-bus specification, the controller clock must respect the timings in the following table.

Table 192. I 2 C-bus specification clock timings

SymbolParameterStandard-mode (Sm)Fast-mode (Fm)Fast-mode Plus (Fm+)Unit
MinMaxMinMaxMinMax
f SCLSCL clock frequency-100-400-1000kHz
t HD:STAHold time (repeated) START condition4.0-0.6-0.26-μs
t SU:STASet-up time for a repeated START condition4.7-0.6-0.26-
t SU:STOSet-up time for STOP condition4.0-0.6-0.26-
t BUFBus free time between a STOP and START condition4.7-1.3-0.5-
t LOWLow period of the SCL clock4.7-1.3-0.5-ns
t HIGHHigh period of the SCL clock4.0-0.6-0.26-
t rRise time of both SDA and SCL signals-1000-300-120
t fFall time of both SDA and SCL signals-300-300-120

Note: The SCLL[7:0] bitfield also determines the t BUF and t SU:STA timings and SCLH[7:0] the t HD:STA and t SU:STO timings.

Refer to Section 33.4.10 for examples of I2C_TIMINGR settings versus the I2CCLK frequency.

Controller communication initialization (address phase)

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

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

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

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

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

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

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

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

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

Figure 318. Controller initialization flow

Flowchart for controller initialization: Controller initialization -> Initial settings -> Enable interrupts and/or DMA in I2C_CR1 -> End. MSV19859V3
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. MSV19859V3

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

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

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

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

Timing diagram for 10-bit address read access. It shows a sequence of bytes: S, Target address 1st 7 bits, R/W (Write), A1, Target address 2nd byte, A2, Sr, Target address 1st 7 bits, R/W (Read), A3, DATA, A, DATA, A-bar, P. Above the first part is '1 1 1 1 0 X X 0' and above the second part is '1 1 1 1 0 X X 1'. MSV41066V2
1 1 1 1 0 X X 01 1 1 1 0 X X 1
STarget address 1st 7 bitsR/WA1Target address 2nd byteA2SrTarget address 1st 7 bitsR/WA3DATAADATAA-barP
WriteRead
Timing diagram for 10-bit address read access. It shows a sequence of bytes: S, Target address 1st 7 bits, R/W (Write), A1, Target address 2nd byte, A2, Sr, Target address 1st 7 bits, R/W (Read), A3, DATA, A, DATA, A-bar, P. Above the first part is '1 1 1 1 0 X X 0' and above the second part is '1 1 1 1 0 X X 1'. MSV41066V2

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

RESTART + Target address 10-bit header Read.

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

Timing diagram for 10-bit address read access with HEAD10R = 1. The diagram shows two sequences of I2C transactions. The first sequence is a 'Write' transaction starting with a START (S) condition, followed by the target address (1st 7 bits) with the R/W bit set to 0 (11110XX 0), an Acknowledge (A), the target address 2nd byte, an Acknowledge (A), a data byte, an Acknowledge (A), another data byte, and a Not Acknowledge (A/Ā). The second sequence is a 'Read' transaction starting with a Repeated START (Sr) condition, followed by the target address (1st 7 bits) with the R/W bit set to 1 (11110XX 1), an Acknowledge (A), a data byte, an Acknowledge (A), another data byte, a Not Acknowledge (Ā), and a STOP (P) condition. An arrow indicates the transition from the write sequence to the read sequence.
Timing diagram for 10-bit address read access with HEAD10R = 1. The diagram shows two sequences of I2C transactions. The first sequence is a 'Write' transaction starting with a START (S) condition, followed by the target address (1st 7 bits) with the R/W bit set to 0 (11110XX 0), an Acknowledge (A), the target address 2nd byte, an Acknowledge (A), a data byte, an Acknowledge (A), another data byte, and a Not Acknowledge (A/Ā). The second sequence is a 'Read' transaction starting with a Repeated START (Sr) condition, followed by the target address (1st 7 bits) with the R/W bit set to 1 (11110XX 1), an Acknowledge (A), a data byte, an Acknowledge (A), another data byte, a Not Acknowledge (Ā), and a STOP (P) condition. An arrow indicates the transition from the write sequence to the read sequence.

Controller transmitter

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

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

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

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

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

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

Flowchart for I2C controller transmitter transfer sequence. It starts with 'Controller transmission' (oval), followed by 'Controller initialization' (rectangle), and then a configuration block (rectangle) with 'NBYTES = N', 'AUTOEND = 0 for RESTART; 1 for STOP', 'Configure target address', and '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' (oval). From 'Set I2C_CR2.START with target address NBYTES ...', it goes to 'End' (oval). A dashed line indicates continuation.
graph TD; A([Controller transmission]) --> B[Controller initialization]; B --> C["NBYTES = N<br/>AUTOEND = 0 for RESTART; 1 for STOP<br/>Configure target address<br/>Set I2C_CR2.START"]; C --> D{I2C_ISR.TXIS = 1?}; D -- No --> E{I2C_ISR.NACKF = 1?}; D -- Yes --> F[Write I2C_TXDR]; F --> G{NBYTES transmitted?}; G -- No --> D; G -- Yes --> H{I2C_ISR.TC = 1?}; H -- Yes --> I["Set I2C_CR2.START with<br/>target address NBYTES<br/>..."]; H -- No --> J([End]); I --> J; E -- Yes --> K([End]); E -- No --> D;
Flowchart for I2C controller transmitter transfer sequence. It starts with 'Controller transmission' (oval), followed by 'Controller initialization' (rectangle), and then a configuration block (rectangle) with 'NBYTES = N', 'AUTOEND = 0 for RESTART; 1 for STOP', 'Configure target address', and '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' (oval). From 'Set I2C_CR2.START with target address NBYTES ...', it goes to 'End' (oval). A dashed line indicates continuation.

MSV19860V3

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

Flowchart of I2C Controller Transmission process for N > 255 bytes
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?} NACKF -- No --> LoopStart NACKF -- Yes --> End1([End]) LoopStart --> TXIS{I2C_ISR.TXIS = 1?} TXIS -- No --> LoopStart TXIS -- Yes --> Write[Write I2C_TXDR] Write --> NTransmitted{NBYTES transmitted?} NTransmitted -- No --> LoopStart NTransmitted -- Yes --> TC{I2C_ISR.TC = 1?} TC -- Yes --> Restart["Set I2C_CR2.START
with target address
NBYTES ..."] TC -- No --> TCR{I2C_ISR.TCR = 1?} TCR -- Yes --> EndBlock["IF N < 256
NBYTES = N; N = 0; RELOAD = 0
AUTOEND = 0 for RESTART; 1 for STOP
ELSE
NBYTES = 0xFF; N = N-255
RELOAD = 1"] EndBlock --> LoopStart TCR -- No --> End2([End]) Restart -.-> End2

The flowchart illustrates the I2C Controller Transmission process for transfers exceeding 255 bytes. It begins with "Controller transmission" followed by "Controller initialization". The initial configuration sets NBYTES to 0xFF, decrements N by 255, sets RELOAD to 1, configures the target address, and sets I2C_CR2.START.

The process enters a loop checking for status flags. If I2C_ISR.NACKF is 1, the process ends. If I2C_ISR.TXIS is 1, data is written to I2C_TXDR. After writing, it checks if NBYTES are transmitted. If not, it loops back. If yes, it checks I2C_ISR.TC. If TC is 1, it sets I2C_CR2.START with the target address and NBYTES, leading towards the end. If TC is 0, it checks I2C_ISR.TCR. If TCR is 1, it evaluates if N < 256. If true, it sets NBYTES to N, N to 0, RELOAD to 0, and configures AUTOEND. If false (ELSE), it sets NBYTES to 0xFF, decrements N by 255, and sets RELOAD to 1, then loops back to the status check junction. If TCR is 0, the process ends.

MSv19861V4

Flowchart of I2C Controller Transmission process for N > 255 bytes

Figure 323. Transfer bus diagrams for I2C controller transmitter (mandatory events only)

Timing diagram for I2C transmitter in automatic stop mode. The bus sequence is: S, Address, A, data1, A, data2, A, P. TXIS events occur after Address-A and data1-A. TXE signal goes high at INIT, low at EV1, high after data1, low at EV2, and high after data2. NBYTES is set to 2 at INIT. SCL stretch occurs during ACK phases. Timing diagram for I2C transmitter in software end mode. The bus sequence is: S, Address, A, data1, A, data2, A, ReS, Address... TXIS events occur after Address-A and data1-A. A TC event occurs after data2-A. TXE signal behavior is similar to the first diagram until EV3. NBYTES is set to 2 at INIT. SCL stretch occurs during ACK phases and before ReS.

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

legend:
☐ transmission
reception
SCL stretch


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

legend:
☐ transmission
reception
SCL stretch

MSV19862V3

Timing diagram for I2C transmitter in automatic stop mode. The bus sequence is: S, Address, A, data1, A, data2, A, P. TXIS events occur after Address-A and data1-A. TXE signal goes high at INIT, low at EV1, high after data1, low at EV2, and high after data2. NBYTES is set to 2 at INIT. SCL stretch occurs during ACK phases. Timing diagram for I2C transmitter in software end mode. The bus sequence is: S, Address, A, data1, A, data2, A, ReS, Address... TXIS events occur after Address-A and data1-A. A TC event occurs after data2-A. TXE signal behavior is similar to the first diagram until EV3. NBYTES is set to 2 at INIT. SCL stretch occurs during ACK phases and before ReS.

Controller receiver

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

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

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

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

Flowchart for I2C controller receiver transfer sequence. The process starts with 'Controller reception', followed by 'Controller initialization'. A loop begins with 'NBYPES = N, AUTOEND = 0 for RESTART; 1 for STOP, Configure target address, Set I2C_CR2.START'. A decision 'I2C_ISR.RXNE = 1?' follows. If 'No', it loops back to the start of the loop. If 'Yes', it proceeds to 'Read I2C_RXDR'. Another decision 'NBYPES received?' follows. If 'No', it loops back to the start of the loop. If 'Yes', it proceeds to 'I2C_ISR.TC = 1?'. If 'Yes', it proceeds to 'Set I2C_CR2.START with target address NBYPES ...'. If 'No', it proceeds to 'End'.
graph TD; Start([Controller reception]) --> Init[Controller initialization]; Init --> LoopStart[NBYTES = N
AUTOEND = 0 for RESTART; 1 for STOP
Configure target address
Set I2C_CR2.START]; LoopStart --> RXNE{I2C_ISR.RXNE = 1?}; RXNE -- No --> LoopStart; RXNE -- Yes --> Read[Read I2C_RXDR]; Read --> Received{NBYPES received?}; Received -- No --> LoopStart; Received -- Yes --> TC{I2C_ISR.TC = 1?}; TC -- Yes --> SetStart[Set I2C_CR2.START with target address NBYPES ...]; TC -- No --> End([End]); SetStart -.-> End;
Flowchart for I2C controller receiver transfer sequence. The process starts with 'Controller reception', followed by 'Controller initialization'. A loop begins with 'NBYPES = N, AUTOEND = 0 for RESTART; 1 for STOP, Configure target address, Set I2C_CR2.START'. A decision 'I2C_ISR.RXNE = 1?' follows. If 'No', it loops back to the start of the loop. If 'Yes', it proceeds to 'Read I2C_RXDR'. Another decision 'NBYPES received?' follows. If 'No', it loops back to the start of the loop. If 'Yes', it proceeds to 'I2C_ISR.TC = 1?'. If 'Yes', it proceeds to 'Set I2C_CR2.START with target address NBYPES ...'. If 'No', it proceeds to 'End'.

MSV19863V3

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

Flowchart showing the transfer sequence flow for an I2C controller receiver when 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; Set I2C_CR2.START'. It then enters a loop checking 'I2C_ISR.RXNE = 1?'. If 'No', it loops back to the start of the loop. If 'Yes', it proceeds to 'Read I2C_RXDR', then checks 'NBYS received?'. If 'No', it loops back. If '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 enters a block with 'IF N < 256 ... ELSE NBYS = 0xFF; N=N-255; RELOAD=1'. Both paths lead to 'End'.
graph TD
    Start([Controller reception]) --> Init[Controller initialization]
    Init --> Config["NBYS = 0xFF; N=N-255
RELOAD = 1
Configure target address
Set I2C_CR2.START"] Config --> RXNE{"I2C_ISR.RXNE
= 1?"} RXNE -- No --> RXNE RXNE -- Yes --> Read[Read I2C_RXDR] Read --> NBYS_Rx{"NBYS
received?"} NBYS_Rx -- No --> RXNE NBYS_Rx -- Yes --> TC{"I2C_ISR.TC
= 1?"} TC -- Yes --> SetNBYS["Set I2C_CR2.START with
target address NBYS
..."] TC -- No --> TCR{"I2C_ISR.TCR
= 1?"} TCR -- Yes --> IF_ELSE["IF N < 256
NBYS = N; N=0;RELOAD=0
AUTOEND=0 for RESTART; 1 for STOP
ELSE
NBYS = 0xFF;N=N-255
RELOAD=1"] SetNBYS --> End([End]) IF_ELSE --> End
Flowchart showing the transfer sequence flow for an I2C controller receiver when 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; Set I2C_CR2.START'. It then enters a loop checking 'I2C_ISR.RXNE = 1?'. If 'No', it loops back to the start of the loop. If 'Yes', it proceeds to 'Read I2C_RXDR', then checks 'NBYS received?'. If 'No', it loops back. If '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 enters a block with 'IF N < 256 ... ELSE NBYS = 0xFF; N=N-255; RELOAD=1'. Both paths lead to 'End'.

MSv19864V3

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

Timing diagram for I2C controller receiver in automatic end mode (STOP). The sequence starts with INIT (Start), followed by Address, A (Acknowledge), data1, A, data2, NA (Not Acknowledge), and P (Stop). RXNE flags are shown above data1 and data2. EV1 and EV2 are marked below the second and third Acknowledge signals. NBYTES is set to 2. Legend: transmission (white), reception (yellow), SCL stretch (blue line). Timing diagram for I2C controller receiver in software end mode (RESTART). The sequence starts with INIT (Start), followed by Address, A, data1, A, data2, NA, ReS (Restart), and Address. RXNE flags are shown above data1 and data2. EV1 and EV2 are marked below the second and third Acknowledge signals. TC is marked above the NA signal. NBYTES is shown as xx, 2, and N. Legend: transmission (white), reception (yellow), SCL stretch (blue line).

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

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)

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

MSv19865V2

Timing diagram for I2C controller receiver in automatic end mode (STOP). The sequence starts with INIT (Start), followed by Address, A (Acknowledge), data1, A, data2, NA (Not Acknowledge), and P (Stop). RXNE flags are shown above data1 and data2. EV1 and EV2 are marked below the second and third Acknowledge signals. NBYTES is set to 2. Legend: transmission (white), reception (yellow), SCL stretch (blue line). Timing diagram for I2C controller receiver in software end mode (RESTART). The sequence starts with INIT (Start), followed by Address, A, data1, A, data2, NA, ReS (Restart), and Address. RXNE flags are shown above data1 and data2. EV1 and EV2 are marked below the second and third Acknowledge signals. TC is marked above the NA signal. NBYTES is shown as xx, 2, and N. Legend: transmission (white), reception (yellow), SCL stretch (blue line).

33.4.10 I2C_TIMINGR register configuration examples

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

Table 193. Timing settings for\( f_{I2CCLK} \) of 8 MHz
ParameterStandard-mode (Sm)Fast-mode (Fm)Fast-mode Plus (Fm+)
10 kHz100 kHz400 kHz500 kHz
PRESC[3:0]0x10x10x00x0
SCLL[7:0]0xC70x130x90x6
\( t_{SCLL} \)200 x 250 ns = 50 µs20 x 250 ns = 5.0 µs10 x 125 ns = 1250 ns7 x 125 ns = 875 ns
SCLH[7:0]0xC30xF0x30x3
\( t_{SCLH} \)196 x 250 ns = 49 µs16 x 250 ns = 4.0 µs4 x 125 ns = 500 ns4 x 125 ns = 500 ns
\( t_{SCL}^{(1)} \)~100 µs (2)~10 µs (2)~2.5 µs (3)~2.0 µs (4)
SDADEL[3:0]0x20x20x10x0
\( t_{SDADEL} \)2 x 250 ns = 500 ns2 x 250 ns = 500 ns1 x 125 ns = 125 ns0 ns
SCLDEL[3:0]0x40x40x30x1
\( t_{SCLDEL} \)5 x 250 ns = 1250 ns5 x 250 ns = 1250 ns4 x 125 ns = 500 ns2 x 125 ns = 250 ns
  1. 1. \( t_{SCL} \) is greater than \( t_{SCLL} + t_{SCLH} \) due to SCL internal detection delay. Values provided for \( t_{SCL} \) are examples only.
  2. 2. \( t_{SYNC1} + t_{SYNC2} \) minimum value is \( 4 \times f_{I2CCLK} = 500 \) ns. Example with \( t_{SYNC1} + t_{SYNC2} = 1000 \) ns.
  3. 3. \( t_{SYNC1} + t_{SYNC2} \) minimum value is \( 4 \times f_{I2CCLK} = 500 \) ns. Example with \( t_{SYNC1} + t_{SYNC2} = 750 \) ns.
  4. 4. \( t_{SYNC1} + t_{SYNC2} \) minimum value is \( 4 \times f_{I2CCLK} = 500 \) ns. Example with \( t_{SYNC1} + t_{SYNC2} = 655 \) ns.
Table 194. Timing settings for\( f_{I2CCLK} \) of 16 MHz
ParameterStandard-mode (Sm)Fast-mode (Fm)Fast-mode Plus (Fm+)
10 kHz100 kHz400 kHz1000 kHz
PRESC[3:0]0x30x30x10x0
SCLL[7:0]0xC70x130x90x4
\( t_{SCLL} \)200 x 250 ns = 50 µs20 x 250 ns = 5.0 µs10 x 125 ns = 1250 ns5 x 62.5 ns = 312.5 ns
SCLH[7:0]0xC30xF0x30x2
\( t_{SCLH} \)196 x 250 ns = 49 µs16 x 250 ns = 4.0 µs4 x 125 ns = 500 ns3 x 62.5 ns = 187.5 ns
\( t_{SCL}^{(1)} \)~100 µs (2)~10 µs (2)~2.5 µs (3)~1.0 µs (4)
SDADEL[3:0]0x20x20x20x0
\( t_{SDADEL} \)2 x 250 ns = 500 ns2 x 250 ns = 500 ns2 x 125 ns = 250 ns0 ns
SCLDEL[3:0]0x40x40x30x2
\( t_{SCLDEL} \)5 x 250 ns = 1250 ns5 x 250 ns = 1250 ns4 x 125 ns = 500 ns3 x 62.5 ns = 187.5 ns
  1. 1. \( t_{SCL} \) is greater than \( t_{SCLL} + t_{SCLH} \) due to SCL internal detection delay. Values provided for \( t_{SCL} \) are examples only.
  2. 2. \( t_{SYNC1} + t_{SYNC2} \) minimum value is \( 4 \times f_{I2CCLK} = 250 \) ns. Example with \( t_{SYNC1} + t_{SYNC2} = 1000 \) ns.
  3. 3. \( t_{SYNC1} + t_{SYNC2} \) minimum value is \( 4 \times f_{I2CCLK} = 250 \) ns. Example with \( t_{SYNC1} + t_{SYNC2} = 750 \) ns.
  4. 4. \( t_{SYNC1} + t_{SYNC2} \) minimum value is \( 4 \times f_{I2CCLK} = 250 \) ns. Example with \( t_{SYNC1} + t_{SYNC2} = 500 \) ns.
Table 195. Timing settings for\( f_{I2CCLK} \) of 48 MHz
ParameterStandard-mode (Sm)Fast-mode (Fm)Fast-mode Plus (Fm+)
10 kHz100 kHz400 kHz1000 kHz
PRESC[3:0]0xB0xB0x50x5
SCLL[7:0]0xC70x130x90x3
\( t_{SCLL} \)200 x 250 ns = 50 µs20 x 250 ns = 5.0 µs10 x 125 ns = 1250 ns4 x 125 ns = 500 ns
SCLH[7:0]0xC30xF0x30x1
\( t_{SCLH} \)196 x 250 ns = 49 µs16 x 250 ns = 4.0 µs4 x 125 ns = 500 ns2 x 125 ns = 250 ns
\( t_{SCL}^{(1)} \)~100 µs (2)~10 µs (2)~2.5 µs (3)~875 ns (4)
SDADEL[3:0]0x20x20x30x0
\( t_{SDADEL} \)2 x 250 ns = 500 ns2 x 250 ns = 500 ns3 x 125 ns = 375 ns0 ns
SCLDEL[3:0]0x40x40x30x1
\( t_{SCLDEL} \)5 x 250 ns = 1250 ns5 x 250 ns = 1250 ns4 x 125 ns = 500 ns2 x 125 ns = 250 ns
  1. 1. \( t_{SCL} \) is greater than \( t_{SCLL} + t_{SCLH} \) due to the SCL internal detection delay. Values provided for \( t_{SCL} \) are only examples.
  2. 2. \( t_{SYNC1} + t_{SYNC2} \) minimum value is \( 4 \times t_{I2CCLK} = 83.3 \) ns. Example with \( t_{SYNC1} + t_{SYNC2} = 1000 \) ns
  3. 3. \( t_{SYNC1} + t_{SYNC2} \) minimum value is \( 4 \times t_{I2CCLK} = 83.3 \) ns. Example with \( t_{SYNC1} + t_{SYNC2} = 750 \) ns
  4. 4. \( t_{SYNC1} + t_{SYNC2} \) minimum value is \( 4 \times t_{I2CCLK} = 83.3 \) ns. Example with \( t_{SYNC1} + t_{SYNC2} = 250 \) ns

33.4.11 Wake-up from Stop mode on address match

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

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

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

HSI16 is then used for the address reception.

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

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

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

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

  1. Caution: The digital filter is not compatible with the wake-up from Stop mode feature. Before entering Stop mode with the WUPEN bit set, deactivate the digital filter, by writing zero to the DNF[3:0] bitfield.
  2. Caution: The feature is only available when the HSI16 oscillator is selected as the I2C clock.
  3. Caution: Clock stretching must be enabled (NOSTRETCH = 0) to ensure proper operation of the wake-up from Stop mode feature.
  4. Caution: If the wake-up from Stop mode is disabled (WUPEN = 0), the I2C peripheral must be disabled before entering Stop mode (PE = 0).

33.4.12 Error conditions

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

Bus error (BERR)

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

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

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

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

Arbitration loss (ARLO)

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

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

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

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

Overrun/underrun error (OVR)

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

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

33.5 I2C in low-power modes

Table 196. Effect of low-power modes to I2C

ModeDescription
SleepNo effect. I2C interrupts cause the device to exit the Sleep mode.
Stop (1)(2)The contents of I2C registers are kept.
– WUPEN = 1 and I2C is clocked by an internal oscillator (HSI16). The address recognition is functional. The I2C address match condition causes the device to exit the Stop mode.
– WUPEN = 0: the I2C must be disabled before entering Stop mode.
StandbyThe I2C peripheral is powered down. It must be reinitialized after exiting Standby mode.
  1. Refer to Section 33.3: I2C implementation for information about the Stop modes supported by each instance. If the wake-up from a specific stop mode is not supported, the instance must be disabled before entering that specific Stop mode.
  2. Only I2C3 supports wake-up from Stop 2 mode. The other I2C instances must be disabled before entering Stop 2 mode.

33.6 I2C interrupts

The following table gives the list of I2C interrupt requests.

Table 197. I2C interrupt requests

Interrupt acronymInterrupt eventEvent flagEnable control bitInterrupt clear methodExit Sleep modeExit Stop modesExit Standby modes
I2C_EVReceive buffer not emptyRXNERXIERead I2C_RXDR registerYesNoNo
Transmit buffer interrupt statusTXISTXIEWrite I2C_TXDR register
STOP detection interrupt flagSTOPFSTOPIEWrite STOPCF = 1
Transfer complete reloadTCRTCIEWrite I2C_CR2 with NBBYTES[7:0] ≠ 0
Transfer completeTCWrite START = 1 or STOP = 1
Address matchedADDRADDRIEWrite ADDRCF = 1Yes (1)
NACK receptionNACKFNACKIEWrite NACKCF = 1No
I2C_ERRBus errorBERRERRIEWrite BERRCF = 1YesNoNo
Arbitration lossARLOWrite ARLOCF = 1
Overrun/underrunOVRWrite OVRCF = 1
  1. 1. The ADDR match event can wake up the device from Stop mode only if the I2C instance supports the wake-up from Stop mode feature. Refer to Section 33.3: I2C implementation .

33.7 I2C DMA requests

33.7.1 Transmission using DMA

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

Only the data are transferred with DMA.

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

In target mode:

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

33.7.2 Reception using DMA

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

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

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

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

33.8 I2C registers

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

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

33.8.1 I2C control register 1 (I2C_CR1)

Address offset: 0x00

Reset value: 0x0000 0000

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

31302928272625242322212019181716
STOPF
ACLR
ADDRA
CLR
Res.Res.Res.Res.Res.FMPRes.Res.Res.Res.GCENWUPENNOSTRETCHSBC
rwrwrwrwrwrwrw
1514131211109876543210
RXDMA
EN
TXDMA
EN
Res.ANF
OFF
DNF[3:0]ERRIETCIESTOP
IE
NACKIEADDRI
E
RXIETXIEPE
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bit 31 STOPFACLR : STOP detection flag (STOPF) automatic clear

0: STOPF flag is set by hardware, cleared by software by setting STOPCF bit.

1: STOPF flag remains cleared by hardware. This mode can be used in NOSTRETCH target mode, to avoid the overrun error if the STOPF flag is not cleared before next data transmission. This allows a target data management by DMA only, without any interrupt from peripheral.

Bit 30 ADDRACLR : Address match flag (ADDR) automatic clear

0: ADDR flag is set by hardware, cleared by software by setting ADDRCF bit.

1: ADDR flag remains cleared by hardware. This mode can be used in target mode, to avoid the ADDR clock stretching if the I2C enables only one target address. This allows a target data management by DMA only, without any interrupt from peripheral.

Bits 29:25 Reserved, must be kept at reset value.

Bit 24 FMP : Fast-mode Plus 20 mA drive enable

0: 20 mA I/O drive disabled

1: 20 mA I/O drive enabled

Bits 23:20 Reserved, must be kept at reset value.

Bit 19 GCEN : General call enable

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

1: General call enabled. Address 0b000000000 is ACKed.

Bit 18 WUPEN : Wake-up from Stop mode enable

0: Wake-up from Stop mode disabled.

1: Wake-up from Stop mode enabled.

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

Bit 17 NOSTRETCH : 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 be programmed only when the I2C peripheral is disabled (PE = 0).

Bit 16 SBC : 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 15 RXDMAEN : DMA reception requests enable

0: DMA mode disabled for reception
1: DMA mode enabled for reception

Bit 14 TXDMAEN : DMA transmission requests enable

0: DMA mode disabled for transmission
1: DMA mode enabled for transmission

Bit 13 Reserved, must be kept at reset value.

Bit 12 ANFOFF : Analog noise filter OFF

0: Analog noise filter enabled
1: Analog noise filter disabled

Note: This bit can be programmed only when the I2C peripheral is disabled (PE = 0).

Bits 11:8 DNF[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 one \( t_{I2CCLK} \)

...

1111: digital filter enabled and filtering capability up to fifteen \( t_{I2CCLK} \)

Note: If the analog filter is enabled, the digital filter is added to it. This filter can be programmed only when the I2C peripheral is disabled (PE = 0).

Bit 7 ERRIE : Error interrupts enable

0: Error detection interrupts disabled
1: Error detection interrupts enabled

Note: Any of these errors generates an interrupt:

Bit 6 TCIE : Transfer complete interrupt enable

0: Transfer complete interrupt disabled
1: Transfer complete interrupt enabled

Note: Any of these events generates an interrupt:

Transfer complete (TC)
Transfer complete reload (TCR)

Bit 5 STOPIE : STOP detection interrupt enable

0: STOP detection (STOPF) interrupt disabled
1: STOP detection (STOPF) interrupt enabled

Bit 4 NACKIE : Not acknowledge received interrupt enable

0: Not acknowledge (NACKF) received interrupts disabled

1: Not acknowledge (NACKF) received interrupts enabled

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

0: Address match (ADDR) interrupts disabled

1: Address match (ADDR) interrupts enabled

Bit 2 RXIE : RX interrupt enable

0: Receive (RXNE) interrupt disabled

1: Receive (RXNE) interrupt enabled

Bit 1 TXIE : TX interrupt enable

0: Transmit (TXIS) interrupt disabled

1: Transmit (TXIS) interrupt enabled

Bit 0 PE : Peripheral enable

0: Peripheral disabled

1: Peripheral enabled

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

33.8.2 I2C control register 2 (I2C_CR2)

Address offset: 0x04

Reset value: 0x0000 0000

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

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.AUTOE
ND
RELOA
D
NBYPES[7:0]
rwrwrwrwrwrwrwrwrwrw
1514131211109876543210
NACKSTOPSTARTHEAD1
OR
ADD10RD_W
RN
SADD[9:0]
rsrsrsrwrwrwrwrwrwrwrwrwrwrwrwrw

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

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

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

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

Bit 24 RELOAD : NBYPES reload mode

This bit is set and cleared by software.

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

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

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

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

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

Bit 15 NACK : NACK generation (target mode)

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

0: an ACK is sent after current received byte.

1: a NACK is sent after current received byte.

Note: Writing 0 to this bit has no effect.

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

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

Bit 14 STOP : STOP condition generation

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

0: No STOP generation

1: STOP generation after current byte transfer

Note: Writing 0 to this bit has no effect.

Bit 13 START : START condition generation

This bit is set by software. It is cleared by hardware after the START condition followed by the address sequence is sent, by an arbitration loss, by an address matched in target mode, by a timeout error detection, or when PE = 0.

0: No START generation

1: RESTART/START generation:

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

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

Note: Writing 0 to this bit has no effect.

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

This bit has no effect when RELOAD is set.

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 + first seven bits of the 10-bit address in read direction.

1: The controller sends only the first seven 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:0 SADD[9:0] : Target address (controller mode)

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

SADD[7:1] must be written with the 7-bit target address to be sent. Bits SADD[9], SADD[8] and SADD[0] are don't care.

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

SADD[9:0] must be written with the 10-bit target address to be sent.

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

33.8.3 I2C own address 1 register (I2C_OAR1)

Address offset: 0x08

Reset value: 0x0000 0000

Access: no wait states, except if a write access occurs while a write access is ongoing. In this case, wait states are inserted in the second write access until the previous one is completed. The latency of the second write access can be up to \( 2 \times PCLK + 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.OA1MODEOA1[9:0]
rwrwrwrwrwrwrwrwrwrwrwrw

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

Bit 15 OA1EN : 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:11 Reserved, must be kept at reset value.

Bit 10 OA1MODE : Own address 1 10-bit mode

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

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

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

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

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

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

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

33.8.4 I2C own address 2 register (I2C_OAR2)

Address offset: 0x0C

Reset value: 0x0000 0000

Access: no wait states, except if a write access occurs while a write access is ongoing. In this case, wait states are inserted in the second write access, until the previous one is completed. The latency of the second write access can be up to \( 2 \times PCLK + 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.
rwrwrwrwrwrwrwrwrwrwrw

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

Bit 15 OA2EN : Own address 2 enable

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

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

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

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

000: No mask

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

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

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

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

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

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

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

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

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

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

7-bit addressing mode: 7-bit address

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

Bit 0 Reserved, must be kept at reset value.

33.8.5 I2C timing register (I2C_TIMINGR)

Address offset: 0x10

Reset value: 0x0000 0000

Access: no wait states

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

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

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

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

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

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

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

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

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

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

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

Note: \( t_{\text{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: \( t_{\text{SCLH}} \) is also used to generate \( t_{\text{SU:STO}} \) and \( t_{\text{HD:STA}} \) timing.

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

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

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

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

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

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

33.8.6 I2C interrupt and status register (I2C_ISR)

Address offset: 0x18

Reset value: 0x0000 0001

Access: no wait states

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.ADDCODE[6:0]DIR
rrrrrrrr
1514131211109876543210
BUSYRes.Res.Res.Res.OVRARLOBERRTCRTCSTOPFNACKFADDRRXNETXISTXE
rrrrrrrrrrrsrs

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

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

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

Bit 16 DIR : Transfer direction (target mode)

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

0: Write transfer, target enters receiver mode.

1: Read transfer, target enters transmitter mode.

Bit 15 BUSY : Bus busy

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

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

Bit 10 OVR : Overrun/underrun (target mode)

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

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

Bit 9 ARLO : Arbitration lost

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

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

Bit 8 BERR : Bus error

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

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

Bit 7 TCR : Transfer complete reload

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

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

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

Bit 6 TC : Transfer complete (controller mode)

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

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

Bit 5 STOPF : STOP detection flag

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

It is cleared by software by setting the STOPCF bit.

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

Bit 4 NACKF : Not acknowledge received flag

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

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

Bit 3 ADDR : Address matched (target mode)

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

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

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

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

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

Bit 1 TXIS : Transmit interrupt status (transmitters)

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

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

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

Bit 0 TXE : Transmit data register empty (transmitters)

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

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

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

33.8.7 I2C interrupt clear register (I2C_ICR)

Address offset: 0x1C

Reset value: 0x0000 0000

Access: no wait states

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.OVR CFARLO CFBERR CFRes.Res.STOP CFNACK CFADDR CFRes.Res.Res.
wwwwww

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

Bit 10 OVR CF : Overrun/underrun flag clear

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

Bit 9 ARLO CF : Arbitration lost flag clear

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

Bit 8 BERR CF : Bus error flag clear

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

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

Bit 5 STOP CF : STOP detection flag clear

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

Bit 4 NACK CF : Not acknowledge flag clear

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

Bit 3 ADDR CF : Address matched flag clear

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

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

33.8.8 I2C receive data register (I2C_RXDR)

Address offset: 0x24

Reset value: 0x0000 0000

Access: no wait states

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

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

Bits 7:0 RXDATA[7:0] : 8-bit receive data
Data byte received from the I 2 C-bus.

33.8.9 I2C transmit data register (I2C_TXDR)

Address offset: 0x28
Reset value: 0x0000 0000
Access: no wait states

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

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

Bits 7:0 TXDATA[7:0] : 8-bit transmit data
Data byte to be transmitted to the I 2 C-bus
Note: These bits can be written only when TXE = 1.

33.8.10 I2C register map

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

Table 198. I2C register map and reset values

OffsetRegister name313029282726252423222120191817161514131211109876543210
0x00I2C_CR1STOPFACLADDRARes.Res.Res.Res.Res.FMPRes.Res.Res.Res.GCENWUPENNOSTRETCHSBCRXDMAENTXDMAENRes.ANOFFDNF[3:0]ERRIETCIESTOPNACKADDRRXIETXIEPE
Reset value0000000000000000000000
0x04I2C_CR2Res.Res.Res.Res.Res.Res.AUTOENDRELOADNBYTES[7:0]NACKSTOPSTARTHEAD10RADD10RD_WRNSADD[9:0]
Reset value0000000000000000000000000
0x08I2C_OAR1Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.OA1ENRes.Res.Res.Res.OA1MODEOA1[9:0]
Reset value00000000000
0x0CI2C_OAR2Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.OA2ENRes.Res.Res.Res.OA2MSK[2:0]OA2[7:1]Res.
Reset value00000000000
0x10I2C_TIMINGRPRESC[3:0]Res.Res.Res.Res.SCLDEL[3:0]SDADEL[3:0]SCLH[7:0]SCLL[7:0]
Reset value000000000000000000000000000
0x14Reserved
0x18I2C_ISRRes.Res.Res.Res.Res.Res.Res.Res.ADDCODE[6:0]DIRBUSYRes.Res.Res.Res.OVRARLOBERRTCRTCSTOPNACKADDRRXNETXISTXE
Reset value00000000000000000001
0x1CI2C_ICRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.OVRARLOBERRRes.Res.STOPNACKADDRRes.Res.Res.
Reset value000000
0x20Reserved
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: Memory organization for the register boundary addresses.