Order this document
by AN1274/D
© Motorola, Inc., 1996 AN1274/D
AN1274
HC08 SCI Operation with Various Input Clocks
By Rick Cramer
CSIC MCU Product Engineering
Austin, Texas
INTRODUCTION
This application note describes the operation of the serial communications interface (SCI) as it relates to
the MC68HC708XL36 (XL36) with clock generation module A (CGMA). Specifically, the information here
provides an analysis of the effects of the input clock on the SCI baud rate. SCI communication in various
hardware applications is also examined, as well as code segments and listings.
GENERAL SCI INFORMATION
What is SCI?
SCI is a defined standard for transmitting and receiving data. Serial refers to the method used to transfer
data. This method uses one wire to transfer a data byte serially, that is, one bit at a time. Data also can be
transferred by a parallel method. A parallel data transfer uses eight wires to send eight bits of a byte of data
simultaneously. Figure 1 shows the serial hardware configuration, and Figure 2 shows the parallel.
Figure 1. Serial Hardware Configuration
MCU 1
D0, D1, D2, D3 ...
... D3, D2, D1, D0
MCU 2
F
re
e
sc
a
le
S
e
m
ic
o
n
d
u
c
to
r,
I
For More Information On This Product,
Go to: www.freescale.com
n
c
..
.
rxzb30
ForwardLine
AN1274
2
Figure 2. Parallel Hardware Configuration
Serial communication has an advantage over parallel data transfer because serial uses fewer connections
which results in a cheaper manufacturing cost. The drawback of using serial, however, is that this type of
communication generally makes a slower transfer than parallel.
The SCI is used in most applications to communicate with other microcontroller units (MCU) over a 2-wire
system. Using two wires allows full duplex operation. Essentially, both MCUs can transmit information to
each other simultaneously. Figure 1 shows full duplex operation.
Baud Rate
Baud rate is the rate in which the data is transferred. Baud rate also conveys the capacity of a data channel
and is expressed most commonly as bits per second (BPS). Although not exactly a correct definition, BPS
is often used synonymously with baud, and, for the purpose of this document, they are considered the
same. For example, if an SCI system is set to run at 1200 baud, 1200 bits of data can be transferred in one
second. This is a measure of speed and capacity. The bit period, which is the length of time required to
transfer one bit of data, is calculated by dividing one second by the baud rate. Therefore, the bit rate for a
1200-baud system is 8.334 x 10-4s, or 834 µs.
Input Clock
The input clock is a square wave that determines the chip speed. Ideally, the input clock could be set to any
frequency, and the chip could run as fast as it is driven. Realistically, however, the MCU can run only within
specific limits. Consult the appropriate technical data sheet for the device in use to determine its maximum
and minimum input clock frequencies. Typically for the XL36, the input clock frequencies range from 4 MHz
to 8 MHz. The input clock in the XL36 using CGMA is referred to as CGMXCLK.
MCU 1
D0
D1
D2
D3
D4
D5
D6
D7
CLOCK
MCU 2
F
re
e
sc
a
le
S
e
m
ic
o
n
d
u
c
to
r,
I
Freescale Semiconductor, Inc.
For More Information On This Product,
Go to: www.freescale.com
n
c
..
.
AN1274
3
How does the input clock affect the baud rate?
The input clock is related directly to the baud rate. This relationship is defined by the baud rate equation in
Figure 3.
Figure 3. Baud Rate Equation
In this equation, PD is the prescaler divisor and BD is the baud rate divisor. PD and BD are variables that
allow the user to change the baud rate; however, the baud rate continues to be directly related to
GCMXCLK. So when the CGMXCLK frequency is increased, the baud rate also increases.
Why are two communicating devices required to have the same baud rate?
When using the SCI system, no clock signal is sent with the data. A clock signal normally is used to tell the
receiving device when the bits of data should be read. Therefore, since no clock is sent with the SCI data,
the receiver must determine when each data bit is valid to read. This is done with critical timing. The
receiver marks the time when the first bit starts and then reads each following bit at the time they are
supposed to be valid at the receiver. If the receiver and transmitter are attempting to communicate at
different baud rates, the receiver will misread the incoming data, and errors will occur.
BASIC SCI OPERATION WITH
EQUAL INPUT CLOCK FREQUENCIES
The SCI operates easily under ideal conditions, such as these:
• Using two identical HC08 microcontrollers
• Operating both microcontrollers at the same input clock frequency
• Placing both microcontrollers adjacent to each other
• Allowing enough time in the application for a complete SCI transfer
• Accepting the default values of SCI parameters
• Operating the circuit at room temperature
An important point to realize is that the simplest way to use HC08 microcontrollers in unison is to leave
most of the registers at their default values. Since all XL36 microcontrollers have the same default value,
assuming that they will operate together is a fair assumption. Seven registers are associated with the SCI
operation on the XL36, but only three are needed. Figure 4 illustrates the process of using the SCI to
transmit data.
baud rate = CGMXCLK
64 x PD x BD
F
re
e
sc
a
le
S
e
m
ic
o
n
d
u
c
to
r,
I
Freescale Semiconductor, Inc.
For More Information On This Product,
Go to: www.freescale.com
n
c
..
.
AN1274
4
Figure 4. SCI Transmitter Operation
The flowchart in Figure 4 illustrates the basic operation of how the SCI transmits data. However, some
further explanations and a software code example are necessary. Appendix A: Basic SCI Transmitter
Code shows the implementation of the basic SCI operation. This code is mostly academic. For the code to
be of any actual value, the transmitted code must be received. Several variables are defined at the
beginning of the program. Notice that most variables are not used in the program code but are included to
provide a complete header of SCI code for later use.
BASIC SCI
TRANSMITTER
ENABLE SCI
ENABLE
TRANSMITTER
CLEAR SCI
TRANSMITTER
EMPTY BIT
WRITE DATA TO
DATA REGISTER
F
re
e
sc
a
le
S
e
m
ic
o
n
d
u
c
to
r,
I
Freescale Semiconductor, Inc.
For More Information On This Product,
Go to: www.freescale.com
n
c
..
.
AN1274
5
Connecting Two HC08s
Figure 5 shows how to cross-couple two MMDS08 emulators. Note that these signals are cross-coupled.
Essentially, TxD is connected to RxD on MMDS08 2.
Figure 5. Cross-Coupled MMDS08 Diagram
Once TxD and RxD are cross-coupled, software then can be written on the other MMDS08 to receive the
data being transmitted.
The flowchart in Figure 6 illustrates the basic operation of the SCI as it receives data. However, further
explanation and a software code example are necessary. Appendix B: Basic SCI Receiver Code shows
the implementation of the basic SCI receiver. This code is also mostly academic, since it is seldom that
only one character will be received. Additional code is necessary to demonstrate the flow of data between
two HC08 microcontrollers. Several variables are defined at the beginning of the program. Most of them
are not actually used in the program code but are included to provide a complete header of SCI code for
later use.
MMDS08 1
TOP COVER
68HC708XL36
TOP BOARD
CONNECTORS
MMDS08 2
TOP COVER
68HC708XL36
TOP BOARD
CONNECTORS
PTE2/TxD
PTE1/RxD
PTE2/TxD
PTE1/RxD
OPENING
OPENING
F
re
e
sc
a
le
S
e
m
ic
o
n
d
u
c
to
r,
I
Freescale Semiconductor, Inc.
For More Information On This Product,
Go to: www.freescale.com
n
c
..
.
AN1274
6
Figure 6. Basic SCI Receiver
Sending packets of information from one device to another is often necessary. For the purpose of this
application note, a packet is defined as a string of characters of data, which is variable in length and is
terminated with, but does not contain, the carriage return character (decimal value 13). For example, the
phrase, ’This is a test,’ as shown here, is a packet:
546869732069 DATA: fcb 'This is a test'
0D fcb 13
To better understand the SCI transmitter and receiver, see Figure 7 for an example of how to send packets
of data between two microcontrollers. By using the circuit diagram in Figure 5, new software is developed
to provide a smoother flow between the two chips.The Ping-Pong got its name from the back and forth
nature of its operation. One device sends a packet to the other. The receiving device then verifies that it
has received the correct information and sends a packet of information back to the original sender. This
creates a Ping-Pong effect such that when the data is viewed with an oscilloscope, the data actually
bounces from one device to the other and then back again. Appendix C: SCI Ping-Pong Code is the
software used to illustrate the Ping-Pong algorithm.
BASIC SCI
RECEIVER
ENABLE SCI
ENABLE
RECEIVER
RECEIVED A
CHARACTER?
READ DATA FROM THE
DATA REGISTER
YES
NO
F
re
e
sc
a
le
S
e
m
ic
o
n
d
u
c
to
r,
I
Freescale Semiconductor, Inc.
For More Information On This Product,
Go to: www.freescale.com
n
c
..
.
AN1274
7
Notice that there is much more flow control in Ping-Pong than in the previous two program examples. This
software can be classified as the first program described in this application note that can be used in
practice. Notice, too, the many similarities between the transmitting and receiving MCUs. Also notice that
the variable baud located in Appendix C: SCI Ping-Pong Code is set to $00. This value is updated in later
program examples to explain how to change that baud rate. The default reset value of the SCI baud rate
register is $00, which means that setting the value to $00 is the same as not setting it at all after a reset.
Figure 7. Ping-Pong Flowchart
PING-PONG
INITIALIZE
TRANSMITTER
TRANSMITTER
READY?
SEND NEXT DATA
BYTE
IS BYTE A $0D ?
TRANSMISSION
COMPLETE?
TURN OFF
TRANSMITTER
YES
YES
YES
NO
TO RECEIVE
RECEIVE
INITALIZE RECEIVER
RECEIVER
READY?
GET DATA BYTE
IS BYTE A $0D ?
TURN OFF RECEIVER
YES
YES
NO
TO PING-PONG
STORE DATA IN RAM
NO
NO NO
F
re
e
sc
a
le
S
e
m
ic
o
n
d
u
c
to
r,
I
Freescale Semiconductor, Inc.
For More Information On This Product,
Go to: www.freescale.com
n
c
..
.
AN1274
8
SCI OPERATION WITH UNEQUAL
INPUT CLOCK FREQUENCIES
When using unequal input clock frequencies, adjust the baud rate so that both devices operate at the same
rate. As shown in Figure 3, there is a direct relationship between the input clock and the baud rate. The
two divisors, PD and BD, are variables that allow the user to change the baud rate. The baud rate remains
directly related to GCMXCLK so that when the input clock frequency increases, the baud rate also
increases.
NOTENOTE
When using the XL36 with CGMA, the phase lock loop (PLL) settings have no
effect on the baud rate, even though changing the settings within the PLL cause
the MCU internal clock to operate at a different frequency. This happens because
the clock for the SCI is taken from the input clock and not the PLL output.
Figure 8 shows how to calculate the baud rate using the equation shown in Figure 3.
Figure 8. Baud Rate Calculation Example 1
baud rate =
CGMXCLK
64 x PD x BD
If using a 4.9152-MHz clock source and PD and
BD are set to one, the equation becomes:
baud rate =
4915200 Hz
64 x 1 x 1
baud rate = 76,800
F
re
e
sc
a
le
S
e
m
ic
o
n
d
u
c
to
r,
I
Freescale Semiconductor, Inc.
For More Information On This Product,
Go to: www.freescale.com
n
c
..
.
AN1274
9
Figure 9 shows that using the same settings but a different clock frequency produces a different baud rate.
Figure 9. Baud Rate Calculation Example 2
If these two previous example MCUs were configured similarly to those in Figure 5, communication
between them would not occur, because they operate at different baud rates. Appendix D: SCI Baud
Rate Chart shows these two input clock frequencies. To allow these two example MCUs to communicate,
pick a baud rate that is common between both sets. For example, choose 600 baud, which is common to
both sets. For an 8-MHz input clock, use PD = 13 and BD = 16. For a 4.9152-MHz input clock, use PD = 4
and BD = 32. See Figure 10 for more information.
Figure 10. Baud Rate Calculation Example 3
baud rate =
CGMXCLK
64 x PD x BD
If using a 8.000-MHz clock source and PD and
BD are set to one, the equation becomes:
baud rate =
8000000 Hz
64 x 1 x 1
baud rate = 125,000
baud rate =
CGMXCLK
64 x PD x BD
If using an 8.000-MHz clock source, PD = 13,
and BD = 16, the equation becomes:
baud rate =
8000000 Hz
64 x 13 x 16
baud rate = 600.96
baud rate =
CGMXCLK
64 x PD x BD
If using a 4.915-MHz clock source, PD = 4,
and BD = 32, the equation becomes:
baud rate =
4915200 Hz
64 x 4 x 32
baud rate = 600.00
F
re
e
sc
a
le
S
e
m
ic
o
n
d
u
c
to
r,
I
Freescale Semiconductor, Inc.
For More Information On This Product,
Go to: www.freescale.com
n
c
..
.
AN1274
10
Although the baud rates are not exactly equal, they are close enough to work properly. Baud rates should
be within 3.4% of each other to operate properly. See Figure 11 for more information.
Figure 11. Baud Rate Deviation Equation
If one MCU operates at 600 baud, the other may operate at as much as 2.04 baud out of frequency, which
is 602.04 baud. So as shown in Figure 10, the baud rate of 600.96 is well within the 3.4% deviation limit
and, therefore, will work properly in this implementation.
SCI OPERATION WITH
COMMONLY USED BAUD RATES
Baud rates are used widely when communicating with modems. Modems are devices that convert binary
data into audible frequencies that can be sent across a normal telephone line. Modems also can receive
these frequencies and convert them back into digital data. The SCI format is in exactly the same format as
that used by most modems. The only difference is the voltage levels. The SCI operates at the voltage
supplied to the VDD pin and the voltage supplied at the VSS pin (commonly +5 V and 0 V, respectively).
Since standard modems (or the RS-232 standard) require the voltage be +12 V and –12 V, circuitry is
necessary to convert the levels of the MCU to these standard RS-232 levels. The MC1488 and MC1489
shift voltage levels to meet the RS-232 standard. Figure 12 shows how to connect these chips to a
modem.
Figure 12. Modem Circuit
baud rate deviation = 600 x 0.034
= 2.04
baud rate = baud rate + baud rate deviation
= 600
= 602.04
+ 2.04
MCU MODEM
1/4 MC1488
+12 V
–12 V
+5 V
1/4 MC1489
GND
TxD
RxD
F
re
e
sc
a
le
S
e
m
ic
o
n
d
u
c
to
r,
I
Freescale Semiconductor, Inc.
For More Information On This Product,
Go to: www.freescale.com
n
c
..
.
AN1274
11
Typically, the baud rate between the modem and the MCU is higher than the baud rate between the
modem and another modem. This is because modern modems have become so advanced that they
automatically can sense the maximum baud rate of the second modem. As long as the link between the
MCU and modem is as high as possible, the modem will, in most cases, find the highest baud rate. Over
the years of modem development, several baud rates have been chosen. These are 300, 1200, 2400,
4800, 9600, 14400, 19200, 28800, 38400, and 57600.
To communicate with a modem, choose one of these baud rates. For instance, to communicate with a
1200-baud modem using the MC1488 and MC1489 chips as shown in Figure 12, choose 1200 from the
baud rate chart. See Appendix D: SCI Baud Rate Chart. For a clock input frequency of 8 MHz, choose
PD = 13 and BD = 8. This gives a baud rate of 1201.92. Using the baud rate deviation equation in Figure
13, calculate that the maximum deviation of the baud rate at 1200 baud is 4.08 as shown.
Figure 13. Baud Rate Deviation Equation
This allows a baud rate between 1204.08 and 1195.92. Since the chosen baud rate is 1201.92, it is within
tolerable limits.
baud rate deviation = 1200 x 0.034
= 4.08
baud rate = baud rate + baud rate deviation
= 1200
= 1204.08
+ 4.08
F
re
e
sc
a
le
S
e
m
ic
o
n
d
u
c
to
r,
I
Freescale Semiconductor, Inc.
For More Information On This Product,
Go to: www.freescale.com
n
c
..
.
AN1274
12
Appendix A: Basic SCI Transmitter Code
*********************************************************************
** Basic SCI Transmitter program **
** By Rick Cramer **
** 25 November 1995 **
**-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**
** **
** This program illustrates the basic operation of transmitting **
** data using the SCI on the 68HC708XL36 using CGMA. **
*********************************************************************
*-------------------------------------------------------------------*
DATA EQU $55 ; Data to transmit
*-------------------------------------------------------------------*
SCC1 EQU $13 ; SCI Control Register 1
LOOPS EQU 7 ; Bit 7: Loop Mode Select Bit
ENSCI EQU 6 ; Bit 6: ENable SCI Bit
TXINV EQU 5 ; Bit 5: Transmit Inversion Bit
M EQU 4 ; Bit 4: Mode (Character Length) Bit
WAKE EQU 3 ; Bit 3: Wake-up Condition Bit
ILTY EQU 2 ; Bit 2: Idle Line Type Bit
PEN EQU 1 ; Bit 1: Parity Enable Bit
PTY EQU 0 ; Bit 0: Parity Bit
*-------------------------------------------------------------------*
SCC2 EQU $14 ; SCI Control Register 2
SCTIE EQU 7 ; Bit 7: SCI transmit Interrupt Enable Bit
TCIE EQU 6 ; Bit 6: Transmission Complete Interrupt Enable
; Bit
SCRIE EQU 5 ; Bit 5: SCI Receive Interrupt Enable Bit
ILIE EQU 4 ; Bit 4: Idle Line Interrupt Enable Bit
TE EQU 3 ; Bit 3: Transmitter Enable Bit
RE EQU 2 ; Bit 2: Receiver Enable Bit
RWU EQU 1 ; Bit 1: Receiver Wake Up Bit
SBK EQU 0 ; Bit 0: Send Break Bit
*-------------------------------------------------------------------*
SCC3 EQU $15 ; SCI Control Register 3
R8 EQU 7 ; Bit 7: Received Bit 8
T8 EQU 6 ; Bit 6: Transmitted Bit 8
DMARE EQU 5 ; Bit 5: DMA Receive Enable Bit
DMATE EQU 4 ; Bit 4: DMA Transfer Enable Bit
ORIE EQU 3 ; Bit 3: Receiver Overrun Interrupt Enable Bit
NEIE EQU 2 ; Bit 2: Receiver Noise Error Interrupt Enable
; Bit
FEIF EQU 1 ; Bit 1: Receiver Framing Error Interrupt Enable
; Bit
PEIE EQU 0 ; Bit 0: Receiver Parity Error Interrupt Enable
; Bit
*-------------------------------------------------------------------*
SCS1 EQU $16 ; SCI Status Register 1
SCTE EQU 7 ; Bit 7: SCI Transmitter Empty Bit
TC EQU 6 ; Bit 6: Transmission Complete Bit
SCR
本文档为【AN1274-HC08 SCI Operation with Various Input Clocks】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑,
图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。