I 2 C Master Control FSM. I 2 C Bus Control FSM. I 2 C Master Controller

Similar documents
Each I2C master has 8-deep transmit and receive FIFOs for efficient data handling. SPI to Dual I2C Masters. Registers

I 2 C Slave Controller. I 2 C Master o_timeout_intr

UART Register Set. UART Master Controller. Tx FSM. Rx FSM XMIT FIFO RCVR. i_rx_clk o_intr. o_out1 o_txrdy_n. o_out2 o_rxdy_n i_cs0 i_cs1 i_ads_n

LED1 LED2. Capacitive Touch Sense Controller LED3 LED4

i_csn i_wr i_rd i_cpol i_cpha i_lsb_first i_data [15:0] o_data [15:0] o_tx_ready o_rx_ready o_rx_error o_tx_error o_tx_ack o_tx_no_ack

Reference Design RD1065

ice40 Ultra Self-Learning IR Remote User s Guide

IDE/ATA Interface Controller with WISHBONE

Enhanced Closed-loop Trim with I 2 C Control for Platform Manager Devices

ice40lm Barcode Emulation Solution Control Registers and Data Buffer

MDIO Master and Slave Controllers

AvnetCore: Datasheet

VORAGO VA108x0 I 2 C programming application note

Parallel to MIPI CSI-2 TX Bridge

Gamma Corrector IP Core User Guide

BSCAN2 Multiple Scan Port Linker

8b/10b Encoder/Decoder

Tutorial for I 2 C Serial Protocol

It is well understood that the minimum number of check bits required for single bit error correction is specified by the relationship: D + P P

Introduction to I2C & SPI. Chapter 22

McMaster University Embedded Systems. Computer Engineering 4DS4 Lecture 6 Serial Peripherals Amin Vali Feb. 2016

Real-Time Embedded Systems. CpE-450 Spring 06

Speedster22i sbus Interface User Guide UG047, October 24, 2013

LatticeECP2/M Soft Error Detection (SED) Usage Guide

White Paper Using the MAX II altufm Megafunction I 2 C Interface

Importing HDL Files with Platform Manager 2

isplever Multi-Channel DMA Controller User s Guide February 2006 ipug11_04.0

Dual Boot and Background Programming with Platform Manager 2

FPGA Implementation Of SPI To I2C Bridge

Lattice USB Type-C Solution Design Document

LatticeXP2 Soft Error Detection (SED) Usage Guide

THANG LUONG CAO. Serial bus adapter design for FPGA. Master of Science Thesis

Basics of UART Communication

THE INTERNATIONAL JOURNAL OF SCIENCE & TECHNOLEDGE

Lecture 25 March 23, 2012 Introduction to Serial Communications

DESIGNING OF INTER INTEGRATED CIRCUIT USING VERILOG

PCI to SH-3 AN Hitachi SH3 to PCI bus

Introduction the Serial Communications Parallel Communications Parallel Communications with Handshaking Serial Communications

Median Filter IP Core User s Guide

User-configurable Resolution. 9 to 12 bits (0.5 C to C)

Parallel Data Transfer. Suppose you need to transfer data from one HCS12 to another. How can you do this?

AN-895 APPLICATION NOTE

An Efficient Designing of I2C Bus Controller Using Verilog

Block Diagram. mast_sel. mast_inst. mast_data. mast_val mast_rdy. clk. slv_sel. slv_inst. slv_data. slv_val slv_rdy. rfifo_depth_log2.

Application Note: AZD025 IQ Switch - ProxSense TM Series I2C Example Code for the IQS222

Microtronix Avalon I 2 C

Fibre Channel Arbitrated Loop v2.3

Serial Peripheral Interface. What is it? Basic SPI. Capabilities. Protocol. Pros and Cons. Uses

MachXO2 SED Usage Guide

Handson Technology. I2C Specification and Devices. 1

Discontinued IP. OPB IIC Bus Interface (v1.01d) Introduction. Features. LogiCORE Facts

LatticeSC MACO Core LSCDR1X18 Low-Speed Clock and Data Recovery User s Guide

Theory of Operation STOP CONDITION

RM24C64AF 64-Kbit 1.65V Minimum Non-volatile Fast Write Serial EEPROM I 2 C Bus

CprE 488 Embedded Systems Design. Lecture 4 Interfacing Technologies

CoolRunner XPLA3 SMBus Controller Implementation

SPI 3-Wire Master (VHDL)

I 2 C Bus Interface - Slave ver 3.08

icecube2 Software Release Notes

Byte-to-Pixel Converter IP User Guide

Lecture 5: Computing Platforms. Asbjørn Djupdal ARM Norway, IDI NTNU 2013 TDT

HDS Series I2C Application Notes

EECS150 - Digital Design Lecture 17 Memory 2

MachXO2 Low Power Control Demo User s Guide

How to Implement I 2 C Serial Communication Using Intel MCS-51 Microcontrollers

Hello, and welcome to this presentation of the STM32 Universal Synchronous/Asynchronous Receiver/Transmitter Interface. It covers the main features

Interfacing the NM24C16 Serial EEPROM to the microcontroller. Interfacing the NM24C16 Serial EEPROM to the 8031 Microcontroller AN-957

LatticeSC/M Family flexipcs Data Sheet. DS1005 Version 02.0, June 2011

ice40 SPRAM Usage Guide Technical Note

CoreHPDMACtrl v2.1. Handbook

Virtex-5 GTP Aurora v2.8

CoolRunner CPLD I 2 C Bus Controller Implementation

Section 16. Basic Sychronous Serial Port (BSSP)

Part 1 Using Serial EEPROMs

Level Shifter. for. Hardware User s Manual.

SD Card Controller IP Specification

Fail-Safe Startup Sequencing During Field Upgrades with Platform Manager

I2C Master-Slave Connection

Generic Serial Flash Interface Intel FPGA IP Core User Guide

DESIGN AND IMPLEMENTATION OF I2C SINGLE MASTER ON FPGA USING VERILOG

Lattice Memory Mapped Interface and Lattice Interrupt Interface User Guide

ATC-AD8100K. 8 Channel 100 khz Simultaneous Burst A/D in 16 bits IndustryPack Module REFERENCE MANUAL Version 1.

SILICON MICROSTRUCTURES

Color Space Converter

Lesson I2C. I²C (Inter-Integrated Circuit) Lab Assignment: I2C Slave Driver

Design and development of embedded systems for the Internet of Things (IoT) Fabio Angeletti Fabrizio Gattuso

User-configurable Resolution. 9 to 12 bits (0.5 C to C)

GT34C02. 2Kb SPD EEPROM

AvnetCore: Datasheet

Microcontroller basics

The EFM32 I2C module allows simple, robust and cost effective communication between integrated circuits using only one data and one clock line.

1 Contents 2 2 Overview 3 3 Hardware Interface 4 4 Software Interface Register Map Interrupts 6 5 Revision History 8

PCI Express Throughput Demo Verilog Source Code User s Guide

PCI Express Multi-Channel DMA Interface

F28335 I2C MODULE v1.1

Digital UART Product Specification

ADPCM-LCO Voice Compression Logic Core

Tech Spec for SDXC Host Controller

Inter-Integrated Circuit Bus IIC I2C TWI

Design of an Efficient FSM for an Implementation of AMBA AHB in SD Host Controller

Transcription:

February 2015 Introduction Reference Design RD1139 I 2 C or Inter-Integrated Circuit is a popular serial interface protocol that is widely used in many electronic systems. The I 2 C interface is a two-wire interface capable of half-duplex serial communication at moderate to high speeds of up to a few megabits per second. There are thousands of I 2 C peripherals on the market today, ranging from data converters to video processors. The I 2 C bus is a good choice for designs that need to communicate with low-speed peripherals due to its simplicity and low cost. The I 2 C Master Controller reference design is implemented in Verilog. The Lattice icecube2 Place and Route tool integrated with the Lattice Synthesis Engine (LSE) tool is used for the implementation of the design. The design uses an ice40 ultra low density FPGA and can be targeted to other ice40 family members. Features 7-bit slave address support Supports operation at 100 khz (Standard Mode) and 400 khz (Fast Mode) Supports repeated start operations Interrupt generation logic Verilog RTL, test bench Functional Description Figure 1. Block Diagram i_clk i_rst_n o_int_n i_slave_address_reg i_byte_cnt_reg I 2 C Master Control FSM SBIO SDA i_clk_div_lsb i_config_reg io_sda Processor Interface i_mode_reg i_slave_addr_reg o_cmd_status_reg I 2 C Bus Control FSM SBIO SCL io_scl I 2 C Slave i_transmit_data o_transmit_data_req o_received_data_valid o_receive_data I 2 C Master Controller 2015 Lattice Semiconductor Corp. All Lattice trademarks, registered trademarks, patents, and disclaimers are as listed at www.latticesemi.com/legal. All other brand or product names are trademarks or registered trademarks of their respective holders. The specifications and information herein are subject to change without notice. www.latticesemi.com 1 RD1139_1.1

Pin Descriptions Table 1. Pin Descriptions Signal Width Type Description i_clk 1 Input System clock operating at 32 MHz i_rst_n 1 Input Asynchronous active-low system reset o_int_n 1 Output Active-low processor interrupt i_slave_addr_reg 8 Input 7-bit I 2 C slave address i_byte_cnt_reg 8 Input Design Modules The design includes the modules shown in Figure 2. Figure 2. Functional Block Diagram Sets the number of data bytes to be read or written for the I 2 C transaction i_clk_div_lsb 8 Input Sets the lower byte of the clock divider that is used to generate SCL from CLK. The upper three bits are located in the mode register. i_config_reg 6 Input Used to configure the I 2 C Master Controller (see Table 1) i_mode_reg 8 Input Sets the various modes of operation like speed, read/write (see Table 1) o_cmd_status_reg 8 Output Lets the user know the status of the operation, I 2 C bus (see Table 1) o_start_ack 1 Output Acknowledge to the start bit provided by the user through i_config_reg i_transmit_data 8 Input Data to be transmitted over the SDA line to the I 2 C slave o_transmit_data_requested 1 Output Lets the user know that transmit data is required o_received_data_valid 1 Output A 1 corresponds to valid data availability on the o_receive_data line o_receive_data 8 Output Received data bus io_scl 1 Inout I 2 C clock line io_sda 1 Inout I 2 C data line Clock Generator Clock Synchronizer Tx Data FSM Rx Data FSM Start Generate Logic Stop Detect Logic I 2 C Master Control FSM Acknowledge Generate Detect Logic Filter I 2 C Bus Control FSM 2

I 2 C Bus Control FSM I 2 C Master Controller The I 2 C Bus Control FSM is comprised of the Clock Generator/Synchronizer, Start/Stop generate/detect logic and Acknowledge generate/detect logic. The Clock Generation and Synchronization logic generates the I 2 C clock signal SCL, based on the system clock and clock divide factors configured by the processor. Due to the nature of the I 2 C bus, the actual SCL clock that is seen by all devices on the bus may not be running at the same frequency that the master generates. This module starts counting its SCL low period when the current master drives SCL low. Once a device s clock has gone low, the master holds the SCL line low until the clock high state is reached. When all devices have counted off their LOW period, the clock line will be released and goes HIGH. There will then be no difference between the device clocks and the state of the SCL line, and all the devices will start counting their HIGH periods. The first device to complete its HIGH period will again pull the SCL line LOW. In this way, a synchronized SCL clock is generated with its LOW period determined by the device with the longest clock LOW period, and its HIGH period determined by the one with the shortest clock HIGH period. The start/stop logic generates and detects start and stop events on the I 2 C bus. The detection of start and stop events is necessary to determine whether or not the I 2 C bus is in use by another master on the bus when the primary master gets a START signal from the processor. When the I 2 C bus is idle, both SCL and SDA are pulled high by passive pull-ups. A start condition is signalled by transitioning SDA from high to low while SCL is still high. Likewise, a stop condition is signalled by transitioning SDA from low to high while SCL is high. I 2 C Master Control FSM For controlling data transfer, the I 2 C master makes use of a control FSM, along with counters for controlling the bits and bytes. The byte counter is an 8-bit counter that keeps track of the number of bytes that have been written or read during the I 2 C transaction. This counter increments after each byte has been written to or read from the external I 2 C slave device. The count is then compared with the byte count register. If the value is a match, the I 2 C Master Controller considers the transaction complete, issues a stop signal on the I 2 C bus, asserts the RXTX_DONE flag and waits for the next transaction to be initiated from the processor. This counter is fully controlled by the main control FSM. Internal Register Map The I 2 C Master Controller configuration can be performed on run-time. Table 2 lists the registers available to the user. Table 2. Register List Port/Bit 7 6 5 4 3 2 1 0 i_slave_addr_reg SADR[6] SADR[5] SADR[4] SADR[3] SADR[2] SADR[1] SADR[0] i_byte_cnt_reg BCNT[7] BCNT[6] BCNT[5] BCNT[4] BCNT[3] BCNT[2] BCNT[1] BCNT[0] i_clk_div_lsb DIV[7] DIV[6] DIV[5] DIV[4] DIV[3] DIV[2] DIV[1] DIV[0] i_config_reg RESET ABORT TX_IE RX_IE INT_CLR START i_mode_reg BPS[1] BPS[0] ACK_POL RW_MODE DIV[10] DIV[9] DIV[8] o_cmd_status_reg I2C_BUSY TX_DONE RX_DONE TX_ERR RX_ERR ABORT_ACK Unimplemented Undefined 3

Register Bit Descriptions Table 3. Register Bit Descriptions Register Bit i_slave_addr_reg[7:0] I_byte_cnt_reg[7:0] i_clk_div_lsb[7:0] i_config_reg[5] RESET i_config_reg[4] - ABORT i_config_reg[3] - TX_IE i_config_reg[2] - RX_IE i_config_reg[1] - INT_CLR i_config_reg[0] - START i_mode_reg[7:6] - BPS[1:0] i_mode_reg[4] - ACK_POL i_mode_reg[3] i_mode_reg[2:0] o_cmd_status_reg[7] o_cmd_status_reg[6] - TX_DONE o_cmd_status_reg[5] - RX_DONE 7-bit slave address Description I 2 C Master Controller Sets the number of data bytes to be written or read for the I 2 C transaction. For example, set the register to 8 to transfer eight data bytes. Sets the lower byte of the clock divider that is used to generate SCL from CLK. The upper three bits are located in the Mode Register. Please note that DIV[0] is not used since only even DIV values are supported. Writing a 1 will reset this I 2 C Master Controller. Writing a 1 will stop the current I 2 C transaction in progress. This bit is cleared by the ABORT_ACK status bit in the Command Status Register. Set this bit high to enable interrupt generation on transmit completion and a STOP is issued, or on any error. Set this bit high to enable interrupt generation on receive completion and a STOP is issued, or on any error. Writing a 1 will clear all bits in the Command Status Register except the I2C_BUSY bit. Write a 0 to clear this bit. Write a 1 to start an I 2 C transaction. This bit is auto-cleared after the master has successfully arbitrated and acquired the I 2 C bus. Selects the I 2 C speed mode (2 b00 = standard, 2 b01 = fast, others are reserved) Sets the behavior of ACK during the last byte of a master read transaction. This bit should be 0 for ACK and 1 for NACK. If a repeat START is not used, this bit should be set to 1 (NACK) for I 2 C compliance. RW_MODE Sets the read or write operation on the I 2 C bus ( 0 = write, 1 = read) DIV[10:8] The upper three bits of the clock divide facto I2C_BUSY This read-only status bit indicates that the bridge is busy performing a data transaction and a STOP has not been issued. This bit reflects the state of the I 2 C bus and cannot be cleared by the user. This read-only status bit indicates that the I 2 C write operation issued has been completed, but the STOP condition may still be in progress. This read-only status bit indicates that the I 2 C read operation issued has been completed, but the STOP condition may still be in progress. o_cmd_status_reg[4] - TX_ERR This read-only status bit indicates that an error has occurred during the I 2 C write operation. o_cmd_status_reg[3] - RX_ERR This read-only status bit indicates that an error has occurred during the I 2 C read operation. o_cmd_status_reg[2] - ABORT_ACK This read-only status bit indicates that the ABORT command has been completed. The user should clear the proper FIFO and status bits afterwards. Note that all status bits, except I2C_BUSY, are cleared by writing a 1 to the INTR_CLR bit in the configuration 3egister. 4

Timing Diagram Figure 3 shows the timing diagram for read and write data transfer to the I 2 C Master Controller. Figure 3. Timing Diagram for Read and Write Data Transfer i_clk o_transmit_data_requested i_transmit_data Write Data o_received_data_valid o_receive_data Read Data Operation Sequence The operation sequence for transmit, receive and repeated start is illustrated below. I 2 C Master Transmit Operation Figure 4 illustrates the basic transmit operation of the I 2 C Master Controller. Note that S is notation for START and P is notation for STOP. By writing a 1 to the START bit of the configuration register, the operation is started. Figure 4. Master Transmit Operation ARB S Address ACK First Byte ACK Last Byte ACK P START I2C_BUSY TX_DONE O_INIT_N The I2C_BUSY bit will go high before the START bit is cleared to indicate an active I 2 C transaction. 1. The I2C_BUSY bit will clear itself after the entire I 2 C transaction is complete and the bus is idled. 2. The TX_DONE signal is asserted after the last byte of transmit data has been sent, but the STOP condition may not have completed yet. 3. I2C_BUSY is cleared after the STOP condition has completed and the bus is idled. 4. The interrupt is asserted if the transmit interrupt enable bit (TX_IE) is set. 5. If the slave device did not assert ACK, then TX_ERR and INT_N will both be asserted. 5

I 2 C Master Receive Operation Figure 5 illustrates the basic receive operation of the I 2 C Master Controller. Figure 5. Master Receive Operation ARB S Address ACK First Byte ACK Last Byte ACK P START I2C_BUSY RX_DONE O_INIT_N 1. By writing a 1 to the START bit of the configuration register, the operation is started. 2. The I2C_BUSY bit will go high before the START bit is cleared to indicate an active I 2 C transaction. The I2C_BUSY bit will clear itself after the entire I 2 C transaction is complete and the bus is idled. 3. The RX_DONE signal is asserted after the last byte of receive data have been latched, but the STOP condition may not have completed yet. 4. I2C_BUSY is cleared after the STOP condition has completed and bus is idled. 5. The interrupt is asserted if the receiver interrupt enable bit (RX_IE) is set. 6. If the slave device did not assert ACK during the address phase, then RX_ERR and INT_N will both be asserted. Repeated Start Transactions To overcome the limited addresses provide by the I 2 C bus, some I 2 C slaves uses repeated start transactions to allow indirect access of internal registers. The I 2 C Master Controller supports the generation of repeat start transactions. Figure 6 illustrates a typical repeat start I 2 C transaction. Note that SR is the I 2 C notation for a repeated start. Figure 6. Repeated Start Operation ARB S Address ACK Write Byte ACK SR Same ACK Read Byte NACK P START I2C_BUSY TX_Done RX_DONE O_INIT_N 6

By writing a 1 to the START bit of the configuration register, the operation is started. 1. The initial parts of sequence are identical to the set-up for a normal read or write transaction shown earlier. 2. To perform a repeated start transaction, the user needs to update the Byte Count Register, Mode Register, and finally the configure register is written with 1 for the START bit. Note that the second START command needs to be issued before the TX_DONE /RX_DONE phase of the first transaction. 3. Do not change the slave address for the repeated START transaction; otherwise, a STOP is generated and another full transaction is executed. 4. I2C_BUSY is cleared after the STOP condition is complete and the bus is idled. HDL Simulation Figure 7. HDL Simulation Waveform Figure 8. Simulation Waveform Showing the START Bit of the Configuration Register and Acknowledge Bit 7

Figure 9. Timing Waveforms Showing Config_reg START and Rx Bits Along with Cmd_status_reg TX_Done and I2C_Busy Bits Figure 10. Simulation Timing Diagram Showing Transmit and Receive Operations Implementation This design is implemented in Verilog. When using this design in a different device, density, speed or grade, performance and utilization may vary. Table 4. Performance and Resource Utilization Device Family Language Synthesis Tool References DS1040, ice40 LP/HX Family Data Sheet Technical Support Assistance e-mail: techsupport@latticesemi.com Internet: www.latticesemi.com Utilization (LUTs) fmax (MHz) I/Os Architecture Resources LSE 295 113.55 65 N/A ice40 1 Verilog Syn Pro 282 77.52 65 N/A 1. Performance utilization characteristics are generated using ice40lp1k-cm121 with icecube2 2014.08 design software. 8

Revision History Date Version Change Summary February 2015 1.1 October 2012 01.0 Updated Introduction section. Changed Synplify Pro to Lattice Synthesis Engine (LSE). Updated Implementation section. Updated Table 4, Performance and Resource Utilization. Changed Utilization (LUTs) value. Updated References section. Updated Technical Support Assistance information. Initial release. 9