Serial and Parallel Communication in MCU using SCI and UART, Study notes of Microprocessors

An in-depth explanation of serial and parallel communication in the context of microcontroller units (mcu), focusing on the serial communications interface (sci) and universal asynchronous receiver/transmitter (uart) for data transmission. It includes details about the sci data registers, double-buffering, and programming the sci, as well as an example sci driver in assembly language.

Typology: Study notes

Pre 2010

Uploaded on 08/19/2009

koofers-user-8wh-1
koofers-user-8wh-1 🇺🇸

10 documents

1 / 27

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
ECE 4436 ECE 4436
15 & 18. Serial I/O
Dept. of Electrical & Computer Engineering
University of Houston
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b

Partial preview of the text

Download Serial and Parallel Communication in MCU using SCI and UART and more Study notes Microprocessors in PDF only on Docsity!

15 & 18. Serial I/O

Dept. of Electrical & Computer Engineering University of Houston

What is Serial I/O?

  • “Serial I/O” refers to using a serial communications interface and protocol between the computer and an external device. - Minimally 2-3 wires: Transmit/Receive, and Ground - Many PC peripherals such as printers have required a serial connection, although USB is rapidly displacing serial in devices. - Serial is still frequently used between an MCU and small external devices such as an LCD because of the hardware simplicity and efficiency.
  • The programmer on the MCU, however, sees the built-in “serial communications interface” like any other parallel device.

Serial vs. Parallel

Let’s take the example of transmitting a byte of data:

  • Parallel – The 8 individual bit values are placed on 8 separate wires/pins and transmitted simultaneously. There are usually additional control and status signals. - High speed, but expensive and bulky. - Example: SCSI, ATAPI; writing to port PTT on the MCU, writing to memory.
  • Serial – The 8 individual bit values are placed on a single wire/pin, one at a time in succession. Again, there must be additional control and status signals, or a built-in synchronization technique. - Slower than parallel, but cheaper and more practical. - Examples: RS-232-C, USB

Duplex Communications

Communications can be:

  • Simplex – Communication always in only one direction.
    • Ex: TV or radio broadcast.
  • Half-duplex – Communication in only direction at a time. - Ex: Push-to-talk walkie-talkie; single-lane bridge.
  • Full-duplex – Communication in both directions simultaneously. - Ex: Telephone

Asynchronous Serial Data Format

-3 to -15 v +3 to +15 v -3 to -15 v +3 to +15 v RS-232-C voltage levels Bit 0 follows the start bit.

  • Note that RS-232-C is an older standard with performance very limited compared to these newer standards.
  • However, for non-demanding applications, it is simple and cheap, and thus still widely used.

RS232C Signal Definitions

Serial Communications Interface (SCI)

on the MCU

E.g., MAX3232 Line Driver/Receiver

SCI Data Registers – Double-Buffering

serial in/ out

SCI Registers – Programming the SCI

  • SCIDRL – Write the output character to this register, or read the input character from this register.
  • SCICR2 – Control register 2: enable/disable interrupts, enable/disable transmitter and receiver.
  • SCISR1 – Status register 1: transmitter data register empty flag, receiver data register full flag, error flags.
  • SCIBDH:SCIBDL – Baud rate selection.
  • PTS – This is Port S if you are simply using PTS0-PTS as digital I/O bits, not through the SCI.
  • See Register Definitions in HCS12 SCI Block Guide on the course web site.

Device Drivers

  • A device driver is a software module containing subroutines/functions with the common purpose of providing low-level access to a particular I/O device.
  • The driver is generally the only interface between the other software components in the system and the hardware of this device. All accesses to the device must come through this driver.
  • The functions are normally created in the same file:
    • The public interface consists of the external functions.
    • Other functions may be private (local, static), called only by other functions in the file.
    • The functions may share private (local, static) data.

Driver Files

Drivers written in C:

  • device .c – The driver file containing all of the functions, public and private (static).
  • device .h – The header file containing the prototypes of the public functions. This file is included by other modules that use the driver. Drivers written in assembly language:
  • device .asm – Contains all of the subroutines, public and private. The public subroutines are declared external using XDEF.
  • device .h – If these subroutines are designed to be C- callable, they will need function prototypes here.

; File: sci_driver.asm ECE 4436ECE 4436 INCLUDE "sci.inc“ ; port definitions ; Initialize SCI to 1 start, 8 data and 1 stop ; bit, no parity and 9600 Baud. ; Inputs: None ; Outputs: None ;*************************************** XDEF init_sci, initsci init_sci: initsci: pshd ; Save D reg ; Set 1 start, 8 data and 1 stop bit bclr SCICR1,MODE ; Disable parity for no parity bclr SCICR1,PE ; Enable transmitter and receiver bset SCICR2,TE|RE ; Set Baud rate ldd #B std SCIBDH puld ; Restore D rts

; Put char to SCI ; Send data to SCI ; Inputs: B register = data to send ; Outputs: None ;*************************************** XDEF put_sci, putchar put_sci: putchar: ; Wait until the transmit data reg is empty spin_put: brclr SCISR1,TDRE,spin_put ; Output the data and reset TDRE stab SCIDRL rts