SERIAL COMMUNICATION INTERFACE (SCI)
MOTOROLA
PORT C
6 - 63
is enabled but the interrupts are masked, which prevents the SCI from transmitting
or receiving data at this time.
The circular buffers used have two pointers. The first points to the first data byte; the sec-
ond points to the last data byte. This configuration allows the transmit buffer to act as a
first-in first-out (FIFO) memory. The FIFO can be loaded by a program and emptied by the
SCI in real time. As long as the number of data bytes never exceeds the buffer size, there
will be no overflow or underflow of the buffer. Registers M0-M3 must be loaded with the
buffer size minus one to make pointer registers R0-R3 work as circular pointers. Register
N2 is used as a constant to clear the receive buffer empty flag.
The main program starts by filling the transmit buffer with a data packet. When the trans-
mit buffer is full, it calls the subroutine that transmits the slave’s address and then jumps
to self (SEND jmp SEND), allowing interrupts to transmit and receive the data.
The receive subroutine first checks each byte to see if it is address or data. If it is an ad-
dress, it compares the address with its own. If the addresses do not match, the SCI is put
back to sleep. If the addresses match, the SCI is left awake, and control is returned to the
main program. If the byte is data, it is placed in the receive buffer, and the receive buffer
empty flag is cleared. Although this flag is not used in this program, it can be used by an-
other program as a simple test to see if data is available. Using N2 as the constant $0
allows the flag to be cleared with a single-word instruction, which can be part of a fast in-
terrupt.
The transmit subroutine transmits a byte and then checks to see if the transmit buffer is
empty. If the buffer is not empty, control is returned to the main program, and interrupts
are allowed to continue emptying the buffer. If the buffer is empty, the transmit buffer emp-
ty flag is set, the transmit interrupt is disabled, and control is returned to the main program.
The wakeup subroutine transmits the slave’s address by writing the address to the STXA
register and by enabling the transmit interrupt to allow interrupts to empty the transmit
buffer. Control is then returned to the main program.
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
.
..