Design UART Loopback with Interrupts

Similar documents
Programming the 8032 MCU Core

8032 MCU + Soft Modules. c = rcvdata; // get the keyboard scan code

Designing Your Own Soft Modules

Logic Design With Soft Modules

Using Keil Development Tools with Triscend FastChip and the E5 CSoC Family

Rapidly Developing Embedded Systems Using Configurable Processors

MCS-51 Serial Port A T 8 9 C 5 2 1

CoE3DJ4 Digital Systems Design. Chapter 5: Serial Port Operation

Computer System Overview. Chapter 1

Programming in the MAXQ environment

Lab 3a: Scheduling Tasks with uvision and RTX

Computer System Overview

Operating Systems: Internals and Design Principles, 7/E William Stallings. Chapter 1 Computer System Overview

Interrupt/Timer/DMA 1

Maxim > Design Support > Technical Documents > Application Notes > Microcontrollers > APP 4465

Revolutionary Quad-Pipelined Ultra High Performance 16/32-bit Microcontroller v. 6.05

Figure 1. Proper Method of Holding the ToolStick. Figure 2. Improper Method of Holding the ToolStick

Chapter 2. Overview of Architecture and Microcontroller-Resources

Programmed I/O Interrupt-Driven I/O Direct Memory Access (DMA) I/O Processors. 10/12/2017 Input/Output Systems and Peripheral Devices (02-2)

Triscend E5 Configurable System-on-Chip Platform

NEW CEIBO DEBUGGER. Menus and Commands

MPLAB SIM. MPLAB IDE Software Simulation Engine Microchip Technology Incorporated MPLAB SIM Software Simulation Engine

Project Debugging with MDK-ARM

_ V Intel 8085 Family In-Circuit Emulation. Contents. Technical Notes

B.H.GARDI COLLEGE OF MASTER OF COMPUTER APPLICATION

Zylogic ZE5 Configurable System-on-Chip Platform

Introduction to Embedded Systems

ARM ARCHITECTURE. Contents at a glance:

Configurable Embedded Systems: Using Programmable Logic to Compress Embedded System Design Cycles

Microprocessors and Microcontrollers (EE-231)

An Interrupt is either a Hardware generated CALL (externally derived from a hardware signal)

DEVICE DRIVERS AND TERRUPTS SERVICE MECHANISM Lesson-15: Writing Device Driving ISRs in a System

CONNECTING YOUR PC TO THE USB EVALUATION BOARD

Fredrick M. Cady. Assembly and С Programming forthefreescalehcs12 Microcontroller. шт.

DoCD IP Core. DCD on Chip Debug System v. 6.02

e-pg Pathshala Subject: Computer Science Paper: Embedded System Module: Interrupt Programming in Embedded C Module No: CS/ES/20 Quadrant 1 e-text

Note that FLIP is an Atmel program supplied by Crossware with Atmel s permission.

8051 Serial Communication

Interrupts in Zynq Systems

Lecture 10. Serial Communication

These three counters can be programmed for either binary or BCD count.

Chapter 1 Computer System Overview

Class 413. Rapidly Developing Embedded Systems Using Configurable Processors

Software Serial Port Implemented with the PCA

8051 Microcontroller Interrupts

By the end of Class. Outline. Homework 5. C8051F020 Block Diagram (pg 18) Pseudo-code for Lab 1-2 due as part of prelab

MICROPROCESSOR BASED SYSTEM DESIGN

Development Tools. 8-Bit Development Tools. Development Tools. AVR Development Tools

SYLLABUS UNIT - I 8086/8088 ARCHITECTURE AND INSTRUCTION SET

1. Attempt any three of the following: 15

Computer System Overview OPERATING SYSTEM TOP-LEVEL COMPONENTS. Simplified view: Operating Systems. Slide 1. Slide /S2. Slide 2.

Computer System Overview

MCU: Interrupts and Timers. Ganesh Pitchiah

Module 3. Embedded Systems I/O. Version 2 EE IIT, Kharagpur 1

FR Family MB Emulator System Getting Started Guide

DQ8051. Revolutionary Quad-Pipelined Ultra High performance 8051 Microcontroller Core

Input / Output. School of Computer Science G51CSA

Computer Systems Overview

Chapter 4. Enhancing ARM7 architecture by embedding RTOS

Debugging in AVR32 Studio

UNIT II PROCESSOR AND MEMORY ORGANIZATION

DEVELOPMENT OF A DEBUG MODULE FOR A FPGA-BASED MICROCONTROLLER. Rainer Bermbach, Martin Kupfer

Figure 1. Proper Method of Holding the ToolStick. Figure 2. Improper Method of Holding the ToolStick

Input/Output Problems. External Devices. Input/Output Module. I/O Steps. I/O Module Function Computer Architecture

Course Introduction. Purpose: Objectives: Content: 27 pages 4 questions. Learning Time: 20 minutes

TN0132 Technical note

Chapter 1 Computer System Overview

Integrated Device Technology, Inc Stender Way, Santa Clara, CA Phone #: (408) Fax #: (408) Errata Notification

Quick Start Guide for the Turbo upsd DK3300-ELCD Development Kit- RIDE

Using programmed I/O on the M16C; and Writing an Interrupt Service Routine (ISR)

Chapter 7 Central Processor Unit (S08CPUV2)

Keil uvision development story (Adapted from (Valvano, 2014a))

CHAPTER 11 INTERRUPTS PROGRAMMING

UNIT V MICRO CONTROLLER PROGRAMMING & APPLICATIONS TWO MARKS. 3.Give any two differences between microprocessor and micro controller.

ECEN 4613/5613 Embedded System Design Week #6 Spring 2018 Homework #6

Figure 1. Proper Method of Holding the ToolStick. Figure 2. Improper Method of Holding the ToolStick

Understanding the basic building blocks of a microcontroller device in general. Knows the terminologies like embedded and external memory devices,

Interrupts and Using Them in C

Top-Level View of Computer Organization

I/O Devices & Debugging. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

8-bit Microcontroller. Application Note. AVR134: Real-Time Clock (RTC) using the Asynchronous Timer. Features. Theory of Operation.

MPLAB X Debugging Techniques

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 09, SPRING 2013

Architecture of 8085 microprocessor

Section 31. DMA Controller

Introduction to the Altera SOPC Builder Using Verilog Designs. 1 Introduction

DS-251 In-Circuit Emulator

Unit 3 and Unit 4: Chapter 4 INPUT/OUTPUT ORGANIZATION

NIOS CPU Based Embedded Computer System on Programmable Chip

Hello, and welcome to this presentation of the STM32 I²C interface. It covers the main features of this communication interface, which is widely used

Microprocessors & Interfacing

8086 Interrupts and Interrupt Responses:


In examining performance Interested in several things Exact times if computable Bounded times if exact not computable Can be measured

Interrupts (I) Lecturer: Sri Notes by Annie Guo. Week8 1

ECAN TM (Polling) Module

The Embedded Computing Platform

AT09381: SAM D - Debugging Watchdog Timer Reset. Introduction. SMART ARM-based Microcontrollers APPLICATION NOTE

CLD SC58x CDC Library v.1.00 Users Guide Users Guide Revision For Use With Analog Devices ADSP-SC58x Series Processors. Closed Loop Design, LLC

April 4, 2001: Debugging Your C24x DSP Design Using Code Composer Studio Real-Time Monitor

Transcription:

Once the E is displayed, will the 0 reappear if you return the DIP switch to its OFF position and re-establish the loopback path? Usually not. When you break the loopback path, it will most likely truncate the string of eleven bits comprised of the start bit, eight data bits forming the counter value, the programmable ninth data bit, and the stop bit. If the UART receiver doesn't receive a complete transmission, it will not set its interrupt flag (RI). If RI is never set, then the program will loop forever on line 17 waiting for the interrupt flag to be set. Therefore, no more transmissions are initiated and the display updates cease. Design 2.3 - UART Loopback with Interrupts The previous design has the drawback that the program gets stuck in a polling loop once the loopback path is interrupted. The example design in this section fixes that problem by using interrupts from the UART. 2000 by XESS Corp. 120

Start this design by opening the Chap22 project with FastChip and then save it as Chap23. You don't have to change any of the hardware interconnections, but you do have to enable the 8032 MCU interrupts and the UART interrupts. Click on the Interrupts button in the Dedicated Resources area of the FastChip project window. In the Interrupt Controller window that appears, click on the Enable all interrupts checkbox. Then click on OK to finalize this change. 2000 by XESS Corp. 121

To enable the specific interrupt from the UART, click on the UART button in the Dedicated Resources area and then click on the Enable UART Interrupt checkbox in the 8032 UART window. In addition to this, click on the Enable Receiver checkbox. This will move the enabling of the UART to the initialization subroutine so you don't have to do it explicitly at the beginning of the main() routine (see line 11 of Listing 3). Then click on OK to close the window. Once you have made these changes to the hardware, you can generate the header file that links the CSoC hardware and software. Start the coding for the application software as in the previous designs examples by creating a keil folder in the Chap23 FastChip project folder. Then start the Keil IDE and type the code from Listing 4 into a new window. The main() routine on lines 9 13 initializes the MCU peripherals and then enters an infinite loop (line 12). All the real work is performed by the interrupt handler on lines 15 29. This handler is activated when interrupt 4 occurs. What is interrupt 4? Table 8 lists the various interrupt identifiers associated with the various sources of interrupts in the 8032 MCU. Interrupt 4 is associated with the UART. So the UART_ISR() routine is called whenever the UART transmitter or receiver generates an interrupt. Lines 17 21 handle interrupts from the UART receiver whenever it receives a byte of data (as indicated by the RI flag being set). The value in the receiver buffer is stored in the rcvcnt variable on line 19. Line 20 clears the receiver interrupt flag. 2000 by XESS Corp. 122

Lines 22 28 take care of UART transmitter interrupts that occur when the transmitter has finished sending a byte of data (as indicated by the TI flag being set). On lines 24 25, the last value received by the UART is compared to the last value transmitted. The LED digit displays 0 if the values match (line 24). If the values don't match, the LED digit displays E and the error counter is incremented (line 25). Then the transmitter value is incremented and loaded into the transmitter buffer on line 26. The transmitter interrupt flag is cleared on line 27. Why does the interrupt handler compare the transmitted and received values when a transmitter interrupt occurs and not a receiver interrupt? If the loopback path is broken, no more receiver interrupts occur so any comparisons in the receiver portion of the interrupt handler would never be executed. But the transmitter keeps pumping out data even when the loopback path is broken so the transmitted and received values are always compared and the results are recorded and displayed. Therefore, the status display never stalls. Once you have the code typed in, save it in the keil folder as chap23.c. Then create a new Keil project called chap23 and add the chap23.c file to it. Set the compiler and linker options as you did in the previous designs and then build the chap23.hex file. Return to the FastChip project window and do a binding operation on the Chap23 project. Then download the hardware configuration and the chap23.hex file to the CSoC Board. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 Listing 4: C application code for the Interrupt-driven UART loopback design. #include "..\Chap23.h" #define LETTERE 0x79 #define LETTERO 0x3F unsigned char txcnt=0, rcvcnt=0; unsigned int errcnt = 0; main() { Chap23_INIT(); // initialize on-chip resources while(1) ; // wait while interrupt services run } static void UART_ISR(void) interrupt 4 using 0 { if(ri) { rcvcnt = SBUF; RI = 0; // clear the receiver interrupt } if(ti) { if(rcvcnt==txcnt) ledport=lettero; 2000 by XESS Corp. 123

25 26 27 28 29 } } else {ledport=lettere; errcnt++;} SBUF = ++txcnt; TI = 0; // clear the transmitter interrupt Table 8: Keil interrupt identifiers for the 8032 MCU in the Triscend CSoC. Interrupt source Interrupt Id External Interrupt 0 0 Timer 0 Overflow 1 External Interrupt 1 2 Timer 1 Overflow 3 Serial Port 4 Timer 2 Interrupt 5 High-Priority Interrupt 6 DMA 7 Hardware Breakpoint 8 JTAG 9 Software Breakpoint 10 Watchdog Timer 12 Now that your CSoC Board is loaded with the loopback hardware and application code, click on the Run dscope Debugger menu item in the Keil IDE to start the debugger. Select the 8032-te5.dll entry in the drop-down list near the top of the dscope window and establish the debugging link with the CSoC Board by clicking on OK in the TCP/IP Configuration window. Next click on the Reset button in the Toolbox window. Then load the debugging information from the chap23 OMF file into dscope with the File Load object file menu item. Before starting the interrupt-driven UART loopback program, lower DIP switch #1 into its OFF position to establish the loopback connection. Then click on Go! or the button in the Module window and the program starts executing. You should see 0 on the LED digit, indicating that the receiver is getting the bits sent by the transmitter. Then flip DIP switch #1 to its ON position and you should see an E displayed on the LED digit as the 2000 by XESS Corp. 124

loopback path is broken. Finally, lower DIP switch #1 to re-establish the loopback connection and the 0 will return to the LED digit. So your program now indicates the current status of the loopback path and doesn't get stuck waiting to receive data which never arrives. How can you check the number of transmission errors recorded in the errcnt variable in your program? The easiest way is to get dscope to query the value of errcnt through the JTAG debugging interface. Begin by clicking on Setup Watchpoints in the dscope window. This will cause the Watchpoints window to appear. Click on the Symbols button in the Watchpoints window to bring up the window that shows all the variable names in your program. Click on the Publics radio button in the Symbols window and then scroll down in the list until you find the errcnt variable. Click and drag the errcnt variable over to the Expr: box in the Watchpoints window. 2000 by XESS Corp. 125

Next, click on the Define watch button and the errcnt variable will be added to the list of current items to watch. Click on Close to remove the Watchpoints window. Now the debugger is set-up to watch the value of the errcnt variable. dscope will query the value through the JTAG interface whenever you halt the program. Click on the Stop! button and then press the Reset button. Make sure DIP switch #1 is in the OFF position. Then click on Go! to start your loopback program from the beginning. The LED should display 0 indicating that the loopback path is in place. Now if you click on Stop! to halt the program, dscope will fetch the errcnt value from the 8032 MCU and display it in the Watch window as shown below. (If the Watch window is not visible, click on View Watch window in the dscope window.) The Watch window reports the errcnt variable is set to zero. This makes sense since no transmission errors should have occurred yet. Now click on Go! to resume execution of the loopback program. Raise DIP switch #1 and then lower it after approximately one second. Then click on Stop! and the Watch 2000 by XESS Corp. 126

window will show the number of transmission errors that occurred during the onesecond break in the loopback path. Does this number make sense? The 8032 MCU is running at 25 MHz and the UART is in mode 2 so it transmits a single bit every 64 clock cycles = 2.56 µs. Each byte transmission consists of eleven bits (a start bit, eight data bits, one programmable data bit, and a stop bit) over an interval of 28.2 µs. So a one-second interruption in the loopback path will cause 1 s / 28.2 µs = 35,500 errors. The Watch window reports errcnt = 0x7555 = 30,037 which is pretty close given that you have to manually open and close the DIP switch. Design 2.4-8032 MCU Memory Tester Your last MCU-based design in this chapter will test the external SRAM chip on the CSoC Board. It will use the same hardware configuration as the first design (Figure 11). The MCU will determine the segment of SRAM to test by reading the DIP switch settings through port P0. Then the MCU will write a pseudo-random series of bytes to the SRAM segment and read it back to see if it was stored correctly. Finally, the result of the test is displayed on the LED digit. Address Translation in the Triscend CSoC In order to understand how the SRAM testing program works, you need to know how the CSoC assists the 8032 MCU with memory accesses. The CSoC has a 32-bit CSI address bus that is used to selectively access various components of the internal circuitry (registers in the CSL, DMA controllers, etc.) or external devices (e.g., memory devices connected to the MIU). But the 8032 MCU uses 16-bit addresses. In order for the MCU to be able to access all the circuitry inside and outside the CSoC, address mappers are provided that translate the 16-bit logical addresses into full 32-bit physical addresses. An address mapper uses three parameters to control the translation process: 2000 by XESS Corp. 127