AN1095: What to Do When the I2C Master Does Not Support Clock Stretching

Similar documents
EFM8 Laser Bee Family QSG110: EFM8LB1-SLSTK2030A Quick Start Guide

QSG144: CP2615-EK2 Quick-Start Guide

AN999: WT32i Current Consumption

Translate HCSL to LVPECL, LVDS or CML levels Reduce Power Consumption Simplify BOM AVL. silabs.com Building a more connected world. Rev. 0.

Software Release Note

QSG119: Wizard Gecko WSTK Quick-Start Guide

QSG123: CP2102N Evaluation Kit Quick- Start Guide

QSG114: CPT007B SLEX8007A Kit Quick- Start Guide

EFM8 Universal Bee Family EFM8UB2 Errata

SMBus. Target Bootloader Firmware. Master Programmer Firmware. Figure 1. Firmware Update Setup

UG345: Si72xx Eval Kit User's Guide

AN976: CP2101/2/3/4/9 to CP2102N Porting Guide

Date CET Initials Name Justification

EFM32 Pearl Gecko Family QSG118: EFM32PG1 SLSTK3401A Quick- Start Guide

EFM32 Happy Gecko Family EFM32HG-SLSTK3400A Quick-Start Guide

EFM8 Busy Bee Family EFM8BB2-SLSTK2021A Quick Start Guide

AN125 INTEGRATING RAISONANCE 8051 TOOLS INTO THE S ILICON LABS IDE. 4. Configure the Tool Chain Integration Dialog. 1. Introduction. 2.

Date CET Initials Name Justification

AN0059.1: UART Flow Control

Humidity/Temp/Optical EVB UG

Bluegiga WF111 Software Driver Release Notes

AN1143: Using Micrium OS with Silicon Labs Thread

UG271: CP2615-EK2 User's Guide

AN1139: CP2615 I/O Protocol

UG322: Isolated CAN Expansion Board User Guide

AN1117: Migrating the Zigbee HA Profile to Zigbee 3.0

QSG107: SLWSTK6101A Quick-Start Guide

QSG155: Using the Silicon Labs Dynamic Multiprotocol Demonstration Applications

EFM8 Universal Bee Family EFM8UB1 Errata

8-Bit MCU C8051F85x/86x Errata

CP2103-EK CP2103 EVALUATION KIT USER S GUIDE. 1. Kit Contents. 2. Relevant Documentation. 3. Software Setup USBXpress Driver Development Kit

AN1160: Project Collaboration with Simplicity Studio

EFR32MG13, EFR32BG13 & EFR32FG13 Revision C and Data Sheet Revision 1.0

CP2110-EK CP2110 EVALUATION KIT USER S GUIDE. 1. Kit Contents. 2. Relevant Documentation. 3. Software Setup

EFR32 Mighty Gecko Family EFR32MG1 with Integrated Serial Flash Errata History

UG274: Isolated USB Expansion Board User Guide

CP2104-EK CP2104 EVALUATION KIT USER S GUIDE. 1. Kit Contents. 2. Relevant Documentation. 3. Software Setup USBXpress Driver Development Kit

UG254: CP2102N-MINIEK Kit User's Guide

EFM32 Zero Gecko EFM32ZG Errata

AN1106: Optimizing Jitter in 10G/40G Data Center Applications

UG365: GATT Configurator User s Guide

AN0059.0: UART Flow Control

The process also requires the use of the following files found in the Micriµm Quick Start Package for the FRDM-KL46Z:

µc/probe on the Freescale FRDM-KL05Z without an RTOS

Router-E and Router-E-PA Wireless Router PRODUCT MANUAL

8-bit MCU Family C8051F93x/92x Errata

QSG153: Micrium s μc/probe Tool Quick- Start Guide

CP2105-EK CP2105 EVALUATION KIT USER S GUIDE. 1. Kit Contents. 2. Relevant Documentation. 3. Software Setup USBXpress Driver Development Kit

EFM8 Busy Bee EFM8BB1 Errata

CP2114 Family CP2114 Errata

Figure 1. CP2108 USB-to-Quad UART Bridge Controller Evaluation Board

UG294: CPT213B SLEXP8019A Kit User's Guide

Date CET Initials Name Justification

QSG159: EFM32TG11-SLSTK3301A Quick- Start Guide

WT12 EVALUATION KIT DATA SHEET. Monday, 09 September Version 1.7

UG369: Wireless Xpress BGX13P SLEXP8027A Kit User's Guide

BRD4300B Reference Manual MGM111 Mighty Gecko Module

Software Design Specification

Si1146 UVIRSlider2EK Demo Kit

QSG107: SLWSTK6101A/B Quick-Start Guide

AN324 ADVANCED ENCRYPTION STANDARD RELEVANT DEVICES. 1. Introduction. 2. Implementation Potential Applications Firmware Organization

AN1083: Creating and Using a Secure CoAP Connection with ARM s mbed TLS

EFM32 EFM32GG11 Giant Gecko Family QSG149: EFM32GG11-SLSTK3701A Quick-Start Guide

UG313: Thunderboard Sense 2 Bluetooth Low Energy Demo User's Guide

Figure 1. Precision32 AppBuilder

AN888: EZR32 Quick Start Guide

UG232: Si88xxxISO-EVB User's Guide

ETRX3DVK Development Kit Quick-Start Guide

Termination Options for Any-Frequency Si51x XOs, VCXOs

Not Recommended for New Designs. Si Data Sheet Errata for Product Revision B

QSG107: SLWSTK6101A/B Quick-Start Guide

TS9004 Demo Board FEATURES ORDERING INFORMATION

Figure 1. Traditional Biasing and Termination for LVPECL Output Buffers

FM-DAB-DAB Seamless Linking I2S SRAM. I2C / SPI Host Interface. FLASH Interface MOSI/SDA INTB MISO/A0 RSTB SCLK/SCL SSB/A1 SMODE

USBXpress Family CP2102N Errata

Programming Options for Si5332

UG352: Si5391A-A Evaluation Board User's Guide

Software Design Specification

Si1140-DK. Si1140 DEVELOPMENT KIT USER S GUIDE. 1. Kit Contents. Figure 1. Si1143 Evaluation Board

The Si50122-Ax-EVB is used to evaluate the Si50122-Ax. Table 1 shows the device part number and corresponding evaluation board part number.

AN719 PRECISION32 IDE AND APPBUILDER DETAILED TUTORIAL AND WALKTHROUGH. 1. Introduction. Figure 1. Precision32 IDE and AppBuilder Walkthrough Overview

AGC. Radio DSP 1 ADC. Synth 0 AGC. Radio DSP 2 ADC. Synth 1. ARM Cortex M3 MCU. SPI/I2C Control Interface NVSSB SMODE SSB SCLK NVSCLK INTB

Selector Switch SDA. Pin 1. SCL Pin 2. I2C Bus. Pin 7. Pin 8. Pin 1. Pin 2. Pin 7 Pin 8. Pin 1 Pin 2. Pin 7 Pin 8

UG103.13: Application Development Fundamentals: RAIL

Wireless Development Suite (WDS) is a software utility used to configure and test the Silicon Labs line of ISM band RFICs.

UG366: Bluetooth Mesh Node Configuration User s Guide

AN926: Reading and Writing Registers with SPI and I 2 C

FBOUT DDR0T_SDRAM0 DDR0C_SDRAM1 DDR1T_SDRAM2 DDR1C_SDRAM3 DDR2T_SDRAM4 DDR2C_SDRAM5 DDR3T_SDRAM6 DDR3C_SDRAM7 DDR4T_SDRAM8 DDR4C_SDRAM9 DDR5T_SDRAM10

Software Design Specification

Si7005USB-DONGLE. EVALUATION DONGLE KIT FOR THE Si7005 TEMPERATURE AND HUMIDITY SENSOR. 1. Introduction. 2. Evaluation Kit Description

AN1083: Creating and Using a Secure CoAP Connection with ARM s mbed TLS

AN1119: Using RAIL for Wireless M-Bus Applications with EFR32

QSG126: Bluetooth Developer Studio Quick-Start Guide

AN1006: Differences Between Si534x/8x Revision B and Revision D Silicon

AN0885: EFM8UB Low Energy USB Overview

EFM32 Pearl Gecko Family EFM32PG1 Errata

2. Key Points. F93x F92x F91x F90x. Figure 1. C8051F93x-C8051F90x MCU Family Memory Size Options

QSG166: WF200 Wi-Fi Development Kit Quick Start Guide

UG361: Si70xx Evaluation Tools User's Guide

USB Debug Adapter. Power USB DEBUG ADAPTER. Silicon Laboratories. Stop. Run. Figure 1. Hardware Setup using a USB Debug Adapter

Transcription:

AN1095: What to Do When the I2C Master Does Not Support Clock Stretching The I2C Slave (I2CSLAVE0) interface of EFM8LB1 can support clock stretching for cases where the core may be temporarily prohibited from transmitting a byte or processing a received byte during an I2C transaction, and it can be used during a transfer in order to allow slower slave devices to communicate with faster masters. However, sometimes the host may not support clock stretching and will still try to transfer data through SDA despite the status of the I2C SCL. In this case, the data will be lost or be detected as an invalid value. KEY POINTS Clock stretching introduction. Avoiding the clock stretching caused by WR interrupts with RXTH. Avoiding the clock stretching caused by RD interrupts with TXTH. Generally, the effective way to avoid clock stretching is enhancing the system clock of the MCU to reduce the time the ISR takes to execute, but this method is limited by the maximum speed of the MCU. This document will introduce how to deal with the case where I2C master doesn t support clock stretching by using of RXTH and TXTH in I2C fast plus mode. I2CSLAVE0 Module Data / Address I2C0DIN I2C0DOUT Shift Register SDA I2C0INT State Control Logic Slave Address Recognition SCL Timer 4 SCL Low silabs.com Building a more connected world. Rev. 0.1

Introduction 1. Introduction The I2C peripheral contains separate two-byte FIFOs for RX and TX paths, and the shift registers for I2C Write and Read transfers are also separate. All of the received data will be stored in the RX FIFO, and reading the I2C0DIN register can read data from RX FIFO until RXE is set to 1, indicating that there is no more data in the RX FIFO. All of the transmit data should be transferred into the TX FIFO by writing I2C0DOUT. The hardware sets the TXNF bit to 1, which indicates that there is more room available in the TX FIFO. Using the Receive FIFO Request (RFRQ) and Transmit FIFO Request (TFRQ) interrupts is an effective way to enhance the real-time data processing of the system to avoid clock stretching. The RXTH field of the I2C0FCN0 register will configure when the hardware sets the Receive FIFO Request bit (RFRQ). The RFRQ bit is set whenever the number of bytes in the RX FIFO exceeds the value of RXTH, and if the RFRQE bit be set to 1 at the same time, an I2C0 interrupt will be generated. Similarly, the TXTH field of register I2C0FCN0 configures when hardware will set the Transmit FIFO Request bit (TFRQ). TFRQ is set whenever the number of bytes in the TX FIFO is equal to or less than the value in TXTH, and an I2C0 interrupt will be generated if the TFRQE bit is set to 1. silabs.com Building a more connected world. Rev. 0.1 2

Avoiding the Clock Stretching Caused by WR Interrupts with RXTH 2. Avoiding the Clock Stretching Caused by WR Interrupts with RXTH The I2C Write sequence with the I2C Slave peripheral consists of a series of interrupts and required actions in each interrupt. The write sequence consists of the following steps: 1. Initialize the I2C peripheral and set the RXTH to ZERO, also enabling the RFRQE at the same time. This ensures the Receive FIFO Request (RFRQ) interrupt will be triggered by each receiving byte. 2. An incoming START + Address + W byte causes the peripheral to automatically ACK a matching address if BUSY is cleared to 0. 3. Firmware reads one or more bytes of data from the RX FIFO on each Receive FIFO Request (RFRQ) interrupt. 4. The master sends a STOP when the entire data transfer completes. The FACS bit in register I2C0ADM controls whether I2C0INT will be set (clock stretching also be enforced at the same time) after a matching slave address has been acknowledged. When this bit is set, clock stretching always occurs after an ACK of the address byte until firmware clears the I2C0INT bit. When this bit is cleared, the I2C0INT bit won't be set by the address ACK alone, but it may be set due to RD or WR. This WR bit will only be set by hardware on the 9th SCL falling edge when the RX FIFO is full when the FACS bit is cleared. However, because the receiving byte will be read in time with the Receive FIFO Request (RFRQ) interrupt, the RX FIFO will never be full, and the WR interrupt won t be triggered. The following figure describes the I2C Write sequence and firmware actions in each interrupt. I2C Initial Set RXTH to 0 Idle/Low Power Waiting for Interrupt Interrupt RFRQ Interrupt & RXE!= 1 NO YES DATA received, ACK/NACK sent. 1. Read data from I2C0DIN Clear I2C0INT START+Address+W received? ACK sent. NO YES Clear START YES Repeated Start? NO Stop received. 1. Clear STOP 2. Clear I2C0INT Idle/Low Power Figure 2.1. I2C Write Flow Diagram with the I2C Slave Peripheral silabs.com Building a more connected world. Rev. 0.1 3

Avoiding the Clock Stretching Caused by WR Interrupts with RXTH The following figures show the Fast Plus mode of EFM8LB1 with the I2C master JI-300. The SCL frequency of master JI-300 should be set to 1 Mbps, the duty cycle is 50%, and the default pull-up resistor value is 1 kω. Figure 2.2. Bus Speed Setting of Master JI-300 Figure 2.3. Pullup Resistor Setting of Master JI-300 After setting up the basic environment, a write message can be added to the message List to write 32 bytes to the EFM8LB1 continuously. silabs.com Building a more connected world. Rev. 0.1 4

Avoiding the Clock Stretching Caused by WR Interrupts with RXTH Figure 2.4. Write Message These 32 bytes data will be received by the I2C SLAVE without clock stretching. Figure 2.5. Write 32 Bytes Data without Clock Stretching A GPIO signal can be used to indicate the interrupt processing flow (Blue waveform from the screenshot of oscilloscope). During operation, the Receive FIFO Request (RFRQ) interrupt will be triggered by each receiving byte following the START+ADDRESS+W. The I2C Slave peripheral still can receive another two bytes (1 byte in the FIFO and 1 byte in the shift register) during data processing since the RX FIFO is still not full. silabs.com Building a more connected world. Rev. 0.1 5

Avoiding the Clock Stretching Caused by WR Interrupts with RXTH To ensure the FIFO does not overflow, the maximum data processing time for each byte should be no longer than two byte receiving times (9 x 2 SCL clock) to avoid the hardware setting the WR bit, triggering an I2C0INT interrupt, and clock stretching. If the RXTH field is set to ONE, the receive FIFO request interrupt will be triggered after receiving two bytes following the START+AD- DRESS+W, and the I2C Slave peripheral still can receive another one byte during data processing since the RX shift register is still not full. The advantage of bigger RXTH settings is that fewer I2C interrupts will be triggered; however, the firmware also has less time to process every two data bytes to avoid the clock stretching. From the experiment results, the recommended value of the RXTH field is ZERO to reserve more time to process received data. Figure 2.6. RFRQ Interrupt Processing silabs.com Building a more connected world. Rev. 0.1 6

Avoiding the Clock Stretching Caused by RD Interrupts with TXTH 3. Avoiding the Clock Stretching Caused by RD Interrupts with TXTH The I2C Read sequence with the I2C Slave peripheral consists of the following steps: 1. Initialize the I2C peripheral and set the TXTH to ONE, enabling the TFRQE bit at the same time. This ensures the Transmit FIFO Request (TFRQ) interrupt will be triggered whenever the number of bytes in the TX FIFO is equal to or less than ONE. 2. Firmware fills the TX FIFO on each Transmit FIFO Request (TFRQ) interrupt until the TX FIFO is full. 3. After receiving an incoming START + Address + R byte, the I2C peripheral will automatically ACK a matching address if BUSY is cleared to 0. 4. A Transmit FIFO Request (TFRQ) interrupt occurs after one byte is shifted from the TX FIFO to the shift register. The firmware will fill the TX FIFO until the TX FIFO is full or all of the ready data is written into the FIFO. 5. The master sends a NACK when the current data transfer completes and either a repeated START or STOP. 6. The master sends a STOP when the entire data transfer completes. 7. Firmware clears the STOP interrupt and reloads the TX FIFO, if necessary. The following figure describes the I2C Read sequence and firmware actions in each interrupt. I2C Initial Set TXTH to 1 Waiting for Interrupt Interrupt TFRQ Interrupt & TXNF? NO YES YES ACK? NO DATA sent, ACK received. 1. Write next data to I2C0DOUT DATA sent, NACK received. 1. Clear NACK Address + R received, ACK sent. 1. Clear START and RD YES Repeated Start? NO Stop received. 1. Clear STOP 2. Reload data to TX FIFO 3. Clear I2C0INT Idle/Low Power Figure 3.1. I2C Read Flow Diagram with the I2C Slave Peripheral silabs.com Building a more connected world. Rev. 0.1 7

Avoiding the Clock Stretching Caused by RD Interrupts with TXTH The following figure is the scope capture of 32 bytes of data read from the I2C SLAVE without clock stretching. After initializing the I2C Slave and setting the TXTH field to ONE with TFRQE enabled, the Transmit FIFO Request (TFRQ) interrupt will be triggered, and firmware will fill the TX FIFO with the available data until the FIFO is full. After receiving START+ADDRESS+R, and the first byte in the TX FIFO is shifted to the shift register. When the number of bytes in the TX FIFO equals the value in TXTH, the Transmit FIFO Request (TFRQ) will be triggered again. There is still one byte in the TX FIFO during firmware processing of the transmitted data, and the maximum processing time should no longer than the transmitting time of 2 bytes (1 remaining byte in the TX FIFO and 1 byte in the shift register). Figure 3.2. Read 32 Bytes of Data Without Clock Stretching silabs.com Building a more connected world. Rev. 0.1 8

Avoiding the Clock Stretching Caused by RD Interrupts with TXTH Figure 3.3. Read Data Without Clock Stretching The master will send a STOP when the entire data transfer completes, the interrupt will be triggered, and firmware should reload the data into the TX FIFO on the STOP interrupt. silabs.com Building a more connected world. Rev. 0.1 9

Avoiding the Clock Stretching Caused by RD Interrupts with TXTH The following figure displays the TX FIFO structure of the I2C slave peripheral. This FIFO consists of 2 bytes and a 1-byte shift register. The data in the first FIFO byte will be shifted to the shift register when a read occurs. For example, if there are 31 bytes be transmitted from the I2C slave to the master successfully before STOP, and the 32 nd byte has been shifted to the shift register, the TX FIFO can be filled with the 33 rd and 34 th bytes. The 32 nd byte in the shift register will be flushed by the 33 rd byte in the TX FIFO when the next read occurs, and 32 nd byte will be lost during the data transfer. Because of this, it is necessary to flush and reload the TX FIFO with the previous bytes after receiving the STOP interrupt. FIFO 34 33 SHIFT 32 Figure 3.4. TX FIFO & SHIFT Register After flushing and reloading, the 32 nd and 33 rd bytes will exist in the TX FIFO to avoid losing one byte. FIFO SHIFT 33 32 Figure 3.5. Flush and Reload TX FIFO The following figure demonstrates this result of continuous reading and writing without losing data. Figure 3.6. Continuous Reading and Writing Without Data Loss silabs.com Building a more connected world. Rev. 0.1 10

Software Example 4. Software Example An I2C slave example called [EFM8LB1_I2C_Slave_FIFO] is included in the 8-bit SDK that demonstrates using the RXTH and TXTH fields to avoid clock stretching. This example can be found in Simplicity Studio (www.silabs.com/simplicity). silabs.com Building a more connected world. Rev. 0.1 11

Smart. Connected. Energy-Friendly. Products www.silabs.com/products Quality www.silabs.com/quality Support and Community community.silabs.com Disclaimer Silicon Labs intends to provide customers with the latest, accurate, and in-depth documentation of all peripherals and modules available for system and software implementers using or intending to use the Silicon Labs products. Characterization data, available modules and peripherals, memory sizes and memory addresses refer to each specific device, and "Typical" parameters provided can and do vary in different applications. Application examples described herein are for illustrative purposes only. Silicon Labs reserves the right to make changes without further notice and limitation to product information, specifications, and descriptions herein, and does not give warranties as to the accuracy or completeness of the included information. Silicon Labs shall have no liability for the consequences of use of the information supplied herein. This document does not imply or express copyright licenses granted hereunder to design or fabricate any integrated circuits. The products are not designed or authorized to be used within any Life Support System without the specific written consent of Silicon Labs. A "Life Support System" is any product or system intended to support or sustain life and/or health, which, if it fails, can be reasonably expected to result in significant personal injury or death. Silicon Labs products are not designed or authorized for military applications. Silicon Labs products shall under no circumstances be used in weapons of mass destruction including (but not limited to) nuclear, biological or chemical weapons, or missiles capable of delivering such weapons. Trademark Information Silicon Laboratories Inc., Silicon Laboratories, Silicon Labs, SiLabs and the Silicon Labs logo, Bluegiga, Bluegiga Logo, Clockbuilder, CMEMS, DSPLL, EFM, EFM32, EFR, Ember, Energy Micro, Energy Micro logo and combinations thereof, "the world s most energy friendly microcontrollers", Ember, EZLink, EZRadio, EZRadioPRO, Gecko, ISOmodem, Micrium, Precision32, ProSLIC, Simplicity Studio, SiPHY, Telegesis, the Telegesis Logo, USBXpress, Zentri and others are trademarks or registered trademarks of Silicon Labs. ARM, CORTEX, Cortex-M3 and THUMB are trademarks or registered trademarks of ARM Holdings. Keil is a registered trademark of ARM Limited. All other products or brand names mentioned herein are trademarks of their respective holders. Silicon Laboratories Inc. 400 West Cesar Chavez Austin, TX 78701 USA http://www.silabs.com