 Hello, and welcome to this presentation of the STM32i²C interface. It covers the main features of this communication interface, which is widely used to connect devices such as microcontrollers, sensors, and serial interface memories. The i²C interface is compliant with the NXPi²C bus specification and user manual revision 3. The SM bus system management bus specification revision 2 and the PM bus power management system protocol specification revision 1.1. This peripheral provides an easy to use interface with very simple software programming and full timing flexibility. Additionally, the i²C peripheral is functional in low power stop modes. The i²C peripheral supports multi-master and slave modes. The i²C iO pins must be configured in open drain mode. The logic high level is driven by an external pull up. The i²C alternate functions are available on iO pins supplied by VDD, which can be from 1.71 to 3.6 volts. This allows communication with external chips at voltages different from the STM32l4 main power supply. A typical use case is communication with an application processor in sensor hub applications. The iO pins support the 20 milliamp output drive required for fast mode plus. The iO pins support the 20 milliamp output drive required for fast mode plus. The peripheral controls all i²C bus specific sequencing protocol arbitration and timing values. 7 and 10 bit addressing modes are supported and multiple 7 bit addresses can be supported in the same application. The peripheral supports slave clock stretching and clock stretching from slave can be disabled by software. The setup and hold times are programmable by software. Analog and digital glitch filters on the data and clock lines can be configured by software. The peripheral can wake up the MCU from stop mode when an address match is detected. The peripheral has an independent clock domain which allows a communication baud rate independent from the system clock. Here is the i²C block diagram. The registers are accessed through the APB bus and the peripheral is clocked with the i²C clock which is independent from the APB clock. The i²C clock can be selected between the system clock, APB clock and the high speed internal 16 MHz RC oscillator. Analog and digital noise filters are present on the SCL and SDA lines. A 20 milliamp driving capability is enabled using the control bits in the system configuration registers. In addition an SM bus alert pin is available in SM bus mode. The STM32L4 embeds noise filters on i²C data and clock lines. The analog noise filters can filter spikes up to 50 nanoseconds and can be enabled or disabled by software. By default analog noise filters are enabled. The digital noise filters can be enabled on the SDA and SCL lines instead of the analog noise filters. These filters suppress spikes with a programmable length from 1 to 15 i²C clock periods. The digital filters offer an extra filtering capability compared to the 50 nanosecond required by the i²C standard. The digital filter value is fixed by software while the analog filter value may vary with process, temperature and voltage. Take care that the digital filter is disabled by hardware when the wake up from stop feature is enabled. In this case only the analog filter can be enabled. The i²C setup and hold times can be configured by software through the i²C timing register. The SDA DEL and SCL DEL counters are used during transmission in order to guarantee the minimum data hold and data setup times. The i²C peripheral waits for the programmed data hold time after detecting a falling edge on the clock line before sending the data. After the data is sent the clock line is stretched low during the programmed data setup time. The total data hold time is greater than the programmed SDA DEL counter. This is due to the fact that SDA DEL delay is only added once the SCL falling edge is internally detected. The time T-sync one needed for this internal detection depends on the SCL falling edge, the input delay due to the filters and the delay due to the internal SCL synchronization with the i²C clock. However the setup time is not impacted by these internal delays. The i²C master clocks low and high level durations are configured by software in the i²C timings register. The SCL low and high level counters start after the detection of the edge of the SCL line. This implementation allows the peripheral to support the master clock synchronization mechanism in a multi master environment as well as the slave clock stretching feature. Therefore the total SCL period is greater than the sum of the counters. This is linked to the added delays due to the internal detection of the SCL line edge. These delays T-sync one and T-sync two depend on the SCL falling or rising edge, the input delay due to the filters and the delay due to the internal SCL synchronization with the i²C clock. The i²C slave can acknowledge several slave addresses. The slave addresses are programmed into two registers. Own address register one can be programmed with a seven or ten bit address. Own address register two can be programmed with a seven bit address but the least significant bits of this address can be masked through the OA2 MSK register in order to acknowledge multiple slave addresses. The two own address registers can be enabled simultaneously. The i²C peripheral supports wake up from stop mode on address matches. To do this the i²C peripheral clock must be set to the high speed internal 16 MHz RC oscillator. Only the analog noise filter is supported when the wake up from stop feature is enabled. All addressing modes are supported. When the device is in stop mode the high speed internal oscillator is switched off. When a start condition is detected the i²C peripheral enables the high speed internal oscillator which is used to receive the address on the buzz. After an address is received in stop mode a wake up interrupt is generated if the address matches the programmed slave address. If the address does not match the high speed internal oscillator is switched off no interrupt is generated and the device remains in stop mode. Clock stretching must be enabled because the i²C peripheral stretches the clock line low after the start condition until the high speed internal oscillator is started. After having received an address that matches the programmed slave address the i²C peripheral also stretches the clock line low until the STM32L4 device is woken up. Master mode software management is very simple. Only one right action is needed to handle a master transfer with a payload smaller than 255 bytes. The full protocol is managed by the hardware. In order to start a transfer in master mode i²C control register 2 must be written with the start condition request, the slave address, the transfer direction, the number of bytes to be transferred and the end of transfer mode. End of transfer mode is configured by the auto end bit. If it is set the stop condition is automatically sent after the programmed number of bytes is transferred. If the auto end bit is not set the end of transfer is managed by software. After the programmed number of bytes is transferred the transfer complete or TC flag is set and an interrupt is generated if enabled. Then a repeated start or a stop condition can be requested by software. The data transfer can be managed by interrupts or by the DMA. When the payload is greater than 255 bytes the reload bit must be set in i²C control register 2. In this case the transfer complete reload or TCR flag is set after the programmed number of bytes has been transferred. The additional number of bytes to be transferred is programmed when the TCR bit is set and then the data transfer will resume. The i²C clock is stretched low as long as TCR is set. The reload bit is used in master mode when the payload is greater than 255 bytes and in slave mode when slave byte control is enabled. When the reload bit is set the auto end bit has no effect. By default the i²C slave uses clock stretching. The clock stretching feature can be disabled by default. In reception the slave acknowledge on received byte behavior can be configured when slave byte control mode is selected together with the reload bit being set. When the SBC bit is set the number of bytes counter is enabled in slave mode. Clock stretching must be enabled when slave byte control is enabled. In reception when slave byte control is enabled with the reload bit set and the number of bytes to be transferred is 1. The transfer complete reload flag is set after each received byte and SCL is stretched. This is done after data reception and before the acknowledge pulse. The receive buffer not empty flag is also set so the data can be read. In the TCR subroutine an acknowledge or not acknowledge can be programmed to be sent after the byte is received. It is recommended to clear the SBC byte in transmission as there is no use for the byte counter in i²C slave transmitter mode. In SM bus mode slave byte control mode is used in transmission for sending the PEC or packet error code byte. The i²C peripheral provides hardware support for SM bus. The SM bus address resolution protocol is supported through the device default address and arbitration in slave mode. The host notify protocol is supported with host address support. The alert protocol is supported through the SM bus alert pin and alert response address. The SM bus clock low timeout and cumulative clock low extend times can be detected with a programmable duration. The bus idle condition can be detected with a programmable duration. Command and data acknowledge control is supported through slave byte control mode. The packet error code or PEC byte is calculated by hardware. The packet error code or PEC byte is automatically sent in transmission and checked in reception. The data transfer counter initialized with the N bytes value is used to automatically check the PEC byte in reception after N bytes minus 1 byte are received. If the received PEC byte does not match the calculation, a not acknowledge is automatically sent after the PEC byte. In transmission the internally calculated PEC byte is automatically sent after the N bytes minus 1 byte. Slave byte control mode must be enabled in slave mode in order to enable the N bytes counter and allow automatic PEC reception or transmission. Several events can trigger and interrupt. The received buffer not empty flag is set when the received buffer contains received data and is ready to be read. The transmit buffer interrupt status is set when the transmit buffer is empty and is ready to be written. The stop detection flag is set when a stop condition is detected on the bus. The transfer complete reload flag is set when the reload bit is set and N bytes byte of data have been transferred. The transfer complete flag is set when the reload and auto end bits are cleared and N bytes bytes of data have been transferred. The address match flag is set when the received slave address matches one of the enabled slave addresses. The NAC reception flag is set when a not acknowledge is received after a byte transmission. DMA requests can be generated when the received buffer not empty or transmit buffer empty flag is set. Several error flags can be generated. A bus error detection flag is set when a misplaced start or stop condition is detected. The arbitration loss flag is set in the event of an arbitration loss. An overrun or underrun error flag is set in slave mode with clock stretching disabled when an overrun or an underrun error is detected. In SM bus mode, a PEC error flag is set when the received PEC does not match the calculated PEC register content. A timeout error flag is set when a timeout or extended clock timeout is detected. An alert pin detection flag is set in the SM bus host configuration when alert is enabled and a falling edge is detected on the SMBA pin. The I2C peripheral is active in run, low power run, sleep and low power sleep modes. I2C interrupts cause the device to exit sleep or low power sleep modes. Address detection is active in stop modes. The I2C peripheral generates a wake-up interrupt in the event of an address match. In standby and shutdown modes, the peripheral is powered down and must be reinitialized after exiting standby or shutdown mode. For each I2C peripheral, a bit is available for debugging purposes in the MCU debug component that can be used to stop the SM bus timeout counter when the core is halted. Here is an example of a sensor hub application that requires several I2C peripherals. One or several I2C masters are used to interface with external sensors. It is possible to configure the STM32L4 device in low power sleep mode for this purpose in order to reduce power consumption during data transfers. This is called batch acquisition mode. Only the required communication peripheral, plus 1DMA, plus SRAM1 or SRAM2 are configured with the clock enabled in low power sleep mode. The flash memory is put in power down mode and the flash clock is gated off during low power sleep mode. The I2C clock can be at 16 MHz even in low power sleep mode, allowing support for the 1 MHz fast mode plus. An I2C slave is used to communicate with the application processor. The STM32L4 device can be put in stop mode and wakes up only when addressed by the application processor. The STM32L4 devices embed up to 4 I2C peripherals with this full set of features. Wake up from stop 1 mode is supported by all I2C instances. Wake up from stop 2 mode is supported only by I2C3. For more information related to this peripheral, you can also refer to these peripheral trainings. System configuration controller, reset and clock controller, power controller, interrupts controller and direct memory access controller. For more details, please refer to the I2C bus specification and user manual from the NXPE website. The SMBus specification can be found in the smart battery system implementers forum. The PMBus power system management protocol specification can be found in the power management bus implementers forum.