Serial Communications Interface (SCI)

Slides:



Advertisements
Similar presentations
INPUT-OUTPUT ORGANIZATION
Advertisements

Serial Communications Interface (SCI) Michael LennardZachary PetersBao Nguyen.
SCI: Serial Communications Interface Presented by: Sean Kline Chad Smith Jamie Cruce.
Serial I/O - Programmable Communication Interface
68HC11 Polling and Interrupts
Hierarchy of I/O Control Devices
Serial Communication Interface
ECE 372 – Microcontroller Design Parallel IO Ports - Interrupts
Asynchronous Communication Hardware  Data within a DTE is usually stored and moved in a parallel fashion.  Data sent across the channel is generally.
7-1 Digital Serial Input/Output Two basic approaches  Synchronous shared common clock signal all devices synchronised with the shared clock signal data.
13-1 EE 319K Introduction to Microcontrollers Lecture 13: Serial Communications Interface (SCI), Producer-Consumer problems, FIFO Queues, Lab9 Read Book.
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.
Serial Peripheral Interface Module MTT M SERIAL PERIPHERAL INTERFACE (SPI)
Serial Communication ETEC 6416.
Input/Output mechanisms
Lecture Set 9 MCS-51 Serial Port.
Universal Synchronous/Asynchronous Receiver/Transmitter (USART)
Universal Asynchronous Receiver/Transmitter (UART)
Scott Baker Will Cross Belinda Frieri March 9 th, 2005 Serial Communication Overview ME4447/6405.
Serial Communication Interface Ta Kim Nicholas Earnhart Razid Ahmad ME 6405 – Fall 2008 November 6, 2008.
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
ATtiny23131 A SEMINAR ON AVR MICROCONTROLLER ATtiny2313.
1 October 26, 2006ME 6405 MechatronicsSerial Communication Interface Brian Guerriero Jon Rogers Robert Thiets.
Serial Communications Interface Module Slide #1 of 19 MC68HC908GP20 Training PURPOSE -To explain how to configure and use the Serial Communications Interface.
© 2009, Renesas Technology America, Inc., All Rights Reserved 1 Course Introduction  Purpose:  This course provides an overview of the serial communication.
SCI Communication Proudly Presented By: Adam Cardi & Aaron Enes.
Digital Logic Design Alex Bronstein
Why are Timer Functions Important?
Serial Communications
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.
Serial mode of data transfer
Buffered, Interrupt-Driven Printer Design Example
Fri. Sept 29 Announcements
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.
Source: Serial Port Source:
Timer and Interrupts.
Inter-IC Bus (I C) 2.
Chapter 11: Inter-Integrated Circuit (I2C) Interface
Analog-to-Digital Converter
Fri. Oct 13 Announcements Lab practical next week
Serial I/O and Data Communication.
SERIAL PORT PROGRAMMING
Buffered, Interrupt-Driven Printer Design Example
1 Input-Output Organization Computer Organization Computer Architectures Lab Peripheral Devices Input-Output Interface Asynchronous Data Transfer Modes.
Oct 30 Announcements Code Marked and on Blackboard
E3165 DIGITAL ELECTRONIC SYSTEM
Introduction to Micro Controllers & Embedded System Design I/O Processing and Serial Port Operation Department of Electrical & Computer Engineering Missouri.
Computer Organization and Design
Source: Serial Port Source:
Oct 30 Announcements Code Marked and on Blackboard
UART Serial Port Programming
Asynchronous Serial Communications
Serial Communication Interface: Using 8251
Computer System Overview
Serial Communication Interface
UART Protocol Chapter 11 Sepehr Naimi
COMP3221: Microprocessors and Embedded Systems
Processor Fundamentals
Programmable Data Communication Blocks
Source: Serial Port Source:
CHAPTER SERIAL PORT PROGRAMMING. Basics of Serial Communication Computers transfer data in two ways: ◦ Parallel  Often 8 or more lines (wire.
EUSART Serial Communication.
Source: Serial Port Source:
PIC Serial Port Interfacing
PIC Serial Port Interfacing
Serial Communications
Introduction Communication Modes Transmission Modes
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:

Serial Communications Interface (SCI) Module 3.F Serial Communications Interface (SCI) Tim Rogers 2017

Learning Outcome #3 A: Clocks and Real Time Interrupt (RTI) “An ability to effectively utilize the wide variety of peripherals integrated into a contemporary microcontroller” A: Clocks and Real Time Interrupt (RTI) B: Analog-to-Digital Converter (ATD) C: Serial Peripheral Interface (SPI) D: Timer Module (TIM) E: Pulse Width Modulation (PWM) F: Serial Communications Interface (SCI) How?

Motivation Parallel Communication is expense Especially at long distances Each wire needs a twisted pair + line driver/receiver Solution: Transmit data serially – like SPI… SPI vs. SCI: SPI Needs a clock + data line. SCI gets away with just a data line.

Background and Motivation Alternative: Manchester encoding – returns to 0 after transmitting a “1” Illustration of serial bit stream (“NRZ”) LSB 1 1 1 MSB Data Clk Td = period of one data bit time Data Transmitted = 0010 0110 = $26

Background and Motivation Basic components required for “half duplex” implementation Twisted Pair SIPO Shift Register PISO Shift Register 8-bit Data In 8-bit Data Out Clk Question: What components would be required for a “full duplex” implementation?

Background and Motivation Additional components required for “full duplex” implementation Twisted Pair PISO Shift Register SIPO Shift Register 8-bit Data Out 8-bit Data In Clk Answer: A duplicate, “mirror image” version of the circuit on the previous slide

Background and Motivation Note: Would like to avoid sending clock in order to eliminate a twisted pair SIPO Shift Register PISO Shift Register 8-bit Data In 8-bit Data Out X T Clk R Clk Question: What difficulties are associated with generating the “transmit” and “receive” clocks locally?

Background and Motivation Note: Would like to avoid sending clock in order to eliminate a twisted pair SIPO Shift Register PISO Shift Register 8-bit Data In 8-bit Data Out X T Clk R Clk Question: What difficulties are associated with generating the “transmit” and “receive” clocks locally? Local clock synchronization

Asynchronous Serial Transmission Solution: Sample serial data stream at a higher rate than the data rate (1/Td) SIPO Shift Register PISO Shift Register 8-bit Data In 8-bit Data Out T Clk R Clk Typically a local clock period (Tc) that is 1/16 of the data period (Td) is used – i.e., the sampling rate (1/Tc) is 16 times the data rate (1/Td)

Asynchronous Serial Transmission Illustration of asynchronous serial data stream sampling Td Tc = period of local clock = 1/16 Td Note: Receiving end needs to know when a given code transmitted (ASCII character) starts and stops

Asynchronous Serial Transmission Solution: Append START bit (always “0”) to the beginning of each character sent Approximate “middle” of START bit Tc = period of local clock = 1/16 Td

Asynchronous Serial Transmission Solution: Sample successive data bits at intervals of 16 Tc referenced to START bit First data bit sampled 16 Tc after START bit Tc = period of local clock = 1/16 Td

Asynchronous Serial Transmission Solution: Sample successive data bits at intervals of 16 Tc referenced to START bit Second data bit sampled 32 Tc after START bit Tc = period of local clock = 1/16 Td

Asynchronous Serial Transmission Solution: Append STOP bit (always “1”) to the end of each character sent STOP bit at end of frame Tc = period of local clock = 1/16 Td

Character Format and Timing Reference

Asynchronous Serial Transmission Definition: BAUD rate is the number of bits per second transmitted over the serial link Example: If 10 bit character frames are used, then if 960 characters/second are transmitted, the BAUD rate is 9600 Question: What is the local clock frequency (assuming Td = 16 x Tc) required to support a 9600 BAUD data transmission rate? Answer: 9600 x 16 = 153,600 Hz

Asynchronous Serial Transmission Question: What is the tolerance required between the transmitting clock and the receiving clock?  1/2 bit at end of frame

Asynchronous Serial Transmission Question: How can the integrity of the data received be tested? Solution: Add a parity bit to the character frame

Parity Generation/Detection

Asynchronous Serial Transmission Parity possibilities even parity – here the parity bit is set so that there are an even number of “ones” transmitted in the data bits plus parity bit odd parity – here the parity is set so that there are an odd number of “ones” transmitted in the data bits plus parity bit marking parity – the parity bit is always the same value

Nov 8 Announcements “Code talk” results updated in BB Mini-project signup also posted in BB. Self-form your groups in BB. Project proposal (one per group), due Monday Nov 20th. Last day to present mini project: Thursday Dec 7th

Even Parity XOR 1 0 1 1 0 0 1 0 1 0 1 0 1 1 0 0 1 0 0 1 0 1 0 1 1 0 0 1 0 1 0 1 1 0 0 1 0

Odd Parity XNOR 1 0 1 1 0 0 1 0 1 1 1 0 1 1 0 0 1 0 0 1 1 1 0 1 1 0 0 1 0 1 0 1 1 0 0 1 0

Asynchronous Serial Transmission Question: What kinds of errors can occur in asynchronous serial transmission? don’t get STOP bit at end of frame – framing error receiver doesn’t read data from shift register before next character starts shifting in – receiver overrun noise on the transmission line corrupts one or more bits in the data stream – parity error

Asynchronous Serial Transmission Question: What are the most likely causes of serial data transmission errors, and how can these errors be corrected? framing error cause: local clocks too far out of tolerance correction: bring clocks within tolerance overrun error cause: data not read “fast enough” correction: lower baud rate or fix software parity error cause: problem with cable/connector correction: repair/replace cable

The baud rate of a serial transmission link refers to: the number of bits per second transferred the number of bytes per second transferred the local clock frequency the data error rate none of the above 1-A

the sampling clock is 16 times faster than the data rate Local clock error does not accumulate on an asynchronous communication link because: the sampling clock is 16 times faster than the data rate the receiver re-synchronizes every time a start bit is detected the transmitter periodically sends “sync” pulses the receiver re-synchronizes every time a stop bit is detected none of the above 2-B

The length of time required to transmit a 10-bit character frame at 19 The length of time required to transmit a 10-bit character frame at 19.2 Kbaud is approximately: 1.042 milliseconds 2.084 milliseconds 5.208 milliseconds 0.521 milliseconds none of the above 3-D

A possible cause of a framing error on a serial transmission link is: a bad cable or connector mismatch in baud rates error in the transmit side software error in the receive side software none of the above 4-B

9S12 Block User Guide https://engineering.purdue.edu/ece362/Refs/9S12C_Refs/S12SCIV2.p df

9S12 SCI Features Specific instance of a UART (Universal Asynchronous Receiver/Transmitter) Software-selectable baud rates “Advanced” sampling technique Allows single-wire/loop modes Uses NRZ format Can be used in full-duplex Programmable word length (8/9bits data) Parity generation/checking (optional) Interrupt or program driven

SCI Features Illustration of double buffering Transmitter Receiver

SCI Features Illustration of data bit sampling Three successive samples taken in “middle” of each data bit; data bit is declared “valid” if two out of three samples agree (but noise flag “NF” is set to indicate that the “vote” was not “unanimous”)

SCI Features Normal Mode: One pin for transition, one for reception. Single-Wire Mode: Transmit/receive are from a single pin (of Port S); Loop Mode: Used for testing serial I/O software when the external device may not be available

Data Registers Lower 8-bits for both transmit and receive Lower 9-bit mode: 9th bit is here for Tx/Rx

Config Register 1 Bit-Mode 0 – 8-bit data 1 – 9-bit data Parity enable 0 – no parity bit 1 – use parity Config Register 1 0 – Normal Mode 1 –Loop Mode Receiver src (in loop mode) 0 – internally connected Tx/Rx 1 – Tx/Rx pins connected externally Parity Type 0 – even 1 – odd

Control Register 2 Receive Interrupt Enable 0 – Disabled 1 –Enabled Transmit interrupt enable 0 – Disabled 1 –Enabled Transmit complete interrupt enable 0 – Disabled 1 –Enabled

Control Register 2 Idle Line interrupt Enable 0 – Disabled 1 –Enabled Transmit Enable 0 – Disabled 1 –Enabled Receive Enable 0 – Disabled 1 –Enabled Receive Interrupt Enable 0 – Disabled 1 –Enabled

Status Register 1 Transmit complete flag 0 – transmitter busy 1 –transmitter idle Cleared by reading SCISR1 before writing to TDR Status Register 1 Transmit Data reg. empty flag 0 – not ready for new data 1 –ready for new data MUST Read SCISR1 before writing to TDR

Cleared by reading SCISR1 then reading RDR Receiver overrun flag 0 –no overrun 1 –overrun detected Status Register 1 Noise flag 0 –no noise 1 –noise Idle Line detected flag 0 –receive data line idle 1 –receive data line active Transmit Data reg. full 0 – no new data 1 –new data ready Cleared by reading SCISR1 then reading RDR Framing Error 0 –no error 1 –error Parity Error 0 –no error 1 –error

Status Register 2 Receiver active flag 0 –receiver inactive 1 – receiving character

BR DIV = CLK / (16 x baud rate) SCI Baud Rate Divisor Allows for 13-bit divisor BR DIV = CLK / (16 x baud rate) here, CLK = 24 MHz Example: For operation at 9600 baud, a baud rate divisor of 156 (base 10) should be loaded into SCIBDL (leave SCIBDH in reset state)

A possible cause of the noise flag (NF) being set in the SCI is: a bad cable or connector mismatch in baud rates error in the transmit side software error in the receive side software none of the above 2-A

a bad cable or connector mismatch in baud rates A possible cause of the receiver overrun flag (OR) being set in the SCI is: a bad cable or connector mismatch in baud rates error in the transmit side software error in the receive side software none of the above 3-D

a bad quarterback and/or wide receiver mismatch in baud rates If the receiver overrun flag is not being set, a possible cause of “dropped characters” is: a bad quarterback and/or wide receiver mismatch in baud rates error in the transmit side software error in the receive side software none of the above 4-C

The SCI’s TDRE (Transmit Data Register Empty) flag is cleared by: writing a character to SCIDR reading SCISR1 and then writing a character to SCIDR reading SCISR1 writing a “1” to the TDRE bit of SCISR1 none of the above 5-B

The SCI’s RDRF (Receiver Data Register Full) flag is cleared by: reading a character from SCIDR reading SCISR1 and then reading the character from SCIDR reading SCISR1 writing a “1” to the RDRF bit of SCISR1 none of the above 6-B

The SCI baud rate divisor that should be used in a 24 MHz system to transmit 11-bit character frames at 9600 baud is: 26 52 104 156 none of the above 7-D

The number of 11-bit character frames that can be transmitted each second at 9600 baud is approximately: 873 960 8730 9600 none of the above 8-A

For a 24 MHz system, the local clock error associated with transmitting 10-bit character frames at 9600 baud using the SCI is approximately: 5.0% 1.6% 0.5% 0.16% none of the above 9-D

Program-Driven Code rxdrf equ $20 ; RDRF mask ; Declarations rxdrf equ $20 ; RDRF mask txdre equ $80 ; TDRE mask tron equ $0C ; transmitter and ; receiver enable mask

Program-Driven Initialization ; STEP (1) Set transmission rate to 9600 baud sci_pini movb #156,scibdl ; STEP (2) Select character format (M bit) and parity (bits 1 & 0) via SCI Control Register #1 clr scicr1 ; STEP (3) Enable transmitter and receiver via SCI Control Register #2 (with interrupts off) movb #tron,scicr2 rts tron equ $0C

Program-Driven Device Driver ; Inputs ASCII character from SCI port and ; returns it in the A register ; No condition code bits or registers affected ; STEP (1) Check RDRF flag (wait until set) inchar brclr scisr1,rxdrf,inchar ; STEP (2) Load A with character in RDR ldaa scidrl rts rxdrf equ $20 ; RDRF mask This reads the character received via SCI

Program-Driven Device Driver ; Outputs character passed in A to the SCI port ; No condition code bits or registers affected ; STEP (1) Check TDRE flag (wait until set) outchar brclr scisr1,txdre,outchar ; STEP (2) Load TDR with character in A register staa scidrl rts txdre equ $80 Stores the character you want to write to the transmit register

Program versus Interrupt-Driven Program driven mode works (you have been using this when writing to terra-term all semester)! But it is not efficient. LOTS of waiting around. Lets look at a more complex interrupt-driven mode.

Interrupt-Driven Mode SCI receive interrupt means next character is ready Should always be turned on What if we can’t use just one character? i.e. we are expecting a multi- character command? What do we need to do? Receive Buffer! Also useful if the micro cannot keep up with the SCI receive interrupt

Interrupt-Driven Mode SCI transmit interrupt means: Please send another character! Problem: The application may not have something to send. Interrupt is just annoying us. Solution? Enable transmit interrupt only when you have character to send Means transmit interrupt is initially disabled

Interrupt-Driven Mode Transmit also needs a buffer. Why? What if the CPU wants to send a multi-byte message? Or what if it generates new characters much faster than 9600 baud can keep up with? 9600 Baud gives us ~1ms/character CPU Cycle is ~40ns. Takes 25,000 CPU cycles to send a character

Basic setup

Interrupt-Driven Buffer Initialization ; Declarations rxdrf equ $20 ; RDRF mask txdre equ $80 ; TDRE mask tron equ $0C ; transmitter/receiver enable mask rimask equ $20 ; receive interrupt mask timask equ $80 ; transmit interrupt mask Additional flags for interrupt-driven mode

Input/Output Buffer incBmod MACRO incb cmpb #\1 bne $+3 clrb ENDM rsize equ 40 ; receive buffer size rbuf rmb rsize rin fcb 0 ; receive buffer IN pointer rout fcb 0 ; receive buffer OUT pointer tsize equ 20 ; transmit buffer size tbuf rmb tsize tin fcb 0 ; transmit buffer IN pointer tout fcb 0 ; transmit buffer OUT pointer

Program-Driven Initialization ; STEP (1) Set transmission rate to 9600 baud sci_iini movb #156,scibdl ; STEP (2) Select character format (M bit) and parity (bits 1 & 0) via SCI Control Register #1 clr scicr1 ; STEP (3) Enable transmitter and receiver, initially with receive interrupts enabled and transmit interrupts disabled movb #tron,scicr2 bset scicr2,rimask ;enable recv intrs cli ;enable IRQ intrs rts Added for interrupt-driven rimask equ $20

Buffered Character In (BCI) Routine Application program interface that returns the next character available from the receive buffer RBUF in the A register 1. Check status of receive buffer RBUF 2. If EMPTY, wait for character 3. Else, access character from RBUF[ROUT] and return it in (A) 4. ROUT = (ROUT+1) mod RSIZE 5. Exit Called from “main” program

; Returns next character from RBUF in A register ; STEP (1) Check RBUF status bci ldab rout ; STEP (2) If EMPTY, wait for character rwait cmpb rin ; perform EMPTY check beq rwait ; wait if RBUF empty

Reads character off buffer and stores it in A ; Returns next character from RBUF in A register ; STEP (1) Check RBUF status bci ldab rout ; STEP (2) If EMPTY, wait for character rwait cmpb rin ; perform EMPTY check beq rwait ; wait if RBUF empty ; STEP (3) Access next character from RBUF ldx #rbuf ldaa b,x ;(A) = RBUF[ROUT] Reads character off buffer and stores it in A

Reads character off buffer and stores it in A ; Returns next character from RBUF in A register ; STEP (1) Check RBUF status bci ldab rout ; STEP (2) If EMPTY, wait for character rwait cmpb rin ; perform EMPTY check beq rwait ; wait if RBUF empty ; STEP (3) Access next character from RBUF ldx #rbuf ldaa b,x ;(A) = RBUF[ROUT] ; STEP (4) Increment ROUT modulo RSIZE incBmod rsize stab rout ; STEP (5) Exit rts From the circular buffer’s perspective, on SCI reception, the main program is the: producer consumer  neither both What Buffer? From the circular buffer’s perspective, on SCI reception, the main program is the: producer consumer neither both What Buffer? Reads character off buffer and stores it in A

Buffered Character Output (BCO) routine Application program interface that places character passed in A register into transmit buffer TBUF 1. Check status of transmit buffer TBUF 2. If FULL, wait for space 3. Else, store character passed in the A register at TBUF[TIN] 4. TIN = (TIN + 1) mod TSIZE 5. Enable SCI transmit interrupts 6. Exit Called from “main” program

; Places character passed in A into TBUF ; STEP (1) Check TBUF status bco ldab tin incBmod tsize ;(B) = (TIN+1) mod TSIZE pshb ;save on stack

; Places character passed in A into TBUF ; STEP (1) Check TBUF status bco ldab tin incBmod tsize ;(B) = (TIN+1) mod TSIZE pshb ;save on stack ; STEP (2) If FULL, wait for space twait cmpb tout ;perform FULL check beq twait ;wait if TBUF full

Puts character to transmit in buffer ; Places character passed in A into TBUF ; STEP (1) Check TBUF status bco ldab tin incBmod tsize ;(B) = (TIN+1) mod TSIZE pshb ;save on stack ; STEP (2) If FULL, wait for space twait cmpb tout ;perform FULL check beq twait ;wait if TBUF full ; STEP (3) Place character in TBUF ldx #tbuf ldab tin staa b,x ; TBUF[TIN] = (A) Puts character to transmit in buffer

Puts character to transmit in buffer ; Places character passed in A into TBUF ; STEP (1) Check TBUF status bco ldab tin incBmod tsize ;(B) = (TIN+1) mod TSIZE pshb ;save on stack ; STEP (2) If FULL, wait for space twait cmpb tout ;perform FULL check beq twait ;wait if TBUF full ; STEP (3) Place character in TBUF ldx #tbuf ldab tin staa b,x ; TBUF[TIN] = (A) ; STEP (4) Increment TIN mod TSIZE pulb stab tin Puts character to transmit in buffer

Puts character to transmit in buffer ; Places character passed in A into TBUF ; STEP (1) Check TBUF status bco ldab tin incBmod tsize ;(B) = (TIN+1) mod TSIZE pshb ;save on stack ; STEP (2) If FULL, wait for space twait cmpb tout ;perform FULL check beq twait ;wait if TBUF full ; STEP (3) Place character in TBUF ldx #tbuf ldab tin staa b,x ; TBUF[TIN] = (A) ; STEP (4) Increment TIN mod TSIZE pulb stab tin ; STEP (5) Enable SCI transmit interrupts bset scicr2,timask ; STEP (6) Exit rts From the circular buffer’s perspective, on SCI transmission, the main program is the: producer consumer neither both What Buffer? From the circular buffer’s perspective, on SCI transmission, the main program is the: producer consumer neither both What Buffer? Puts character to transmit in buffer timask equ $80

Interrupt Service Routine Only one ISR for both transmit and receive. Have to check which one is active before servicing

ISR Routine Algorithm: 2 sections Receive section R1. Check receive data register full flag R2. If not full, go to transmit section; else, continue with receive section R3. Check status of receive buffer RBUF R4. If FULL, error exit (via “SWI”) R5. Else, input character from SCI RDR R6. Store character at RBUF[RIN] R7. RIN = (RIN + 1) mod RSIZE This is an application of the same routine we looked at for circular buffers previously

ISR Routine Algorithm: 2 sections Transmit section T1. Check transmit data register empty flag T2. If empty, exit; else, continue T3. Check status of transmit buffer TBUF T4. If EMPTY, disable SCI transmit interrupts and exit; else, continue T5. Access character from TBUF[TOUT] T6. Output character to SCI TDR T7. TOUT = (TOUT + 1) mod TSIZE T8. Exit This is an application of the same routine we looked at for circular buffers previously

sciisr brclr scisr1,rxdrf,trans Checks receive done flag. If receive not done, skip this section go to transmit

sciisr brclr scisr1,rxdrf,trans ; STEP (R3) Check status of RBUF ldab rin incBmod rsize ;(B) = (RIN+1) mod RSIZE Checks receive done flag. If receive not done, skip this section go to transmit

sciisr brclr scisr1,rxdrf,trans ; STEP (R3) Check status of RBUF ldab rin incBmod rsize ;(B) = (RIN+1) mod RSIZE ; STEP (R4) If FULL, error exit; else, continue cmpb rout bne rok swi Checks receive done flag. If receive not done, skip this section go to transmit “SWI” is an exception – presumably you have an exception handler that does something sane

sciisr brclr scisr1,rxdrf,trans ; STEP (R3) Check status of RBUF ldab rin incBmod rsize ;(B) = (RIN+1) mod RSIZE ; STEP (R4) If FULL, error exit; else, continue cmpb rout bne rok swi ; STEP (R5) Input character from SCI RDR rok pshb ; save (RIN+1) mod RSIZE ldaa scidrl ; read SCI RDR Checks receive done flag. If receive not done, skip this section go to transmit “SWI” is an exception – presumably you have an exception handler that does something sane Reads the received character into A register

sciisr brclr scisr1,rxdrf,trans ; STEP (R3) Check status of RBUF ldab rin incBmod rsize ;(B) = (RIN+1) mod RSIZE ; STEP (R4) If FULL, error exit; else, continue cmpb rout bne rok swi ; STEP (R5) Input character from SCI RDR rok pshb ; save (RIN+1) mod RSIZE ldaa scidrl ; read SCI RDR ; STEP (R6) Store character at RBUF[RIN] ldx #rbuf ldab rin staa b,x ; RBUF[RIN] = (RDR) Checks receive done flag. If receive not done, skip this section go to transmit “SWI” is an exception – presumably you have an exception handler that does something sane Reads the received character into A register Stores the read value in the buffer

sciisr brclr scisr1,rxdrf,trans ; STEP (R3) Check status of RBUF ldab rin incBmod rsize ;(B) = (RIN+1) mod RSIZE ; STEP (R4) If FULL, error exit; else, continue cmpb rout bne rok swi ; STEP (R5) Input character from SCI RDR rok pshb ; save (RIN+1) mod RSIZE ldaa scidrl ; read SCI RDR ; STEP (R6) Store character at RBUF[RIN] ldx #rbuf ldab rin staa b,x ; RBUF[RIN] = (RDR) ; STEP (R7) Increment RIN mod RSIZE pulb ; restore from stack stab rin ; RIN = (RIN+1) mod RSIZE From the circular buffer’s perspective, on SCI reception, the ISR is the: producer consumer neither both What Buffer? From the circular buffer’s perspective, on SCI reception, the ISR is the: producer consumer neither both What Buffer? Checks receive done flag. If receive not done, skip this section go to transmit “SWI” is an exception – presumably you have an exception handler that does something sane Reads the received character into A register Stores the read value in the buffer

trans brclr scisr1,txdre,scexit Checks transmit done flag. If transmit not done, finish Continued…

trans brclr scisr1,txdre,scexit ; STEP (T3) Check status of TBUF ldab tout cmpb tin Checks transmit done flag. If transmit not done, finish Continued…

trans brclr scisr1,txdre,scexit ; STEP (T3) Check status of TBUF ldab tout cmpb tin ; STEP (T4) If EMPTY, disable SCI transmit ; interrupts and exit; else, continue bne tok bclr scicr2,timask ;disable trans intrs rti Checks transmit done flag. If transmit not done, finish Continued… If we have nothing in the buffer: stop trans. interrupts

trans brclr scisr1,txdre,scexit ; STEP (T3) Check status of TBUF ldab tout cmpb tin ; STEP (T4) If EMPTY, disable SCI transmit ; interrupts and exit; else, continue bne tok bclr scicr2,timask ;disable trans intrs rti ; STEP (T5) Access character from TBUF tok ldx #tbuf ldaa b,x ; (A) = TBUF[TOUT] Checks transmit done flag. If transmit not done, finish Continued… If we have nothing in the buffer: stop trans. interrupts Read buffer into A

trans brclr scisr1,txdre,scexit ; STEP (T3) Check status of TBUF ldab tout cmpb tin ; STEP (T4) If EMPTY, disable SCI transmit ; interrupts and exit; else, continue bne tok bclr scicr2,timask ;disable trans intrs rti ; STEP (T5) Access character from TBUF tok ldx #tbuf ldaa b,x ; (A) = TBUF[TOUT] ; STEP (T6) Output character to SCI TDR staa scidrl ; (TDR) = TBUF[TOUT] Checks transmit done flag. If transmit not done, finish Continued… If we have nothing in the buffer: stop trans. interrupts Read buffer into A Store A into SCI data register: initiates transmission

trans brclr scisr1,txdre,scexit ; STEP (T3) Check status of TBUF ldab tout cmpb tin ; STEP (T4) If EMPTY, disable SCI transmit ; interrupts and exit; else, continue bne tok bclr scicr2,timask ;disable trans intrs rti ; STEP (T5) Access character from TBUF tok ldx #tbuf ldaa b,x ; (A) = TBUF[TOUT] ; STEP (T6) Output character to SCI TDR staa scidrl ; (TDR) = TBUF[TOUT] ; STEP (T7) Increment TOUT mod TSIZE incBmod tsize stab tout ; TOUT=(TOUT+1) mod TSIZE ; STEP (T8) Exit scexit rti Checks transmit done flag. If transmit not done, finish From the circular buffer’s perspective, on SCI transmission, the ISR is the: producer consumer neither both What Buffer? From the circular buffer’s perspective, on SCI transmission, the ISR is the: producer consumer  neither both What Buffer? Continued… If we have nothing in the buffer: stop trans. interrupts Read buffer into A Store A into SCI data register: initiates transmission

Code dump + marked quiz Will do this Monday

;*********************************************************************** ; In this exercise we will investigate ATD-PWM audio digitization ; and signal reconstruction as well as a "digital volume control". ; Resources used: ; - TIM TC7 - interrupt every 0.1 ms, used to initiate ATD conversion ; - ATD Ch 0 - audio input (PIN 5 on BREADBOARD HEADER) ; - ATD Ch 1 - potentiometer input for digital volume control (PIN 6 on ; BREADBOARD HEADER) ; - PWM Ch 0 - audio output (PIN 27 on BREADBOARD HEADER) ; CAUTION: Carefully adjust the function generator analog output for a ; D.C. offset of 2.5 V and a peak voltage no greater than 5 V ; (use the oscilloscope to confirm). ; Task list: ; 1. Determine the input sampling frequency and the output sampling ; frequency for the code as written. ; 2. Try varying the input and output sampling frequencies ; (independently), and note the effects.

;*********************************************************************** ; START OF CODE ; initialize ATD (8 bit, unsigned, nominal sample time, seq length = 2) movb #$80,ATDCTL2 ; power up ATD movb #$10,ATDCTL3 ; set conversion sequence length to TWO movb #$85,ATDCTL4 ; select resolution and sample time ; initialize PWM Ch 0 (left aligned, positive polarity, max 8-bit period) movb #$01,MODRR ; PT0 used as PWM Ch 0 output movb #$01,PWME ; enable PWM Ch 0 movb #$01,PWMPOL ; set active high polarity movb #$00,PWMCTL ; no concatenate (8-bit) movb #$00,PWMCAE ; left-aligned output mode movb #$FF,PWMPER0 ; set maximum 8-bit period movb #$00,PWMDTY0 ; initially clear DUTY register movb #$00,PWMPRCLK ; set Clock A = 24 MHz (prescaler = 1) movb #$01,PWMCLK ; select Clock SA for Ch 0 movb #$01,PWMSCLA ; set Clock SA scalar to 2 ; **** change to modify output sampling rate

; initialize TIM Ch 7 (periodic 0.1 ms interrupt) movb #$80,tscr1 ; enable TC7 movb #$0C,tscr2 ; set TIM prescale factor to 16 ; and enable counter reset after OC7 movb #$80,tios ; set TIM TC7 for Output Compare movb #$80,tie ; enable TIM TC7 interrupt movw #150,tc7 ; set up TIM TC7 to generate 0.1 ms interrupt rate ; **** change this to modify input sampling rate ; enable IRQ interrupts cli ; enable IRQ interrupts ; do nothing after initialization complete eloop bra eloop ; wait loop

;*********************************************************************** ; TIM interrupt service routine ; Interrupt generated every 0.1 ms (default - may be changed) ; Initiate ATD conversion on Chs 0 and 1 ; Multiply analog input sample by potentiometer sample -> PWM Ch 0 ; tim_isr bset tflg1,$80 ; clear TC7 interrupt flag movb #$10,ATDCTL5 ; start conversion on ATD Ch 0 ; NOTE: "mult" (bit 4) needs to be set await brclr ATDSTAT,$80,await ldaa ATDDR0 ; analog input sample ldab ATDDR1 ; potentiometer sample mul ; multiply input sample X pot setting adca #0 ; round upper 8 bits of result staa PWMDTY0 ; copy result to PWM Ch 0 rti