Faculty of Engineering and Information Technology Embedded Software. Lab 1 Tower Serial Communications

Similar documents
Faculty of Engineering and Information Technology Embedded Software. Lab 3 Interrupts and Timers

Interrupts Peter Rounce - room 6.18

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

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

Embedded Systems and Software

Interrupts Peter Rounce

School of Computer Science Faculty of Engineering and Computer Science Student ID Number. Lab Cover Page. Lab Date and Time:

Embedded Systems and Software. Serial Communication

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

YOU WILL NOT BE ALLOWED INTO YOUR LAB SECTION WITHOUT THE REQUIRED PRE-LAB.

COMP2121: Microprocessors and Interfacing

UART (Universal Asynchronous Receiver-Transmitter)

Basics of UART Communication

Digital Input and Output

Serial Communications

The MMDVM Specification ( )

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

AN-895 APPLICATION NOTE

PD215 Mechatronics. Week 3/4 Interfacing Hardware and Communication Systems

Event Device Drivers. Release rc1

Embedded Systems. Read pages

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

UART Implementation Using the N2HET

I/O Organization John D. Carpinelli, All Rights Reserved 1

Nios Embedded Processor UART Peripheral

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

Emulating Dual SPI Using FlexIO

COMP 273 Winter asynchronous I/O April 5, 2012

Laboratory 5 Communication Interfaces

INTRODUCTION TO FLEXIO

COMP asynchronous buses April 5, 2016

Multifunction Serial Interface (PDL_MFS) Features. General Description. When to Use a PDL_MFS Component. Quick Start 1.0

To be familiar with the USART (RS-232) protocol. To be familiar with one type of internal storage system in PIC (EEPROM).

AN10955 Full-duplex software UART for LPC111x and LPC13xx

Operating systems and concurrency B02

SPART. SPART Design. A Special Purpose Asynchronous Receiver/Transmitter. The objectives of this miniproject are to:

4Serial SIK BINDER //77

University of Texas at El Paso Electrical and Computer Engineering Department. EE 3176 Laboratory for Microprocessors I.

Serial Peripheral Interface Bus SPI

In the HEW, open a new project by selecting New workspace from the main menu.

TMS470R1x Serial Communication Interface (SCI) Reference Guide

Concepts of Serial Communication

Using FlexIO to emulate communications and timing peripherals

NS9360. Errata _F. Release date: March 2008

Using UART in radio data transmission with the CDP-02 module By Tomihiko Uchikawa

UART Design Example. User Guide. 04/2014 Capital Microelectronics, Inc. China

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

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

Microcontroller basics

RPC Interface Specification November 2001 Introduction

ECE251: Thursday November 8

Lab 13 Real Time Debugging

INTRODUCTION OF MICROPROCESSOR& INTERFACING DEVICES Introduction to Microprocessor Evolutions of Microprocessor

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

EDBG. Description. Programmers and Debuggers USER GUIDE

Synchronous = SPI (3 options)

USER GUIDE EDBG. Description

I Introduction to Real-time Applications By Prawat Nagvajara

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

PC Interrupt Structure and 8259 DMA Controllers

CSE380 - Operating Systems. Communicating with Devices

NS9750B-0. Use in conjunction with: Errata , Rev G. Release date: May Phone: Web:

Rochester Institute of Technology CMPE 663/EEEE 663 Graduate Student Project

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

or between microcontrollers)

Design and Implementation Interrupt Mechanism

AN-1435 APPLICATION NOTE

_äìé`çêé» UART Host Transport Summary. February 2004

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

Unit 19 - Serial Communications 19.1

Serial I-O for Dinesh K. Sharma Electrical Engineering Department I.I.T. Bombay Mumbai (version 14/10/07)

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

AN HI-3200 Avionics Data Management Engine Evaluation Board Software Guide

CoE3DJ4 Digital Systems Design. Chapter 5: Serial Port Operation

Application Note, V1.0, Jul AP XC16x. Interfacing the XC16x Microcontroller to a Serial SPI EEPROM. Microcontrollers

EE 354 November 13, 2017 ARM UART Notes

Software Serial Port Implemented with the PCA

ECE251: Thursday September 27

Mechatronics Laboratory Assignment 2 Serial Communication DSP Time-Keeping, Visual Basic, LCD Screens, and Wireless Networks

CAN / RS485. Product Description. Technical Reference Note. Interface Adapter. Special Features

Programming in the MAXQ environment

Input/Output Programming

Modes of Transfer. Interface. Data Register. Status Register. F= Flag Bit. Fig. (1) Data transfer from I/O to CPU

Interrupts in Zynq Systems

Infineon C167CR microcontroller, 256 kb external. RAM and 256 kb external (Flash) EEPROM. - Small single-board computer (SBC) with an

ECE/CS 5780/6780: Embedded System Design

4 Multiplexer. Y Fig Keyboard Scan Matrix

Document Conventions nc. Page 2-4, 2.1.6: While MCBASE normally points to external RAM, it is permissible to set it up that some or all BDs will actua

Interfacing a Hyper Terminal to the Flight 86 Kit

Design And Implementation Of USART IP Soft Core Based On DMA Mode

Asynchronous Transmission. Asynchronous Serial Communications & UARTS

ICN12. I2C to UART Bridge, ADC,DAC and I/O

Introduction to ARM LPC2148 Microcontroller

Project Final Report Internet Ready Refrigerator Inventory Control System

Engineer-to-Engineer Note

AN Sleep programming for NXP bridge ICs. Document information

Product Technical Brief S3C2440X Series Rev 2.0, Oct. 2003

19.1. Unit 19. Serial Communications

Device: MOD This document Version: 1.0. Matches module version: v3 [29 June 2016] Date: 23 October 2017

Serial Communication

Transcription:

Faculty of Engineering and Information Technology Subject: 48434 Embedded Software Assessment Number: 1 Assessment Title: Lab 1 Tower Serial Communications Tutorial Group: Students Name(s) and Number(s) Student Number Family Name First Name Declaration of Originality: The work contained in this assignment, other than that specifically attributed to another source, is that of the author(s). It is recognised that, should this declaration be found to be false, disciplinary action could be taken and the assignments of all students involved will be given zero marks. In the statement below, I have indicated the extent to which I have collaborated with other students, whom I have named. Statement of Collaboration: Signature(s) key Assessment Submission Receipt Assessment Title: Lab 1 Tower Serial Communications Mark Student Name(s): Date Submitted: Tutor Signature: Office use only

Assessment Criteria Your lab will be assessed according to the following criteria: Item Detail Evaluation Mark Opening comments File headers are correct. G A P /0.5 Function descriptions Naming conventions Code structure UART functions Packet functions implementation Protocol implementation Function descriptions are appropriate and correct. Names conform to the Software Style Guide. Code structure conforms to the Software Style Guide. All control register bits are set individually. Baud rate set correctly. Correct use of s. Polling is correct. Packet functionality is correct. Errors are handled correctly. Functionally correct, easy to modify (read) and efficient. Protocol response is correct, including ACK/NAK. G A P /0.5 G A P /0.5 G A P /0.5 G A P /1 G A P /1 G A P /2 G A P /2 TOTAL /8 Evaluation When we evaluate an assessment item, we will use the following criteria: G = All relevant material is presented in a logical manner showing clear understanding, and sound reasoning. For software - evidence of correct coding style, efficient implementation and / or novel (and correct) code. A = Most relevant material is presented with acceptable organisation and understanding. For software some code may be prone to errors under certain operating conditions (e.g. input parameters) or usage, style may have inconsistent sections, occasional inefficient or incorrect code. P = Little relevant material is presented and/or code displays poor organisation or understanding of the underlying concepts. Oral Defence During the demonstration session you will be asked a number of questions based on material which you have learnt in the subject and then used to implement the assignment. You are expected to know exactly how your implementation works and be able to justify the design choices which you have made. If you fail to answer the questions with appropriate substance then you will be awarded zero for that component.

L1.1 Lab 1 Tower Serial Communications Port access. UART initialization. Polling. Circular buffer. Packet decoding. Introduction The Universal Asynchronous Receiver / Transmitter (UART) is a simple yet extremely important peripheral of the K70 microcontroller. On the Tower board it is connected to a serial-to-usb chip that enables the board to communicate to a PC running Windows 7. The Tower board is to implement the serial communication protocol as outlined in the separate document entitled Tower Serial Communication Protocol. Objectives 1. To set up a UART on a microcontroller. 2. To implement a circular buffer in the C language. 3. To decode and respond to packets according to a defined protocol. Equipment 1 TWR-K70F120M-KIT 1 USB cable NXP Kinetis Design Studio Safety This is a Category A laboratory experiment. Please adhere to the Category A safety guidelines (issued separately). Cat. A lab

L1.2 Software Overview The serial communication between the Tower board and the PC uses 5-byte packets. The task of the Tower software is to receive and send packets of information asynchronously. This is a classic producer-consumer problem. One solution to the asynchronous nature of the communication is to implement a first-in first-out () buffer between the producer and consumer. This is shown diagrammatically below: Data flow graph showing two s that buffer data between producers and consumers consumer UART_InChar Rx_Get Rx Rx_Put producer RDRF Set UART input Packet producer Tx_Put UART_OutChar Tx Tx_Get consumer TDRE Set UART output UART interrupt or polling Figure L1.1 A simple (but inefficient) way of handling the asynchronous nature of the UART communication is to check the status of the UART hardware repeatedly by calling a function in the main loop of the program that polls the status of the UART, and calls Rx_Put or Tx_Get as required.

L1.3 Receiving Data When the packet module wishes to receive input, it calls UART_InChar, which will attempt to get data from the Rx (it will fail if the buffer is empty). How does data get in the Rx? The incoming serial data will set the Receive Data Register Full (RDRF) flag in the UART Status Register 1 (UART_S1) register, indicating that the receiver hardware has just received a byte of data. In the main loop, a poll of the RDRF flag is performed. If it is set, then the program tries to accept the data and put it in the Rx. The Rx buffers data between the input hardware and the main program that processes the data. If the Rx becomes full, then data will be lost. This is illustrated below: In this lab, the receive interrupt service routine is replaced by a polling operation RDRF set Read data from input InChar A queue can be used to pass data between an input device and a main thread _Put _Get yes full? empty? yes no Put buffer no Get Error Return data to caller Error return return Figure L1.2 full errors will always occur if the average input rate (number of bytes arriving per second from the input hardware) exceeds the average processing rate (number of bytes processed per second by the main program). In this situation, either the output rate must be increased (by using a faster computer

L1.4 or by writing a better software processing algorithm), or the input rate must be decreased (by slowing down the arrival rate of data). The second way the Rx could become full is if there is a temporary increase in the arrival rate or a temporary decrease in the processing rate. For this situation, the full errors could be eliminated by increasing the size of the Rx. It is inefficient, but not catastrophic, for the main program to wait on an empty Rx in some cases. Efficiency can be improved for the buffered input problem by performing other tasks while waiting for data. Sending Data When the packet module wishes to output, it calls UART_OutChar, which will put the data in the Tx and arm the output device. In this lab, the transmit interrupt service routine is replaced by a polling operation The setting of the Transmit Data Register Empty (TDRE) flag by the UART hardware signals that the output shift register is idle and ready to output more data. In the main loop, a poll of the TDRE flag is performed. If it is set, then the program tries to retrieve the data in the Tx., and send it out the serial port. If the Tx becomes empty, then no data will be sent out the serial port. This is illustrated below: A queue can be used to pass data between a main thread and an output device _Put OutChar TDRE set _Get yes full? empty? yes no Put buffer no Get Error Write data to output Error return return Figure L1.3

L1.5 It is inefficient, but not catastrophic, for the main program to wait on a full Tx. Efficiency can be improved for the buffered output problem by increasing the Tx size. Software Modules Various modules should be written to support the serial communication protocol. Software module dependency main only to configure peripheral and pin functions PORTE_PCR16 PORTE_PCR17 SIM_SCGC4 SIM_SCGC5 packet UART only UART_Poll UART2_C1 UART2_C2 UART2_C3 UART2_C4 UART2_C5 UART2_BDH UART2_BDL UART2_MODEM UART2_D UART2_S1 UART2_S2 Figure L1.4

L1.6 Software Requirements 1. The serial-to-usb bridge uses UART2. The baud rate is to be 38400 baud, with an 8N1 frame. You are required to set/clear individual bits in the UART s control registers, based on this software requirements specification (SRS). 2. The CPU bus clock frequency can be found in CPU.h. The CPU bus clock is supplied to UART2 as its module clock (see Table 5-2 in K70P256M150SF3RM.pdf). The UART2 module clock is needed for baud rate divisor calculations. 3. The software must be able to handle at least 40 packets in the receive buffer and at least 40 packets in the transmit buffer (each packet is 5 bytes). 4. A frequent polling operation in the main loop should be used to check the status of the serial port. 5. The commands of the Tower serial protocol to be implemented (with packet acknowledgement) are: Tower to PC 0x04 Tower startup 0x09 Special Tower version 0x0B Tower number PC to Tower 0x04 Special Get startup values 0x09 Special Get version 0x0B Tower number (get & set) 6. In response to reception of a 0x04 Special Get startup values packet from the PC, the Tower should transmit three packets: a 0x04 Tower startup packet a 0x09 Special Tower version packet a 0x0B Tower number packet 7. Upon power up, the Tower should send the same 3 packets as above. 8. Use the last 4 digits of your student number to initialise the Tower number. Note that it may be changed via the 0x0B Tower number packet at a later time.

L1.7 9. The 0x09 Special Tower Version should be V1.0. 10. TortoiseSVN must be used for version control.

L1.8 Hints 1. You need to enable the UART module in SIM_SCGC4. 2. To enable pin routing for Port E, you need to enable Port E in SIM_SCGC5. 3. For PIN multiplexing, see p. 280 of K70P256M150SF3RM.pdf. UART2 shares pins with PortE bits 16 and 17. 4. For the UART control registers, you only need to write code to change individual bits from their reset state, if required by the SRS (in other words, your software may assume that a valid reset has taken place before it is executed). For every bit that is set or cleared, there should be one line of code, with appropriate comments. 5. The Baud Rate Divisor Register and Fine Adjust are discussed on p. 1974 of K70P256M150SF3RM.pdf. 6. The project has automatically included MK70F12.h which defines all the registers, such as UART2_S1, as well as the bit masks, such as UART_S1_RDRF_MASK. 7. Valid commands also require valid parameters when handling a packet. Marking The software should be ready for marking on the date specified in the Timetable in the Learning Guide. Software marking will be carried out in the laboratory, in the format of an oral exam. Marking criteria are on the front page. Also refer to the document Software Style Guide.