Date post: | 30-May-2018 |
Category: |
Documents |
Upload: | nguyen-trinh-thanh-vinh |
View: | 217 times |
Download: | 0 times |
of 29
8/14/2019 Serial Communications: 2 Flavors: Synchronous
1/29
10/19/2005 ECE 340 Fall 2004 Lecture 23 1
Serial I/O
Serial Communications: 2 Flavors:Synchronous Asynchronous
Synchronous Communications
Requires clock signal Data bits may be non-uniformly spaced!
Can operate at faster data rates than
asynchronous serial I/O Clock signal synchronizes data transfers
8/14/2019 Serial Communications: 2 Flavors: Synchronous
2/29
10/19/2005 ECE 340 Fall 2004 Lecture 23 2
Serial I/O
Asynchronous Communications
No clock is required
Additional overhead in message to manage
synchronization
Data bits must be uniformly spaced!
Data rates: 110B 115KB
Common use:
PC serial ports
Point to point communications
8/14/2019 Serial Communications: 2 Flavors: Synchronous
3/29
10/19/2005 ECE 340 Fall 2004 Lecture 23 3
Asynchronous Communications
RS232 Standard Reference WEB site: http://www.camiresearch.com/Data_Com_Basi
cs/RS232_standard.html
Voltage levels areNOTTTL!
8/14/2019 Serial Communications: 2 Flavors: Synchronous
4/29
10/19/2005 ECE 340 Fall 2004 Lecture 23 4
Asynchronous Communications
Definition: BAUD The inverse of the period of a unit symbol.
Protocol -
8/14/2019 Serial Communications: 2 Flavors: Synchronous
5/29
10/19/2005 ECE 340 Fall 2004 Lecture 23 5
Asynchronous Communications
8/14/2019 Serial Communications: 2 Flavors: Synchronous
6/29
10/19/2005 ECE 340 Fall 2004 Lecture 23 6
Asynchronous Communications
Parity Options: None, Odd, and Even None: Parity bit is omitted. Character
terminated with a stop bit
Even: Logic level of the parity bit is set tomake the total number of logic one states (data
plus parity bit) evenly divisible by 2.
Odd: Logic level of the parity bit is set to make
the total number of logic one states (data plusparity bit)not evenly divisible by 2.
8/14/2019 Serial Communications: 2 Flavors: Synchronous
7/29
10/19/2005 ECE 340 Fall 2004 Lecture 23 7
UART Block Diagram
Baud Rate Generator, Transmitter, and Receiver.
Transmitter transmits using Baud Clock
Receiver Samples using faster clock (8x Baud Clock)
8/14/2019 Serial Communications: 2 Flavors: Synchronous
8/29
10/19/2005 ECE 340 Fall 2004 Lecture 23 8
Reciver
From idle state, waits 4 cc after RXD drops, then samples
every 8 cc
Packet always starts with RXD low (start bit) and ends with
RXD high (stop bit)
8/14/2019 Serial Communications: 2 Flavors: Synchronous
9/29
10/19/2005 ECE 340 Fall 2004 Lecture 23 9
Serial Communications ASCII American Standard Code for
Information Interchange
8/14/2019 Serial Communications: 2 Flavors: Synchronous
10/29
10/19/2005 ECE 340 Fall 2004 Lecture 23 10
Serial Communications
Standard Connectors: 9 pin and 25 pin
(legacy)
DTE Data terminal equipment TheComputer!
DCE Data communications equipment The
modem
Full standard includes clock (for sync),
secondary data channel, and flow control
8/14/2019 Serial Communications: 2 Flavors: Synchronous
11/29
10/19/2005 ECE 340 Fall 2004 Lecture 23 11
8/14/2019 Serial Communications: 2 Flavors: Synchronous
12/29
10/19/2005 ECE 340 Fall 2004 Lecture 23 12
8/14/2019 Serial Communications: 2 Flavors: Synchronous
13/29
10/19/2005 ECE 340 Fall 2004 Lecture 23 13
Common Configurations
Direct Extension (e.g., DTE -> DCE)
Wire straight across
Loopback
Allows a DTE to talk to itself
Null Modem (e.g., DTE -> DTE)
Connecting two computers via RS232
8/14/2019 Serial Communications: 2 Flavors: Synchronous
14/29
10/19/2005 ECE 340 Fall 2004 Lecture 23 14
Direct Extension (DB9)
8/14/2019 Serial Communications: 2 Flavors: Synchronous
15/29
10/19/2005 ECE 340 Fall 2004 Lecture 23 15
Loopback (DB9)
ConnectsRX to TX
8/14/2019 Serial Communications: 2 Flavors: Synchronous
16/29
10/19/2005 ECE 340 Fall 2004 Lecture 23 16
Null Modem (DTE to DTE)
8/14/2019 Serial Communications: 2 Flavors: Synchronous
17/29
10/19/2005 ECE 340 Fall 2004 Lecture 23 17
Modem to Modem (DCE to DCE)
8/14/2019 Serial Communications: 2 Flavors: Synchronous
18/29
10/19/2005 ECE 340 Fall 2004 Lecture 23 18
Gotcha!!!
8/14/2019 Serial Communications: 2 Flavors: Synchronous
19/29
10/19/2005 ECE 340 Fall 2004 Lecture 23 19
Rabbit - Asynchronous Serial
Communications UI Lab Project board:
Port D DCE
Port C DTE
Rabbit Serial Port Initialization (Port D)#use rs232.lib
#define DINBUFSIZE 64 // Arbitrary
#define DOUTBUFSIZE 64 // Arbitrary
#define _232BAUD 19200
serDopen(_232BAUD);
serDwrFlush();
serDrdFlush();
8/14/2019 Serial Communications: 2 Flavors: Synchronous
20/29
10/19/2005 ECE 340 Fall 2004 Lecture 23 20
Rabbit - Asynchronous Serial
CommunicationsserDopen
SYNTAX: int serDopen(long baud);
DESCRIPTION: Opens the D serial port.
This function is non-reentrant.
PARAMETER1: baud : bits per second of data transfer
RETURN VALUE:1: The baud set on the rabbit is the same as the input baud
0: The baud set on the rabbit does not match the input baud
RELATED WORDS: serDgetc, serDpeek, serDputs, serDwrite,
cof_serDgetc, cof_serDgets, cof_serDread, cof_serDputc, cof_serDputs,
cof_serDwrite, serDclose
8/14/2019 Serial Communications: 2 Flavors: Synchronous
21/29
10/19/2005 ECE 340 Fall 2004 Lecture 23 21
Rabbit - Asynchronous Serial
CommunicationsserDwrFlush
SYNTAX: void serDwrFlush();
DESCRIPTION: Flushes the serial port D transmit buffer.
This function is non-reentrant.
PARAMETER1: None
RETURN VALUE: None
serDrdFlush
SYNTAX: void serDrdFlush();
DESCRIPTION: Flushes the serial port D input buffer.
This function is non-reentrant.
PARAMETER1: None
RETURN VALUE: None
8/14/2019 Serial Communications: 2 Flavors: Synchronous
22/29
10/19/2005 ECE 340 Fall 2004 Lecture 23 22
Rabbit - Asynchronous Serial
CommunicationsserDputc
SYNTAX: int serDputc(char c);
DESCRIPTION: Write a character to serial port D write buffer.
This function is non-reentrant.
PARAMETER1: c: Character to write to serial port D write buffer
RETURN VALUE: 0 if buffer locked or full, 1 if character sent
serDgetc
SYNTAX: int serDgetc();
DESCRIPTION: Get next available character from serial port D read buffer.
This function is non-reentrant.
PARAMETER1: None
RETURN VALUE: success: the next character in the low byte, 0 in the high byte
failure: the integer -1
8/14/2019 Serial Communications: 2 Flavors: Synchronous
23/29
10/19/2005 ECE 340 Fall 2004 Lecture 23 23
Rabbit - Asynchronous Serial
CommunicationsserDpeek
SYNTAX: int serDpeek();
DESCRIPTION: Returns the 1st character of the data in the D input buffer.
This function is non-reentrant.
PARAMETER1: NoneRETURN VALUE: -1 if the buffer is empty, the 1st character of the data if not
serDputs
SYNTAX: int serDputs(char* s);
DESCRIPTION: Calls serDwrite(s, strlen(s)); does not write null terminator.
This function is non-reentrant.
PARAMETER1: s: Null terminated character string to write
RETURN VALUE: The number of characters successfully written to serial port D.
8/14/2019 Serial Communications: 2 Flavors: Synchronous
24/29
10/19/2005 ECE 340 Fall 2004 Lecture 23 24
Rabbit - Asynchronous Serial
Communications
serDwrite
SYNTAX: int serDwrite(void *data, int length);
DESCRIPTION: Transmits length bytes to serial port D.This function is non-reentrant.
PARAMETER1: data : data structure to write to serial port D
length: number of bytes to write
RETURN VALUE:The number of bytes successfully written to serial port D.
8/14/2019 Serial Communications: 2 Flavors: Synchronous
25/29
10/19/2005 ECE 340 Fall 2004 Lecture 23 25
Formatted Buffer Writes
sprintf
SYNTAX: int sprintf(char *buffer, char *format, ...);
KEYWORDS:
DESCRIPTION: This function takes a "format" string (pointed to by "format"),arguments of the format, and output the formatted string to "buffer"
(pointed to by "buffer"). The user should make sure
(1) there are enough arguments after "format" to fill in the format parameters in the
format string
(2) the types of arguments after "format" match the format fields in "format"
(3) buffer is large enough to hold the longest possible formatted string
8/14/2019 Serial Communications: 2 Flavors: Synchronous
26/29
8/14/2019 Serial Communications: 2 Flavors: Synchronous
27/29
10/19/2005 ECE 340 Fall 2004 Lecture 23 27
Formatted Buffer Writes
Example: sprintf(buffer,"%s=%x","variable x",256) should put the string "variable
x=100" into buffer.
The macro STDIO_DISABLE_FLOATS can be defined if it is not necessary to
format floating point numbers. If this macro is defined, %e, %f and %g will not be
recognized. This can save thousands of bytes of code space. This function can be
called by processes of different priorities.
RETURN VALUE: The number of characters written
8/14/2019 Serial Communications: 2 Flavors: Synchronous
28/29
10/19/2005 ECE 340 Fall 2004 Lecture 23 28
Example#define CINBUFSIZE 15
#define COUTBUFSIZE 15
#define DINBUFSIZE 15
#define DOUTBUFSIZE 15
// change serial baud rate here#ifndef _232BAUD
#define _232BAUD 115200
#endif
main() {
auto int nIn1, nIn2;
auto char cOut;
long time;
serCopen(_232BAUD); serDopen(_232BAUD);
serCwrFlush(); serCrdFlush(); serDwrFlush(); serDrdFlush();
8/14/2019 Serial Communications: 2 Flavors: Synchronous
29/29
10/19/2005 ECE 340 Fall 2004 Lecture 23 29
for (cOut='a'; cOut