UART. ELEC 418 Advanced Digital Systems Dr. Ron Hayne. Images Courtesy of Cengage Learning

Similar documents
SERIAL COMMUNICATION BY USING UART

Sequential Logic - Module 5

SCI Serial Communication Interface

The University of Alabama in Huntsville ECE Department CPE Midterm Exam Solution Spring 2016

VHDL in 1h. Martin Schöberl

The University of Alabama in Huntsville Electrical and Computer Engineering CPE/EE 422/522 Spring 2005 Homework #6 Solution


Summary of FPGA & VHDL

Design Examples. ELEC 418 Advanced Digital Systems Dr. Ron Hayne. Images Courtesy of Cengage Learning

Control Unit: Binary Multiplier. Arturo Díaz-Pérez Departamento de Computación Laboratorio de Tecnologías de Información CINVESTAV-IPN

Corrections for Digital Systems Design Using VHDL, 3rd printing

VHDL Testbench. Test Bench Syntax. VHDL Testbench Tutorial 1. Contents

Codec. WM8731 Audio Codec

A B C D E F 0480 FE B F5 3B FC F3 E 1A 1D 2A 2D 3A 3D 4A 4D 5A 5D 6A 6D 7A 7D

VHDL. ELEC 418 Advanced Digital Systems Dr. Ron Hayne. Images Courtesy of Cengage Learning

Test Benches - Module 8

MAX 10. Memory Modules

1. Specifications Functions Used Operation Software Flowcharts Program Listing... 13

VHDL And Synthesis Review

8-1. Fig. 8-1 ASM Chart Elements 2001 Prentice Hall, Inc. M. Morris Mano & Charles R. Kime LOGIC AND COMPUTER DESIGN FUNDAMENTALS, 2e, Updated.

Quartus Counter Example. Last updated 9/6/18

Counters. Counter Types. Variations. Modulo Gray Code BCD (Decimal) Decade Ring Johnson (twisted ring) LFSR

VHDL for Modeling - Module 10

Problem Set 10 Solutions

DIGITAL LOGIC DESIGN VHDL Coding for FPGAs Unit 6

Example 58: Traffic Lights

In our case Dr. Johnson is setting the best practices

EL 310 Hardware Description Languages Midterm

[VARIABLE declaration] BEGIN. sequential statements

Timing in synchronous systems

Review for Exam 3. Write 0x05 to ATD0CTL4 to set at fastest conversion speed and 10-bit conversions

Dallas Semiconductor DS1307 Real Time Clock. The DS 1307 is a real-time clock with 56 bytes of NV (nonvolatile)

8-1. Fig. 8-1 ASM Chart Elements 2001 Prentice Hall, Inc. M. Morris Mano & Charles R. Kime LOGIC AND COMPUTER DESIGN FUNDAMENTALS, 2e, Updated.

The block diagram representation is given below: The output equation of a 2x1 multiplexer is given below:

Multiplication Simple Gradeschool Algorithm for 16 Bits (32 Bit Result)

MCPU - A Minimal 8Bit CPU in a 32 Macrocell CPLD.

Asynchronous Data Transfer

COVER SHEET: Total: Regrade Info: 5 (14 points) 7 (15 points) Midterm 1 Spring 2012 VERSION 1 UFID:

DIGITAL LOGIC WITH VHDL (Fall 2013) Unit 6

The University of Alabama in Huntsville ECE Department CPE Midterm Exam Solution March 2, 2006

CS/ECE 5780/6780: Embedded System Design

EENG 2910 Project III: Digital System Design. Due: 04/30/2014. Team Members: University of North Texas Department of Electrical Engineering

Very High Speed Integrated Circuit Har dware Description Language

APPLICATION NOTE CPLDs

Example 15: Moving Sprites with Flash Background

Lecture 4: Modeling in VHDL (Continued ) EE 3610 Digital Systems

3 Designing Digital Systems with Algorithmic State Machine Charts

constant reg_init: std_logic_vector(11 downto 0):=" ";

Experiment 0 OR3 Gate ECE 332 Section 000 Dr. Ron Hayne June 8, 2003

ECE/CS 5780/6780: Embedded System Design

Synthesis from VHDL. Krzysztof Kuchcinski Department of Computer Science Lund Institute of Technology Sweden

Design Problem 5 Solutions

EEL 4712 Digital Design Test 1 Spring Semester 2007

EE 3170 Microcontroller Applications

ECE 545 Lecture 8. Data Flow Description of Combinational-Circuit Building Blocks. George Mason University

The University of Alabama in Huntsville ECE Department CPE Final Exam Solution Spring 2004

Symbolically the RS-Latch that is being simulated is the one shown below, it s truth table is also given:

Design Problem 4 Solutions

FSM Components. FSM Description. HDL Coding Methods. Chapter 7: HDL Coding Techniques

Lecture 12 VHDL Synthesis

6.111 Lecture # 8. Topics for Today: (as time permits)


VHDL Modeling Behavior from Synthesis Perspective -Part B - EL 310 Erkay Savaş Sabancı University

Exercise: how can we do?

Understand the design and operation of the SCI and the I 2 C, IrDA and Smart Card interfaces

COE 405, Term 062. Design & Modeling of Digital Systems. HW# 1 Solution. Due date: Wednesday, March. 14

Lattice VHDL Training

Test Bench. Top Level Model Test Bench MUT

Constructing VHDL Models with CSA

RTL Design. Gate-level design is now rare! RTL = Register Transfer Level

DESCRIPTION OF DIGITAL CIRCUITS USING VHDL

Luleå University of Technology Kurskod SMD152 Datum Skrivtid

EEL 4712 Digital Design Test 1 Spring Semester 2008

CSE 260 Introduction to Digital Logic and Computer Design. Exam 1. Your name 2/13/2014

Problem Set 5 Solutions

Schedule. ECE U530 Digital Hardware Synthesis. Rest of Semester. Midterm Question 1a

VHDL. Chapter 7. Behavioral Modeling. Outline. Behavioral Modeling. Process Statement

COVER SHEET: Total: Regrade Info: 1 (8 points) 2 ( 8 points) 3 (16 points) 4 (16 points) 5 (16 points) 6 (16 points) 7 (16 points) 8 (8 points)

VHDL. Official Definition: VHSIC Hardware Description Language VHISC Very High Speed Integrated Circuit

HCS12 Serial Communications Interface (SCI) Block Guide V02.06

Lecture 5: State Machines, Arrays, Loops. EE 3610 Digital Systems

Sequential Statement

IT T35 Digital system desigm y - ii /s - iii

AN Multifunction Serial Interface of FM MCU. Contents. 1 Introduction

ENGR 5865 DIGITAL SYSTEMS

CSE 260 Digital Computers: Organization and Logical Design. Exam 2. Jon Turner 3/28/2012

VHDL Simulation. Testbench Design

Concurrent & Sequential Stmts. (Review)

CMPT 250: Computer Architecture. Using LogicWorks 5. Tutorial Part 1. Somsubhra Sharangi

Sign here to give permission for your test to be returned in class, where others might see your score:

The CPU Bus : Structure 0

Modeling Complex Behavior

Universal Asynchronous Receiver Transmitter (UART ) CSCE 612 Project #2 Specification

Lecture 27. Structural Description of a 3-Bit Synchronous Decade Counter. FIGURE 4.31 A State diagram of a decade counter.

Introduction to Computer Design

ECEU530. Schedule. ECE U530 Digital Hardware Synthesis. Datapath for the Calculator (HW 5) HW 5 Datapath Entity

Hierarchy of I/O Control Devices

Symbolically a D-Latch can be represented as so, it s truth table is also given:

VHDL Testbench Design. Textbook chapters 2.19, , 9.5

13/06/56 8 ก ก. 08-Case Study

Transcription:

UART ELEC 418 Advanced Digital Systems Dr. Ron Hayne Images Courtesy of Cengage Learning

UART Universal Asynchronous Receiver Transmitter Serial Data Transmission

68HC11 Microcontroller UART Registers RSR Receive Shift Register RDR Receive Data Register TDR Transmit Data Register TSR Transmit Shift Register SCCR Serial Communications Control Register SCSR Serial Communications Status Register UART Flags TDRE Transmit Data Register Empty RDRF Receive Data Register Full

UART Block Diagram

Transmitter Operation Microcontroller waits until TDRE = '1' Loads data into TDR Clears TDRE UART transfers data from TDR to TSR Sets TDRE UART outputs start bit ('0') then shifts TSR right eight times followed by a stop bit ('1')

Transmitter SM Chart

Transmitter VHDL Model library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity UART_Transmitter is port(bclk, sysclk, rst_b, TDRE, loadtdr: in std_logic; DBUS: in unsigned(7 downto 0); settdre, TxD: out std_logic); end UART_Transmitter;

Transmitter VHDL Model architecture xmit of UART_Transmitter is type statetype is (IDLE, SYNCH, TDATA); signal state, nextstate: statetype; signal TSR: unsigned(8 downto 0); signal TDR: unsigned(7 downto 0); signal Bct: integer range 0 to 9; signal inc, clr, loadtsr, shfttsr, start: std_logic; signal Bclk_rising, Bclk_Dlayed: std_logic; begin TxD <= TSR(0); settdre <= loadtsr; Bclk_rising <= Bclk and (not Bclk_Dlayed);

Transmitter VHDL Model Xmit_Control: process(state, TDRE, Bct, Bclk_rising) begin inc <= '0'; clr <= '0'; loadtsr <= '0'; shfttsr <= '0'; start <= '0'; case state is when IDLE => if (TDRE = '0') then loadtsr <= '1'; nextstate <= SYNCH; else nextstate <= IDLE; end if;

Transmitter VHDL Model when SYNCH => if (Bclk_rising = '1') then start <= '1'; nextstate <= TDATA; else nextstate <= SYNCH; end if; when TDATA => if (Bclk_rising = '0') then nextstate <= TDATA; elsif (Bct /= 9) then shfttsr <= '1'; inc <= '1'; nextstate <= TDATA; else clr <= '1'; nextstate <= IDLE; end if; end case; end process;

Transmitter VHDL Model Xmit_update: process(sysclk, rst_b) begin if (rst_b = '0') then TSR <= "111111111"; state <= IDLE; Bct <= 0; Bclk_Dlayed <= '0'; elsif (sysclk'event and sysclk = '1') then state <= nextstate; if (clr = '1') then Bct <= 0; elsif (inc = '1') then Bct <= Bct + 1; end if;

Transmitter VHDL Model if (loadtdr = '1') then TDR <= DBUS; end if; if (loadtsr = '1') then TSR <= TDR & '1'; end if; if (start = '1') then TSR(0) <= '0'; end if; if (shfttsr = '1') then TSR <= '1' & TSR(8 downto 1); end if; Bclk_Dlayed <= Bclk; end if; end process; end xmit;

Receiver Operation UART waits for start bit Shifts bits into RSR When all data bits and stop bit are received RSR loaded into RDR Set RDRF Microcontroller waits until RDRF is set Read RDR Clear RDRF

Sampling RxD

Receiver SM Chart

Receiver VHDL Model library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity UART_Receiver is port(rxd, BclkX8, sysclk, rst_b, RDRF: in std_logic; RDR: out unsigned(7 downto 0); setrdrf, setoe, setfe: out std_logic); end UART_Receiver;

Receiver VHDL Model architecture rcvr of UART_Receiver is type statetype is (IDLE, START_DETECTED, RECV_DATA); signal state, nextstate: statetype; signal RSR: unsigned(7 downto 0); signal ct1 : integer range 0 to 7; signal ct2 : integer range 0 to 8; signal inc1, inc2, clr1, clr2, shftrsr, loadrdr: std_logic; signal BclkX8_Dlayed, BclkX8_rising: std_logic; begin BclkX8_rising <= BclkX8 and (not BclkX8_Dlayed);

Receiver VHDL Model Rcvr_Control: process(state, RxD, RDRF, ct1, ct2, BclkX8_rising) begin inc1 <= '0'; inc2 <= '0'; clr1 <= '0'; clr2 <= '0'; shftrsr <= '0'; loadrdr <= '0'; setrdrf <= '0'; setoe <= '0'; setfe <= '0'; case state is when IDLE => if (RxD = '0') then nextstate <= START_DETECTED; else nextstate <= IDLE; end if;

Baud Rate Generator Select Bits BAUD Rate 000 38,462 001 19,231 010 9615 011 4808 100 2404 101 1202 110 601 111 300.5

VHDL Model entity clk_divider is port(sysclk, rst_b: in std_logic; Sel: in unsigned(2 downto 0); BclkX8: buffer std_logic; Bclk: out std_logic); end clk_divider; architecture baudgen of clk_divider is signal ctr1: unsigned(3 downto 0) := "0000"; -- divide by 13 counter signal ctr2: unsigned(7 downto 0) := "00000000"; -- div by 256 ctr signal ctr3: unsigned(2 downto 0) := "000"; -- divide by 8 counter signal Clkdiv13: std_logic;

VHDL Model begin process(sysclk) -- first divide system clock by 13 begin if (Sysclk'event and Sysclk = '1') then if (ctr1 = "1100") then ctr1 <= "0000"; else ctr1 <= ctr1 + 1; end if; end if; end process; Clkdiv13 <= ctr1(3);

VHDL Model process(clkdiv13) -- ctr2 is an 8-bit counter begin if (Clkdiv13'event and Clkdiv13 = '1') then ctr2 <= ctr2 + 1; end if; end process; BclkX8 <= ctr2(to_integer(sel)); -- MUX process(bclkx8) begin if (BclkX8'event and BclkX8 = '1') then ctr3 <= ctr3 + 1; end if; end process; Bclk <= ctr3(2); end baudgen;

Complete UART entity UART is port(sci_sel, R_W, clk, rst_b, RxD: in std_logic; ADDR2: in unsigned(1 downto 0); DBUS: inout unsigned(7 downto 0); SCI_IRQ, TxD, RDRF_out, Bclk_out, TDRE_out: out std_logic); end UART; architecture uart1 of UART is component UART_Receiver port(rxd, BclkX8, sysclk, rst_b, RDRF: in std_logic; RDR: out unsigned(7 downto 0); setrdrf, setoe, setfe: out std_logic); end component;

Complete UART component UART_Transmitter port(bclk, sysclk, rst_b, TDRE, loadtdr: in std_logic; DBUS: in unsigned(7 downto 0); settdre, TxD: out std_logic); end component; component clk_divider port(sysclk, rst_b: in std_logic; Sel: in unsigned(2 downto 0); BclkX8: buffer std_logic; Bclk: out std_logic); end component;

Complete UART signal RDR, SCSR, SCCR: unsigned(7 downto 0); signal TDRE, RDRF, OE, FE, TIE, RIE: std_logic; signal BaudSel: unsigned(2 downto 0); signal settdre, setrdrf, setoe, setfe, loadtdr, loadsccr: std_logic; signal clrrdrf, Bclk, BclkX8, SCI_Read, SCI_Write: std_logic; begin RCVR: UART_Receiver port map(rxd, BclkX8, clk, rst_b, RDRF, RDR, setrdrf, setoe, setfe); XMIT: UART_Transmitter port map(bclk, clk, rst_b, TDRE, loadtdr,dbus, settdre, TxD); CLKDIV: clk_divider port map(clk, rst_b, BaudSel, BclkX8, Bclk);

Microcontroller Interface Memory-Mapped I/O ADDR2 R_W Action 00 0 DBUS RDR 00 1 TDR DBUS 01 0 DBUS SCSR 01 1 DBUS hi-z 1-0 DBUS SCCR 1-1 SCCR DBUS

UART Test Bench entity UART_test is end UART_test; architecture test1 of UART_test is component UART port(sci_sel, R_W, clk, rst_b, RxD: in std_logic; ADDR2: in unsigned(1 downto 0); DBUS: inout unsigned(7 downto 0); SCI_IRQ, TxD, RDRF_out, Bclk_out, TDRE_out: end component; out std_logic); signal SCI_sel, R_W, clk, rst_b, RxD, SCI_IRQ, TxD, RDRF, Bclk, TDRE: std_logic := '0'; signal ADDR2: unsigned(1 downto 0); signal DBUS: unsigned(7 downto 0);

UART Test Bench begin uart1: UART port map (SCI_sel, R_W, clk, rst_b, RxD, ADDR2, DBUS, SCI_IRQ, TxD, RDRF, Bclk, TDRE); clk <= not clk after 50 ns; process begin wait for 120 ns; rst_b <= '1'; SCI_sel <= '1'; DBUS <= "10000000"; ADDR2 <= "10"; R_W <= '1'; wait for 100 ns;

UART Test Bench DBUS <= "01101001"; ADDR2 <= "00"; wait for 100 ns; R_W <= '0'; wait until TDRE = '1'; DBUS <= "00111100"; R_W <= '1'; wait for 100 ns; R_W <= '0'; wait until TDRE = '1'; DBUS <= "10101010"; R_W <= '1'; wait for 100 ns; R_W <= '0'; wait; end process; end test1;

ModelSim Simulation

ModelSim Simulation

Loop-Back Test RxD <= TxD; process begin wait for 120 ns; report "Begin Testing"; rst_b <= '1'; SCI_sel <= '1'; -- Set SCCR DBUS <= "10000000"; ADDR2 <= "10"; R_W <= '1'; wait for 100 ns; -- Load TDR DBUS <= "01101001"; ADDR2 <= "00"; wait for 100 ns; DBUS <= "ZZZZZZZZ"; R_W <= '0'; wait until RDRF = '1'; assert DBUS = "01101001" report "Test Failed"; report "Testing Complete"; wait;

Loop-Back Test

Summary Universal Asynchronous Receiver Transmitter Transmitter Receiver Baud Rate Generator VHDL Models ModelSim Simulation