13-1 EE 319K Introduction to Microcontrollers Lecture 13: Serial Communications Interface (SCI), Producer-Consumer problems, FIFO Queues, Lab9 Read Book.

Slides:



Advertisements
Similar presentations
INPUT-OUTPUT ORGANIZATION
Advertisements

Serial Communications Interface (SCI) Michael LennardZachary PetersBao Nguyen.
The 8051 Microcontroller Chapter 5 SERIAL PORT OPERATION.
Chapter 10 Input/Output Organization. Connections between a CPU and an I/O device Types of bus (Figure 10.1) –Address bus –Data bus –Control bus.
SCI: Serial Communications Interface Presented by: Sean Kline Chad Smith Jamie Cruce.
1/1/ / faculty of Electrical Engineering eindhoven university of technology Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir.
A look at interrupts What are interrupts and why are they needed.
Serial I/O - Programmable Communication Interface
10-1 EE 319K Introduction to Microcontrollers Lecture 10: Interrupts, Output Compare Periodic Interrupts Read Book Sections 9.1, 9.2, 9.4, 9.6.1, 9.6.2,
CSCI 4717/5717 Computer Architecture
1/1/ / faculty of Electrical Engineering eindhoven university of technology Introduction Part 3: Input/output and co-processors dr.ir. A.C. Verschueren.
ECE 372 – Microcontroller Design Parallel IO Ports - Interrupts
A look at interrupts What are interrupts and why are they needed in an embedded system? Equally as important – how are these ideas handled on the Blackfin.
Basic Input/Output Operations
A look at interrupts What are interrupts and why are they needed.
Midterm Tuesday October 23 Covers Chapters 3 through 6 - Buses, Clocks, Timing, Edge Triggering, Level Triggering - Cache Memory Systems - Internal Memory.
7-1 Digital Serial Input/Output Two basic approaches  Synchronous shared common clock signal all devices synchronised with the shared clock signal data.
Unit-5 CO-MPI autonomous
Group 7 Jhonathan Briceño Reginal Etienne Christian Kruger Felix Martinez Dane Minott Immer S Rivera Ander Sahonero.
1 SCI Serial Communication Interface Gerrit Becker James McClearen Charlie Hagadorn October 21, 2004.
INPUT-OUTPUT ORGANIZATION
Serial Communication Interface (SCI) Kevin Stuart Matt Betts March 27, 2007 ME 6405, Sp 07.
Ch. 9 Interrupt Programming and Real-Time Sysstems From Valvano’s Introduction to Embedded Systems.
1 Computer System Overview Chapter 1. 2 n An Operating System makes the computing power available to users by controlling the hardware n Let us review.
MICROPROCESSOR INPUT/OUTPUT
Lecture Set 9 MCS-51 Serial Port.
Unit 4 Design and Synthesis of Datapath Controllers
Khaled A. Al-Utaibi  Interrupt-Driven I/O  Hardware Interrupts  Responding to Hardware Interrupts  INTR and NMI  Computing the.
Lecture 14 DMA Controller & Serial Communications Interface (UART)
Universal Asynchronous Receiver/Transmitter (UART)
Chapter 8 Serial and Parallel Port Interfacing Valvano’s Intro. To Embedded Systems.
Scott Baker Will Cross Belinda Frieri March 9 th, 2005 Serial Communication Overview ME4447/6405.
(More) Interfacing concepts. Introduction Overview of I/O operations Programmed I/O – Standard I/O – Memory Mapped I/O Device synchronization Readings:
Chapter 8 I/O. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 8-2 I/O: Connecting to Outside World So far,
Other Chapters From the text by Valvano: Introduction to Embedded Systems: Interfacing to the Freescale 9S12.
The Functions of Operating Systems Interrupts. Learning Objectives Explain how interrupts are used to obtain processor time. Explain how processing of.
Advanced Microprocessor1 I/O Interface Programmable Interval Timer: 8254 Three independent 16-bit programmable counters (timers). Each capable in counting.
 8251A is a USART (Universal Synchronous Asynchronous Receiver Transmitter) for serial data communication.  Programmable peripheral designed for synchronous.
9-1 EE 319K Introduction to Microcontrollers Lecture 9:I/O Synchronization; LCD Interfacing; Implementing Local Variables using a Stack Frame; Parameter.
Universal Asynchronous Receiver/Transmitter (UART)
Computer Architecture Lecture 2 System Buses. Program Concept Hardwired systems are inflexible General purpose hardware can do different tasks, given.
Serial Communication Interface Ta Kim Nicholas Earnhart Razid Ahmad ME 6405 – Fall 2008 November 6, 2008.
Accessing I/O Devices Processor Memory BUS I/O Device 1 I/O Device 2.
13-Nov-15 (1) CSC Computer Organization Lecture 7: Input/Output Organization.
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
1 October 26, 2006ME 6405 MechatronicsSerial Communication Interface Brian Guerriero Jon Rogers Robert Thiets.
Interrupt driven I/O. MIPS RISC Exception Mechanism The processor operates in The processor operates in user mode user mode kernel mode kernel mode Access.
Chapter 13 – I/O Systems (Pgs ). Devices  Two conflicting properties A. Growing uniformity in interfaces (both h/w and s/w): e.g., USB, TWAIN.
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
Embedded Computer - Definition When a microcomputer is part of a larger product, it is said to be an embedded computer. The embedded computer retrieves.
Ch.12 Communication Systems Valvano’s text Introduction SCI can be used to create a network. Figure 12.1 gives a general visualization. –At lowest.
Embedded Systems February 10, Serial Interface - SPI  Serial Peripheral Interface  Synchronous communications  Clock supplied by the Master.
Interrupts and Exception Handling. Execution We are quite aware of the Fetch, Execute process of the control unit of the CPU –Fetch and instruction as.
Introduction to Exceptions 1 Introduction to Exceptions ARM Advanced RISC Machines.
8251 USART.
SCI Communication Proudly Presented By: Adam Cardi & Aaron Enes.
The HCS12 SCI Subsystem A HCS12 device may have one or two serial communication interface. These two SCI interfaces are referred to as SCI0 and SCI1. The.
Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir. A.C. Verschueren Eindhoven University of Technology Section of Digital.
Serial mode of data transfer
EE 319K Introduction to Embedded Systems
Mon. Oct 2 Announcements Quiz Postponed to Wednesday – still only on 2.a + 2.b Video lecture for 2.a posted Lab 6 experiment extension You must come to.
SERIAL PORT PROGRAMMING
Serial Communication Interface: Using 8251
Computer System Overview
Processor Fundamentals
Chapter 13: I/O Systems.
Chapter 13: I/O Systems “The two main jobs of a computer are I/O and [CPU] processing. In many cases, the main job is I/O, and the [CPU] processing is.
Presentation transcript:

13-1 EE 319K Introduction to Microcontrollers Lecture 13: Serial Communications Interface (SCI), Producer-Consumer problems, FIFO Queues, Lab9 Read Book Sections 8.1, 8.2, , , 12.4

13-2 Ramesh Yerraballi Serial Comm. Interface (SCI)  This protocol is also known as UART (Universal Asynchronous, Receiver Transmitter)  Originally used to connect i/o terminals to mainframes.  Neither fast nor reliable but simple SCI Device Driver  Public routines  SCI1_Init  SCI1_InChar  SCI1_OutChar  Private Objects  SCI1CR2  SCI1BD  SCI1SR1  SCI1DRL

13-3 Ramesh Yerraballi SCI Basics  Baud Rate: The total number of bits transmitted per second baud-rate = 1/bit-time  Mode Bit (M): Selects 8- bit(M=0) or 9-bit (M=1) data frames  Frame: The smallest complete unit of serial transmission.  Bandwidth: The amount actual information transmitted per second. A serial data frame with M=0 number of information bits/frame Total number of bits/frame x baud-rate Bandwidth =

13-4 Ramesh Yerraballi Transmitting in Asynchronous Mode The software writes to SCI1DRL, then  8 bits of data are moved to the shift register  start and stop bits are added  shifts in 10 bits of data one at a time on TxD line  shift one bit per bit time (=1/baudRate) Data and shift registers implement the serial transmission

13-5 Ramesh Yerraballi Receiving in Asynchronous Mode The receiver waits for the 1 to 0 edge signifying a start bit, then  shifts in 10 bits of data one at a time from RxD line  shift one bit per bit time (=1/baudRate)  start and stop bits are removed  checked for noise and framing errors  8 bits of data are loaded into the SCIDRL Data and shift registers implement the receive serial interface

13-6 Ramesh Yerraballi SCI Details  SCI1BD : Determines the baud rate: Say SCI1BD[12:0] => Integer BR SCI Baud-rate = MClock/(16xBR) Mclock on 9S12DP512 is 24 MHz (with PLL in Load mode); 8 MHz otherwise.  TE is the Transmitter Enable bit  RE is the Receiver Enable bit.

13-7 Ramesh Yerraballi … SCI Details  TDRE is the Transmit Data Register Empty flag.  set by the SCI hardware if transmit data register empty  if set, the software can write next output to SCIDRL  cleared by two-step software sequence ofirst reading SCISR1 with TDRE set othen SCIDRL write  RDRF is the Receive Data Register Full flag.  set by hardware if a received character is ready to be read  if set, the software can read next input from SCIDRL  cleared by two-step software sequence ofirst reading SCISR1 with RDRF set othen SCIDRL read

13-8 Ramesh Yerraballi … SCI Details  RIE is the Receive Interrupt Enable bit (Arm).  set and cleared by software  set to arm RDRF triggered interrupts  clear to disarm RDRF triggered interrupts  TIE is the Transmit Interrupt Enable bit (Arm).  set and cleared by software  set to arm TDRE triggered interrupts  clear to disarm TDRE triggered interrupts  SCI1DRL register contains transmit and receive data  these two registers exist at the same I/O port address  Reads access the read-only receive data register (RDR)  Writes access the write-only transmit data register (TDR)

13-9 Ramesh Yerraballi SCI I/O Programming ; Initalize 9S12DP512 SCI at bps ; Inputs: none ; Outputs: none ; Errors: none ; assumes 8 MHz E clock (PLL not activated) SCI1_Init movb #$0c,SCI1CR2 ; enable SCI TE=RE=1 movw #13,SCI1BD ; bps ; baud rate(bps)= /(16xBR) ( ) rts

13-10 Ramesh Yerraballi …SCI I/O Programming

13-11 Ramesh Yerraballi …SCI I/O Programming Re-visit Tut3

13-12 Ramesh Yerraballi Overrun Error If there is already data in the SCI0DRL when the shift register is finished, it will wait until the previous frame is read by the software, before it is transferred. An overrun occurs when there is one receive frame in the SCI0DRL, one receive frame in the receive shift register, and a third frame comes into RxD.

13-13 Ramesh Yerraballi Tut2  Busy-wait SCI input  I/O bound (bandwidth limited to input rate)  Very inefficient (spends a lot of time waiting)

13-14 Ramesh Yerraballi Tut2: Recover wasted time? Technique 1: Combine all busy-waits  Requires cooperation,  Complicated to test (all tasks are interrelated)  Can’t guarantee bound on latency

13-15 Ramesh Yerraballi Tut2: Recover wasted time? Technique 2: Input device interrupts when ready  ISR reads new input, puts into FIFO  Latency equals maximum time it runs with I=1 FIFO queues and double buffers can be used to pass data from a producer to a consumer

13-16 Ramesh Yerraballi FIFO Queues Figure 12.6: FIFO queues can be used to pass data between threads

13-17 Ramesh Yerraballi Tut4: Producer Consumer problem

13-18 Ramesh Yerraballi FIFO: Two Implementations  Differ in the way empty/full conditions are determined:  Two pointers (12.3.3, Tut4): oEmpty => GetPt == PutPt oFull => GetPt ==(PutPt+1)%buffer_size oWastes 1 buffer slot  Two pointers with a counter oEmpty => counter == 0 oFull => counter = buffsize oUses all buffer slots

13-19 Ramesh Yerraballi FIFO: Two Implementations  Common to both Implementations  GetPt: Points to the data that will be removed on the next call to FiFo_Get  PutPt: Points to the empty space where the data will be stored on the next call to Fifo_Put  Fifo_Put adds data at PutPt and increments PutPt  FiFo_Get removes data at GetPt and decrements GetPt  Wrapping must be handled because buffers are not infinite

13-20 Ramesh Yerraballi Wrap Pointer wrap on 2nd put Pointer wrap on 4th get

13-21 Ramesh Yerraballi Lab9 Figure 8.3: Data flows from the sensor through the two microcontrollers to the LCD. The output compare timer is used to trigger the real-time sampling. Use the special serial cable to connect the two SCI1 ports. 1.5 cm 1.50 cm

13-22 Ramesh Yerraballi Lab9 Communication interfacing between two 9S12 microcontrollers using SCI

13-23 Ramesh Yerraballi Simple Design Courtesy: Jon Valvano

13-24 Ramesh Yerraballi Issues in Lab 9  Synchronization oBlind-Cycle oBusy Wait oInterrupt  FIFO  Structured mechanism to pass data.  Helps us cope with mismatched speeds of producer and consumer

13-25 Ramesh Yerraballi Lab 9 Transmitter  Context Switch  When a previously scheduled interrupt (OC interrupt) occurs, the processor has to switch context to run the corresponding ISR.  What does this entail: oThe current instruction (of the foreground process) is finished oPush registers (including CCR) on Stack (with I=0) oDisable further interrupts (I=1) oVector fetch and load ISR address into PC  Demo in TExaS with Transmitter

13-26 Ramesh Yerraballi …Lab 9 Transmitter  When does the OC Interrupt occur?  3 conditions must be true oArm the Specific Interrupt: (C0I=1) - ritual oInterrupts enabled: (I=0 using cli) - ritual oInterrupt gets Triggered: C0F is set when TCNT equals TC0  What happens in ISR?  Acknowledge Interrupt: movb #$01,TFLG1  Read ADC data, encode, send one frame  rti Note: It is not necessary for you to set/clear the I bit except in the initial ritual, it is done automatically

13-27 Ramesh Yerraballi Lab 9 Receiver  Context Switch  When a scheduled interrupt (SCI RDRF interrupt) occurs, the processor has to switch context to run the corresponding ISR.  When does the SCI RDRF Interrupt occur?  3 conditions must be true oArm the Specific Interrupt: (RIE=1) - ritual oInterrupts enabled: (I=0 using cli) - ritual oInterrupt gets Triggered: RDRF is set when a new frame arrives  What happens in ISR?  Acknowledge Interrupt: By reading SCI0SR1 and SCI0DRL  Read a frame and pass to foreground through global memory; Schedule  rti

13-28 Ramesh Yerraballi Lab 9: Why FIFO?  May use unstructured globals to pass data  Is there data in there?  Are you writing new data overtop old data?  Are you reading garbage?  FIFOs are structured globals  Fifo_Put stores data; Fifo_Get retreives data  First in first out means the data remains in order  Real way to implement thread synchronization oThe producer needs to stall if FIFO is full oThe consumer needs to stall if FIFO is empty  Lab7 way to implement thread synchronization oThe producer throws data away if FIFO is full oThe consumer waits if FIFO is empty

13-29 Ramesh Yerraballi Lab9: Receiver Main program 1.Initialize Timer, LCD, Fifo_Init, SCI 2.Fifo_Get (wait here until data is available) 3.Convert from 8-bit sample to decimal fixed-point 4.Display on LCD 5.repeat 2,3,4 over and over

13-30 Ramesh Yerraballi Interrupt Programming