Order this
document
as AN429/D
MOTOROLA
SEMICONDUCTOR
APPLICATION NOTE
AN429
MC68332
QSPI
interface
for
the
MCM2814
EEPROM
By
Mark
Malolani
Motorola
Semiconductors
Ltd
East
Kilbride
Glasgow
INTRODUCTION
This application note
describes
the
software
and
hardware
necessary
to use
the
MCM2814
serial
EEPROM
with
the
MC68332
Queued
Serial
Peripheral
Interface,
or
OSPI.
As
well
as
giving
specific
details
on
accessing
the
MCM281
4
EEPROM
with
the
OSPI.
this
application note
can
also
be
used
to
provide
general
information
on
configuring
and
using
the
OSPI
with
SPI
compatible
devices.
The
main
areas
covered
are
hardware
configuration,
the
general
operation
of
the
OSPI
and
a
description
of
software
which
allows
programming
and
reading
data
from
the
MGM2814. Information
on
interfacing
the
software
with
high
level
‘C’
language
programs
is
also
covered,
with
a
short
demonstration
program
included.
HARDWARE
CONFIGURATION
Figure
1
shows
a
simple
system
with
four
MCM2814
EEPROMs
connected
directly
to
the
MG68332
OSPI.
The
MCM2814
is
a
serially
accessed 256
byte
FEPROM,
which
can
be
used
in
either
IC
or
SPI
protocol
systems.
In
this
application
SPI
mode
is
selected
by
pulling
the
MCM281
4
MODE
pin
to
the
..-5V
supply
level,
Vdd.
As
the
MCM2814
generates
its
programming voltage
(Vpp)
internally,
only
a
single
5V
supply
is
necessary.
In
the
simplest
configuration, selection
of
the
individual
EEPROMs
is
accomplished
by
connecting
the
OSPI slave
select
lines,
PCSO-3,
directly
to
the
MCM2814
SPI
slave
select
lines,
SPISS.
With
this
configuration
a
maximum
of
four
EEPROMs
or
other
SPI
devices
can
be
individually
selected.
If
more
than
four
devices
are
to
be
connected
to
the
SPI
bus,
a
decoder
can
be
added
to
select
a
maximum
of
15
devices.
P053
P052
PcS1
PcSo
MC68332
OSPI
MISO
MOSI
50K
1
Vdd
2
5
7
SPISS
MODE
SPISO
SPISI
SPICK
MCM281
4
#0
1
SPISS
Vdd
MODE
2
5
7
SPISO
SPISI
SPICK
MCM281
4
#1
1
SPISS
Vdd
MODE
2
5
7
SPISO
SPISI
SPICK
MCM281
4
#2
—m
1
SPISS
Vdd
MODE
2
5
7
SPISO
SPISI
S
PIG
K
MCM281
4
#3
Figure
1
Basic
Hardware
MOTOROLA
U
AN429/D
C
MOTOROLA
LTD.
1990
SPI
AND
OSPI
OVERVIEW
The
SPI
bus
consists
oftwo
serial
data
lines,
a
clock
line
and
one or
more
slave
select
lines.
The
two
data
lines,
MOSI and
MISO, are
used by
the
master
device
on
the
bus
to
transmit
and
receive
data
respectively.
The
clock
and
slave
select
lines,
designated
SCK
and P050-3
on
the
OSPI.
are
gener-
ated
by
the
master,
which
in
this
case
is
the
OSPI.
When
the
SPI
master
accesses
a
particular
SPI
device,
the
slave
select
line
for
that
particular
device
is
driven
low
before
the
required
number
of
bits
are
transferred
during
SCK
transitions.
The
SPI
protocol defines
that
data
transmission
and
recep
-
;,on
always
occur
simultaneously,
as
while
data
is
transmit-
ed
from
the
master
on
the
MOSI
line,
data
is
being
received
~iong
the MISO
line.
If
the
master
only
has
to
read
data
from
levice,
it
may
transmit
uninitialised
or
‘don’t
care’
values
:i’ng
MOSI,
and
conversely
if
the
master
only
has
to
write
~ta
to
a
device
it
may ignore
the
data
received
along
MISO.
3
enhancements
of
the
OSPI
over
the
SPI
consist
mainly
the
queued
architecture
of
the
OSPI.
Rather
than
having
program
each
individual
transfer
before
it
is
transmitted,
as
on
the
SPI,
the
OSPI
can
be configured
to
automatically
carry
out
a
number
of
transfers
without
intervention
from
the
processor.
Each
transfer
can
be
individually
configured
to
access
a
specific
device
by
using
the
PCSO-3
lines.
Individual
control
of
the
number
of
bits
per
transfer,
bus
timing
delays
and
the
state
of
the
PCS
lines
between
transfers
is
also
possible.
The
transfer
data
and
control
information
is
contained
in
three
queues:-
the
receive
data
queue
RECRAM,
the
trans
-
mit
data
queue
TRANRAM
and
the
command
data
queue
COMD.RAM.
The
transmit
and receive
queues
are
16
bits
wide, although
each
SPI
transfer
can
be
from
8
to
16
bits
long,
defined
by
BITS
of
register
SPCRO
and
BITSE
of
the
command entries.
The
command
data
queue
is
byte
wide,
with
each
byte
configuring
various
aspects
of
one
transfer,
such
as
the
number
of
bits
in
the
transfer,
bus
delays
and
device
selection.
Figure
2
shows
the
bit
usage
of the
command
bytes.
All
three queues
are
16
entries
deep,
resulting
in
32
bytes
each
for
the
transmit
and
receive
data
queues
and
16
bytes
for
the
command
queue
bits.
Command
Queue Entry
7 6 5
432
ICONTIBtTSE
DT OSOKI P0531
P052
P0511
P050
STATE
ACTION
o
Slave
Select Lines
POS
3-0
return
to
default
states,
as
defined
in
QPDR,
between
transfers
1
POS
3-0
do
not
change
between
transfers
0
Transfer
length defaults
to
8 bits
1
Bits
field
of
SPORO
defines
transfer
length
(8
-
16
bits)
o
Default
delay
of
17
clocks
after
each
transter
1
Delay
specified
by
DTL
field
of
SPORi
0
1
Default
delay
of 1/2
clock
between
device
selection
and
transfer
Delay
specified by
DSCKL
field
of
SPORi
Defines
the state
of
the
slave
select
lines PCS3-0
during
transfer
FIgure
2—
Command
entry
format
1
0
BIT
CONT
BITSE
DT
OSCK
P053-0
MOTOROLA
AN429/D
NVMRWC
SOFTWARE
-
OVERVIEW
The
MC68332
assembly
language
software,
NVMRWC,
contains routines
to
both
read
and
write
EEPROM data
via
the
OSPI,
and
is
configured
to
be
called
as
a
function
from
a
C
language
program.
The
read
routine
is
entered
at <ee_read>,
and
is
used
to
read
up
to
29
bytes
of
data
starting
from
any MCM281
4
location.
Figures
3
and
4
show
the
main
program
flow
for
the
read
action,
and
an
example
read
operation.
QSTART~ee
read>
)
Store
registers
on
local
stack
area
Start
transfers by
enabling
OSPI
The
write
routine
starts
at
<ee_write>,
and
is
able
to
write
up
to
4
bytes
of
data
starting
at
any
location,
as
long
as
all
of
the
bytes
are
within
a 4
byte boundary. This
limitation
is
due
to
the
operation
of
the MCM2814,
which
is
detailed
in
the
data
sheet
for
the
device. Program
flow
for
the
write
action
and
an
example
transfer
are
shown
in
figures
5
and
6.
15
Transmit Data
Queue
TRAN.RAM
87
0
READ
($A7)
Address
($20)
xx xx
xx xx
xx xx
Entry
0
Entry
1
Entry
2
Entry
3
-L
.1
15
Receive
Data
Queue
REC.RAM
87
0
2~X
XX
~I~QA~1a
~xI~$2~dat~ ~a~1a
L
Entry
0
Entry
1
Entry
2
Entry
3
,j-
Command Queue CMD.RAM
CONT/BITSE/DT/DSCK
PCS3-0
7 6 5 4 3210
I.-
Example queue set-up
for
a
read
of
5
bytes
of
data
starting
from
MCM2814 address
$20.
with
the
device
select code,
(PCS3-O), set
to
0010.
Note
the
use of
16
bit
transfers
for
each
two
bytes
of
data.
XX
is
un-initialised
or
unused
data,
underlined
data
is
received
from
MCM2814.
FIgure
3
EEPROM
read
flowchart
FIgure
4
EEPROM
read
example
Wait
until
QSPI
has
finished
any
pending
transfers
before
initializing
<OSPINIT>
Get
passed
parameters
from
‘C’
call
[
I——
Initialize
transmit
data
queue,
command
queue
and
main
QSPI
control
registers
using
parameters from
C’
call
K
U—”
Has
OSPI
finished
transfers?
1 1
1
0 0010
1 1
1
0 0010
1 1
1
0
0010
0
1
1
0
0010
Copy
data from
receive queue
into
‘C’
parameter
area
using
MC68332
loop
mode
~PASSL
00Th
Entry
0
Entry
1
Entry
2
Entry
3
AN429/D
MOTOROLA 3
START
.~ee
write>
)
Store
registers
on
local
stack
area
Wait
until
OSPI
has
finished
any
pending transfers before
initializing
<OSPINIT>
Get
passed
parameters from ‘0’
call
:uitialize
transmit data queue,
command
queue
and
main
OSPI
control
registers
using
parameters from
‘C’
call
~1
15
Transmit Data Queue
TXD.RAM
87
0
XX
Vpp
ON
($A6)
XX
WRITE
($A2)
XX
Address
($10)
XX
Data
($AA)
XX
Data
($55)
XX
Vpp
OFF
($A4)
F
15
———-I
Receive
Data
Queue
REC.RAM
87
0
XX
XX
XX
XX
XX
XX
Xx
XX
XX
XX
XX
XX
Start
transfers by
enabling
OSPI
Command Queue CMD.RAM
Has
programming
delay
elapsed?
NO
YES
Initialise
SPCR2
to
send
Vpp
OFF
command
Figure
5—
EEPROM
wrIte
flowchart
CONT/BITSE/DT/DSCK
7
65
4
PCS3-0
3210
0 0
1
0 0001
1
0
1
0 0001
1
0
1
0 0001
1
0
1
0 0001
0 0
1
0 0001
0 0
1
0 0001
L 4
Example
queue
set-up for
a
write
of
3
bytes
of
data starting
from
MCM2814 address
$10,
with
the
device
select
code, (PCS3-0),
set
to
0010.
XX
is
un-initialised
or
unused data,
underlined data
is
received
from
McM2814.
Figure
6
EEPROM
wrIte
example
Entry
0
Entry
1
Entry
2
Entry
3
Entry
4
Entry
5
Entry
0
Entry
1
Entry
2
Entry
3
Entry
4
Entry
5
Entry
0
Entry
1
Entry
2
Entry
3
Entry
4
Entry
5
AN429/D
WORKSPACE
ALLOCATION
-
LINK.
UNLK
AND
MOVEM
The
routines
<ee_read>
and
<ee_write>
return
with
all
processor
registers restored
to
their
origimal
state.
To
ac
-
complish
this,
the registers
are
written
to
the
stack
on
entry,
and
recovered
before returning.
The
instruction,
LINK
A6,#&-28,
creates
a
28
byte
stack
frame
for
this
purpose
by
moving
the
stack
pointer.
A7,
past
the
reserved
area,
and
loading
A6
to
act
as
the frame
pointer.
Storing
the
processor
registers
is
accomplished
in
a
single
instruction
by
the MOVEM
(move
multiple)
command.
MOVEM.L
DO/D1/D2/D3/AO/A1/A2,(A71
stores
all
of
the
listed
registers
as
long
words
starting
at
the
address
pointed
to
by
the
stack
pointer
A7.
As
the
LINK
instruction
sets
A7
to
point
to
the
lowest
address
of
the
reserved
28
bytes,
all
of
the
registers
are
stored
in
this
area.
Figure
7
shows
the
stack
organisation
in
detail.
The
MOVEM
instruction
is
used
again
at
the
end
of
the
program,
with
the
order
of
the
operands reversed,
to recover
the
register
values,
and
the reserved
stack
area
is
deallo
-
cated
by
the
UNLK
(unlink)
instruction.
This
recovers
the
original
value
of
the
specified
local
stack
pointer,
A6,
and
resets
the
main
stack
pointer,
A7,
to
its
previous
value.
(Stack
pointer
A7
—b
-
after
LINK)
(AG
after
LINK)
(Stack
pointer
A7
before
LINK)
DO
Dl
D2
D3
AO
Al
A2
Temporary store
of
AG
‘C’
return address
Parameter
‘DEV’
Parameter
‘ADDR’
Parameter
‘BYTE
COUNT’
Address
of
array
‘BYTE
BUFFER
br
Un-used stack
28
bytes
reserved by
LINK
(contents
after
MOVEM)
I
Stack
condition
on
entry
Long
word
(4
byte)
width
FIgure
7
Stack
allocatIon
AN429/D
Decreasing
address
MOTOROLA
5
INITIALISING
THE
OSPI
Before
the
OSPI
is used
for
an
EEPROM
read
or
write,
it
is
initialised
to
the
desired
startup
state.
The
subroutine
<OSPIN IT>
allows
the
OSPI
to
complete
any
pending
trans-
fers
before
it
is
stopped
and
initialised.
At
this
stage
initiali
-
sation
consists
mainly
of
configuring the
OSPI
hardware
by
assigning
the
lines
MISO,MOSI,SCK and
PCSO-3
to
the
OSPI.
with
MOSI
and
PCSO-3
set
as
outputs
which
default
high.
The
OSPI
is
also
set
to non
wired-or
outputs
and
SPI
master
with
a
clock
rate of
100KHz
at
this
point.
Note
that
if
it
is
known
the
OSPI
will
be
idle
and
in
a
suitable
state
when
an
EEPROM
read
orwrite
is
requested,
or
if it
is
acceptable to halt
the
OSPI
with
transfers
pending,
the
initialisation
subroutine could
be
simplified,
FUNCTION
PARAMETER
PASSING
-
MC68332
LOOP
MODE
.A.’hen
either reading or
writing
EEPROM
data,
the
software
~s
to retrieve
the
parameters
that
the
C
program
has
placed
.~
the
stack.
NVMRWC
is
configured
to
work
with
a
C
2ompiler
that
passes
the
variables
in
the
stack
locations
‘wn
in
figure
7.
If
the
C
compiler
passes
the
variables
in
fferent
manner, the
program
must
be
altered
accord
-
v.
The
parameters
are
initially
stored
in
the
MC68332
mal
registers
as
follows:-
I
Address
in
MC68332
memory
of
the
C
data
array,
<BYTE_BUFFER>
0
Number
of
bytes
to
transfer,
<BYTE_COUNT>
MCM2814 starting
byte
address,
<ADDR>
Note
that
Al
is
the memory
address
of
the
main
C
array,
rather
than
the
actual
data.
This
allows
NVMRWC
to
read
or
modify
the
data
in
the
array
when
necessary
by
using
Al
as
a
pointer.
An
example
of
this
is
when
the
EEPROM
data
is
passed
back
to
the
array
after
a
read
in
the
routine
<PAS
-
SLOOP>.
This
program
section
uses
a
MOVE
instruction
to
copy
a
byte
of
data
from
the
OSPI
receive
data
queue
to
the
array,
and
a
decrement
if
false,
or
DBF
instruction
to cause
the
program
to
loop
around
until
a
count
register
reaches
0.
As
the
MOVE
instruction
occupies
one
word, the
MC68332
automatically
enters
‘Loop
Mode’
when
this
program
sec-
tion
is
encountered.
When
in
this
mode,
no
instruction
fetches
are
made to
memory,
thus
greatly speeding
execu-
tion.
Device selection
code
for
PCSO-3
pins,
<DEV>
TRANSMIT
DATA
QUEUE
INITIALISATION
The
transmit
data queue
has
to
be
initialised
with
the
correct
sequence
of
MCM2814
commands
and
data
before
an
E E
PROM
read
or
write
can
be
carried
out.
Reading data
from
the
E E
PROM
uses
the simplest
sequence, consisting
of
the
following>
MCM2814
READ
command
1SA7)
Starting
byte
address
to
be
read
The
remainder
of
the
transmit
queue
does
not
need
to
be
initialised,
as
after
this
sequence
has
been
sent
the
MCM28l
4
transmits
data,
and
no
longer monitors
incoming
data.
Because
the
MCM281
4
remains selected
between
all
of
the
individual
byte
transfers,
the
full
16
bit
width
of
the
data
queues
can
be
used
to
increase
the
maximum
possible
transfer
size.
The
example
in
figure
4
shows
that
the
read
code
and
the
byte
address are
sent
as
one
16
bit
transfer,
with
the
receive
queue
holding
up
to
29
bytes
of
received
EEPROM data.
When
writing
data
to
the
EEPROM,
the
following
sequence
is
transmitted:
-
Vpp
ON
command
($A6)
WRITE
DATA
command
(SA2)
Starting
byte
address
to
be
programmed
up
to
4
bytes
of
data
Vpp
OFF
command
CSA4)
Because
the
EEPROM
has
to
be
deselected
at various
points
during
the
sequence,
all
transfers
are
8
bit
only.
An
example
transfer
is
shown
in
figure
6.
<“OROLA
AN429/D
COMMAND
QUEUE
INITIALISATION
The
command
queue
is
configured
with
the
device
selection
state
during
and
between
transfers,
timing
information
and
bit
size information.
For
an
EEPROM
read
or
write
sequence
the
device
select
code
remains
constant throughout,
as
all
of
the transfers
are
intended
for
a
single
device.
This
device
select code,
which
is
determined from
the
parameter
<DEV>,
is
written
into
the
PCSO-3
field
of
all
of
the
COMD entries
used.
An
MCM2814
read
sequence
is
treated
as
one
command,
and
the
device
must
remain
selected
for
its
full
duration,
even
between
the
individual
transfers.
To
accomplish
this
the
CONT
bits
are
set
for
all
of
the
COMD
entries
except
the
one
which
controls
the
last
transfer.
Because
a
MCM2814
write
sequence
consists
of
three
command
blocks
lVpp
ON, WRITE and Vpp
OFF)
and
the
device
has
to
be
deselected
between
the
blocks,
the
CONT
bits
have
to
be
cleared
for
the
last
transfer
of
each
block.
This
can
be
seen in
the
example,
figure
6,
where
the
CONT
bits
are
clear in
the
COMD
entries
corresponding
to
the
Vpp
ON
command,
the
last
data
byte
and
the
Vpp
OFF
command.
As
all
EEPROM
writes
are
byte
size,
BITSE
is
clear
for
all
of
the
command
queue
entries.
This forces
the
OSPI
to
use
the
default
transfer
size,
which
is
8
bits.
For
the
EEPROM
read
operation
all
transfers
are
16
bit,
so
BITSE
is
set
for
all
of
the
COMD
entries.
This
causes
the
OSPI
to
use
the
transfer
size
programmed
into
the
BITS
field
of
register
SPCRO,
which
has
previously
been
set
to
16.
If
necessary,
the
BITS
field
can
be
used
to
select
alternative
transfer
sizes
from
8
to
16
bits.
To
conform
with
the
MCM2814
timing
spec.
a
delay
is
generated
after
each
transfer
by
setting bit
DT
in
the
com
-
mand
queue
entries,
causing
the
OSPI
to
use
the
5p~S
delay
specified
in
control
register
SPCR1.
No
extra delay
is
needed
between
selection
of
the
MCM2814
and
data
transfer,
so
the
DSCK
bits,
which
control
this
delay,
are
cleared
in
the
command
queue
en
-
tries.
MAIN
QSPI
CONTROL
REGISTERS
Before
the
OSPI
transfers
can
be
started,
the
main
configu
-
ration
register
SPCR2
is
configured.
This
register holds
the
first
and
last
OSPI
entry
numbers
that
are
to
be
sent
which
are
dependent
on
the
type
of
transfer
and
parameters,
eg.
the
number
of
bytes
to
read/write.
The
WRAP control
bits,
which
control
the
OSPI
wrapping
operation
in
which the
OSPI
constantly loops
around
a
group
of
queue
entries,
are
set
to
disable
this
function.
OSPI
transfers
are
started
by
setting
the
OSPI
enable
bit,
SPE,
of
SPCR1.
The
program
then
loops,
testing
for
comple
-
tion of
transfers
by
polling
the
SPI
finished
flag,
SPIF.
of
the
status
register
SPSR.
DEMONSTRATION
C
PROGRAM
-
EECALL
A
small
demonstration
C
program,
EECALL,
shows
the
way
that
a
C
program
can
utilise the
assembly
language
program
NVMRWC
as
well
as
demonstrating
its functions.
Several
functions
can
be
invoked
by
a
single keypress.
These
func
-
tions
are:
-
P
(Set
Parameters)
This
option allows
the
user
to
define
the
parameters
Start
Address,
No.
of Bytes and
Device
Code.
W
(Write
Data)
This option
makes
one
call
to
the
assem
-
bly
language
routine
<EE_WRITE>
using
the
parameters
which
have
been
set
previously.
The
user
is
prompted
to
enter
the
data
to
be
programmed,
byte
by
byte.
This
data
is
entered
as
single
ASCII
characters,
with
no
carriage
return
necessary.
R
(Read
Data)
One
call
is
made
to
the
assembly
language
routine
<EE_READ>
using
the
previously
set
parameters.
The
returned
data
is
printed
in
ASCII
format,
with
each
byte
separated
by
a
slash
(.1)
character.
D
(EE
PROM
Dump)
The
entire
contents
of
one
E E
PROM
(as
selected
by
the
previously
set
device
code)
are
printed
on
screen
in
an
ASCII
table
format.
This
option
calls
<EE_READ>
16
times,
with
each
call
reading
16
bytes
of
EEPROM.
T
(Text
Entry)
—When
this
option
is
selected,
the
user
can
enter
a
text
message
of
undefined
length
to
be
programmed
into
EEPROM.
To
terminate
the
message
a
hash
l#)
must
be
entered.
Programming
is
carried
out
character
by
character,
by
using
a
call
to
<EE_WRITE>
to
program each
byte
X
(Exit)
Exits
the
program
EECALL
by
executing
an RTS.
AN429~O
MOTOROLA .7
1*
*
EECALL.C
Basic front—end
program
to test
and
show use of
*
assember
calls
EE_READ
and
EE_WRITE
to read
and
write
data
*
on
MQ42814
LEPROM
connected
to OSPI.
*1
*include
<terminal.
h>
typedef
unsigned
char
byte;
byte
i,tbc,dev,addr,tadd,byte
count,byte_buffer(29];
mt
iovar;
char
c;
extern
byteee_write
(byte
d,byte
a,bytebcount,byte
*b_buffer);
extern
byte
ee_read
(byte
d,byte
a,byte
b_count,byte
*b
buffer);
void
pstring
(s)
char
*5;
while
(*s)
putchar(*s++);
main()
byte
error;
dev—14;
addrOxl
0;
byte_count’-4;
for
(i—0;i<4;i++)
byte_buffer~i]=i+40;
/*
Initialise
pass
parameters
*/
/*
initialize
I/O
device
pstring(”Enter
an
pstringQ’
pstring(”
pstring(”
pstring(”
pstring(”
\“X\”
to
terminate
the
program\n\r”);
\“WV’
to
Write
to
EEPROM
\n\r”);
\“RV’
to
Read
the
EEPROM\n\r”);
\“P\”
to
set
Parameters\n\r”);
\“D\”
to
Dump
entire
EEPROM\n\r”);
\“T\”
to
enter
Text
message\n\r”);
while
((c
toupper(getcharo))
‘X’)
if
(c
‘W’)
pstring
(“Write
Data\n\r”);
for (i—O;i<byte_count;
i++)
pstring
(“\n\rEnter
char
c—getchar0;
Jutchar
(c);
byte
buffer
[il—c;
“I;
pstring(”\n\rWriting
Data
to
E.EPR~.
-
error
ee_write(dev,addr,byte_count,byte
buffer);
error
error+l;
AN429/D
open
0;
*1
MOTOROLA
8
if
(c
‘T’)
printf
(“Program
text
from
address
%d.\n\r”,addr);
pstring
(“Enter
Text
-
to
terxuinate\n\r”);
tadd
addr;
tbc
=
1;
while
(Cc
getcharO)
!—
‘I’)
yutchar
(c);
byte_buffer[0]—c;
error
ee
write
(dev,tadd,tbc,byte_buffer);
++tadd;
if
(c
R’)
patring
(“Read
Data\n\r”);
ee
read(dev,addr,byte_count,byte
buffer);
for
(i—O;i<byte_count;i++)
putchar
(byte_buffer[i]);
putchar(
‘I’);
pstring
(“\n\r”);
if
(c
‘0’)
patring
(“Block
EEPROM
durnp\n\r”);
tbc
16;
tadd
=
0;
do
printf(”\n
%4d “,tadd);
ee_read(dev,tadd,tbc,byte_buffer);
for
(i—0;i<16;
i++)
if
(byte
buffer)>]
<
32
byte_buffer[i]
putchar
(byte_bufferfi]);
tadd
tadd+
16;
putchar(’
‘I;
Iwhile
(tadd>0);
pstring(”\n\r”);
if
Cc
‘P’)
pstring
(“Parameters”);
pstring(”\n\rEnter
no.
of bytes
0—29
:“);
do
scanf
(“%d”,
&iovar);
while
(
iovar
>
29
1;
byte_count
(byte)iovar;
pstring(”Enter
start
address
0—255
:“);
do scanf
(“%d”,
Liovar);
while
Ciovar
>
255);
addr
=
(byte)iovar;
printf
(“Bytes
%d
Address
%d.\n”,bytecount,addr);
pstring
(“\n\r”);
pstrinq(”\n\rX:eXit
W:Write
R:Read
P:Paranieters
D:Dump
T:Text\n\r”);
pstring
(“7”);
pstring(”EXIT
PROGRAl’1\n\r”);
AN429/D
MOTOROLA
9
(This
page
intentionally
left
blank)
AN4
29/I
MOTOROLA
10
*
MCM2814
EEPROM
Readand
Write
Subroutinesfor
the
MC68332
OSPI
*
Configured
as
a
‘C’
languageextermal
call
*
*
Copyright
Motorola
1990
*
Call
format:
F.E_READ
(0EV,
ADDR,
BYTE_COUNT,
*BYTE_BUFFER)
LIB
68332.REG
Include
MC68332
register
equates
section
.data
***********
****************************************
*
EEPROM
read
******
*********************************************
* ***
CREATE
LOCAL STACK
FRAME
AND
STORE
REGI STERS
ee read
LINK
A6,#&—28
Allocate
local
stack
area
of
28
bytes
*
and
use
A6
as
local
stack
pointer
MOVEM.L
DO/D1/D2/D3/AO/A1/A2,
(A7)
*
Store
registers
in
local
stack
frame
*
***
INITIALISEQSPI
BSR
OSPINIT
* ***
FETCH
PARAMETERS
FROM
LEA
(&52,A7),AO
MOVE.L
-(AO),Al
MOVE.L
-(AO),DO
MOVE.L
-(AOLDl
MOVE.L
-(AO),D2
Disable
QSPI and
initialise
I/O
STACK USING
AO
AS
POINTER
Point
to
element
above first
parameter
Put
BYTE_BUFFER
address
in
Al
Put
BYTE
COUNT
in DO
Put
ADOR
in
Dl
Put
DEV
in
D2
***
LOAD TXD
QUEUE
WITH
~Z2
184
COt’24ANDS
*
*
*
*
0:
Read byte
con~nand
1:
MC~428l4
byte
address
MOVE.B
•$A7,TXD
MOVE.B
Dl,’IXD+l
***
ENSURE
BYTE_COUNT
IS
ANDI.W
•$OOFF,DO
CMP.B
•$1E,DO
BCS
B_COKi
MOVE.B
•$1D,DO
B_COKi
TST
DO
BNE
B_COK2
MOVE.B
•S0l,DO
*
BYTE_COUNT
should
be
B_COK2
MOVE.W
00,01
store
READ
coriwnand
store
byteaddress
into
TXD
queue
(Dl
can
be
used
now)
IN
RANGE
1
TO
29
Clear
MSB
(word
will
be
used
in
DBcc)
Should
be
0
<
BYTE_COUNT
<
&30
BYTE_COUNT
<
~3O?
No.
so
force
to
&29
BYTE_COUNT
<>
0?
No,
so
force
to
1
O.K.
now
Working
copy
of
BYTE_COUNT
in
Dl
***
SET
UP
CCJMD
QUEUE
Use
0EV
code
to
calculate
ORI.B
#$EO,D2
MOVEA.
L
•COMD,
AD
CCMD
queue
entries
Calculate
entry
with
CONT bit set
16
bit
transfer
Use
AD
as
COMO
queue
pointer
No.
of
32
bit
transfers
Calculate value
in D2
for
ADD.B
ASR.B
SUB.B
*
Setup
COMDLOOP
~VE .B
DBF
*
Setup
ANDI
.B
MOVE.
B
((BYTE_COUNT+2)/2)
+
1
DBcc loop
to
set
up
COMO
queue
BYTE_COUNT
+2
(BYTE_COUNT+2)/2
(BYTE_~OUNT+2)/2—1
all
C~4D
entries
except
last
with
CONT
bitset
02,
(AO)+
Dl,
COMOLOOP
last
COMO
entry
with
CONT
clear
(deselect
EEPROM
at
end)
•S6F,D2
Calculate
entry
with
CONT
bit
clear
02,
(AD)
Install
in
COMO
queue
\N429/D
#$02,
Dl
#1,Dl
#$01,Dl
*
*
MOTOROLA
11
* ***
CALCULATE
LAST
QSPI
MOVE.B
DO,Dl
ADD.B
•$02,D1
ASR.B
~1,D1
MOVE.B D1,SPCR2
MOVE.B
#S0O,
SPCR2+1
*
~READ
DATA FROM
MC~42814
MOVE.W
•S8003,
SPCRl
*
~ WAIT FOR
END
OF
TRANSMISSION
WTLOOP
TST.B
SPSR
BPL
WTLOOP
ENTRY
NO.
AND
INCORPORATE
IN
SPCR2
Make
working
copy
of
BYTE_COUNT
BYTE_COUNT
+2
(BYTE_COUNT+2)
/2
Put
into
SPCR2
MSB
and
00
as
start
entry
in
LSB
Enable
0521,
DTL
delay
of
approx
5u5
Test
SPIF
bit
and
wait
till
set
* ***
PASS
DATA
BACK
TO C
PRCX3RAM
ARRAY
SUB.B
#SO1,DO
Use
BYTE_COUNT-i
as
loop
counter
MOVEA.L
#REC+3,AO
Use
AO
as
REC
queue
pointer
*
Use
MC68332
LOOP
MODE
PASSLOOP MOVE.B
(AO)+,(Al)+
DBF
DO,PASSLOOP
to
fill
array
Copy
one
data
entry
from
REC
queue
(loop
until
00<0
* ***
RESTORE
REGISTERS
AND
DE-ALLOCATE
STACK
MOVEM.L
(A7)
,DO/Dl/02/D3/AO/Al/A2
*
UNIX
RTS
*
ee
write
*
A6
Retrieve
registers
from
local
stack
frame
And
de—allocate
local
stack
********************************
*
******************
*
EEPROM
write
******
****
***************
************
**************
CREATE
LOCAL STACK FRAME
AND
STORE
REGISTERS
LINK
A6,~&-28
Allocate
local
stack
area
of
16
bytes
for
reg.
store,
using
A6
as stack
pointer
MOVEM.L
DO/D1/D2/D3/AO/Al/A2,
(A7)
Store
registers
in local
stack
frame
‘~‘~‘
INITIALISE QSPI
BSR
QSPINIT
***
FETCH PARAMETERS
FROM
LEA (52,A7),AO
MOVE.L
-(AO),Al
MOVE.L
-(AO),DO
MOVE.L
-(AO),Dl
MOVE.L
-(AO),D2
Stack
pointer
unchanged
Disable
and
initialise
OSPI
STACK USING
AO
AS
POINTER
Pointto
element
above
first
parameter
Put
BYTE_BUFFER
address
in
Al
Put
BYTE_COUNT
in
DO
Put
ADDR
in
Dl
Put
0EV
in
D2
LOAD
T~
QUEUE
WITH
14ZM2814
CO~t1ANDS
0:
Vpp
on
coiwnand
1:
Write
data
corrtnand
2:
reserved
for
byte
address
data
off
conunand
•$A6,
TXD+l
•$A2,
TXD+3
Dl,
TXD+5
3:
4:
Vpp
MOVE.
B
MOVE
B
MOVE.
B
Vpp
ON
conunand
WRITE
coirvriand
Use
ADDR
as
byte
address
(Dl
can
be
used
now)
*
~
Adjust
SUB.B
ANDI.W
MOVE
.W
Byte_Count
•soi,oo
•S03,DO
00,01
for
use
in
DBcc
loop
Need
BYTE_COUNT
loop
counter
in
range
0-3
for
use
in
DBcc
loop,
not
1-4
Working
copy
in
Dl
*
*
*
*
*
*
*
*
AN429/IJ
MOTOROLA
12
**
*
PROGRAM
COW)
AND TXD
Program
start
of
TXD
MOVEA.L
•COW),AO
MOVEA.L
#TXD+7,A2
ORI.B
•S20,02
MOVE.B
D2,
(AO)+
ORI.B •$AO,D2
MOVE.B
02,
(AO)+
MOVE.B
D2,(AO)+
QUEUES
and
COW)
queues
Use
AO
as
CCt’!D
queue
pointer
Use
A2
as
TXD
queue
pointer
Calculate
COW)
entrywith
CONT
bit
clear
Use
as
entry
for
Vpp
ON
(CONT
clear)
Calculate
COW)
entrywith
CONT
set
Use
as
entry
for
WRITE
DATA
and
ADDR,
(CONT
set)
*
PROGRAM
DATALOOP
MOVE.
B
ADDA.L
MOVE.
B
DBF
TXD
AND
CMD
QUEUES
(Al)+,
(A2)+
$01,
A2
02,
(AO)+
Dl,
DATALOOP
Put
a
byte
of write
data
in
TXD
queue
TXD
buffer
is
i’K)RD
wide,
so
increment
Put
an
entry
into
COW)
queue
(CONT
set)
Loop
until
finished
Finish
MOVE.
B
ANDI.B
MOVE.
B
MOVE
.B
off
COW)
and
•$A4,
(A2)
#$2F,D2
02,
(—l,AO)
D2,
(AO)
* ***
CALCULATE
WHAT
QUEUE
ADD.B
•$03,DO
MOVE.B
DO,
SPCR2
MOVE.B
•SOO,SPCR2+1
*
***
START
TRANSMISSION
AND
MOVE.W
•$8003,SPCR1
MOVE.L
#$00008000,Dl
LOOP DBF
Dl,
LOOP
TXD
queue
setup
Vpp
OFF
conunand
in
TXD
queue
Calculate
COW)
entry
with
CONT
clear
Change
last
data
COW)
entry
to
CONT
clear
Last
COW)
entry
(Vpp
OFF),
CONT
clear
ENTRIES
TO
SEND
FOR
PROGRAMMING
Last
data
entry
is
no.
2+BYTE_BUFFER
Put
into
SPCR2
MSB
and
00
as
start
entry
in
LSB
PROGRAMMING
DELAY
**
Start
progranuning
**
Progranuning
delay
(approx
2Oms)
* ***
CALCULATE
WHAT
QUEUE
ENTRIES
TO
SEND
FOR
Vpp OFF
ADD.B
•$0l,DO
Vpp
OFF
conunand
is
inunediately
after
*
MOVE.B
DO,SPCR2
MOVE.B
DO,SPCR2+l
progranuning
sequence
Put
into
SPI~R2
MSB
and
LSB
so
that
only
this
cormnand
is
sent
*
~
RESTORE
REGISTERS
AND
DE-ALLOCATE
STACK
MOVEM.L
(A7)
,DO/D1/D2/D3/AO/Al/A2
*
UNIX
RTS
Retrieve
registers
from
local
stack
frame
And
de—allocate
local
stack
AE
*
*
*
MOTOROLA
13
AN429/D
**
****
*
******
******
**
******************************
*
QSPINIT
*
Orderly
stop
and
initialise
QSPI
hardware
*****
**
**
*
*****
************************************
QSPINIT
ORI.B
•$80,SPCRO
ANDI.B
•$BF,SPCR2
ANDI.B
#$7F,SPSR
active
SPCRl
MISS
Ensure
QSPI
is
mester
Clear
WREN
(stop
wrapping)
Clear SPIF to
enable sensing
of
when
transmission
has
finished
Test SPE bit to see if
QSPI
enabled
Goto
MISS
if
disabled
*
Wait
till
QSPI
reached
ANDI.B
*$06,SPCR3
NOSPIF
TST.B
SPSR
BPL NOSPIF
Disable
QSPI
ANDI.B
•S7F,SPCR1
end
of
current
queue
Ensuresystem
not
HALTed
Wait
until
SPlFinished
Clear
SPE
bit
Initialise
QSPI for
accessing
M~42814
MOVE.W
•S8054,SPCRO
Set
MASTER,
no
WIRED
OR,
16
bits,
100KHZ
MOVE.W
•$7B7E,QPAR
Configure
MOSI,MISO+PCSO-3
as
QSPI
lines
MOVE.W
•$OOFA,QPDR
MOSI+PCSO
to
default
high
ANDI.B
•S7F,SPSR
Clear
SPIF
to
enable
sensing
of
when
next
transmission
has
finished
RTS
Allow
other
programs
(eg
C
program)
to
access
routine
labels
ee_write
and
ee_read
export
ee_write
export
ee
read
AN429/l
*
*
Is
QSPI
TST.B
BPL
*
*
MISS
*
*
MOTOROLA
14
(This
page
IntentIonally
left
blank)
AN429/D
MOTOROLA
15
Uterature
DistrIbution
Centers:
USA:
Motorola
Literature Distribution;
P.O.
Box
20912;
Phoenix,
Arizona
85036.
EUROPE.
Motorola
Ltd.;
European
Uterature
Centre;
88
Tanners
Drive,
Blakelands,
Milton
Keynes,
MK14
58P, England.
JAPAN:
Nippon
Motorola
Ltd.;
4-32-1,
Nishi-Gotanda,
Shinagawa-ku,
Tokyo
141,
Japan
ASIA
PACIFIC:
Motorola
Semiconductors
H.K.
Ltd.;
Silicon Harbour
Center,
No.
2
Dal
King
Street,
Tal
Pa
Industrial
Estate,
Tai
Po
N
T
Hong
Kong
U
MOTOROLA
Jut
PRtNTED
IN
THE USA
1993
lAPS
AN42~IO
I
IllJill
111111
III
11111
II
III
liii
Ill
liii
III
liii
All
products
are
sold
on
Motorola’s
Terms
&
Conditions
of
Supply.
In
ordering
a
product
covered
by
this
document
the
Customer
agrees to
be
bound
by
those
Terms
&
Conditions
and nothing
contained
in this
document
constitutes
or
farms
pan
of
a
contract
Iwith
the
exception
of
the
contents
of
this
Notice).
A
copy
of
Motorola’s Terms
&
Conditions
of
Supply
is
available
on
request.
Motorola
reserves
the
right
to
make
changes
without
further
notice
to
any
products
herein.
Motorola makes
no warranty,
representation or guarantee
regarding
the
suitability
of
its
products
for
any
particular
purpose,
nor
does
Motorola
assume
any
liability
arising
out
of
the
application
or
use
of
any
product
or
arcuit,
and
specificaily
disclaims
any
and
ail
liability,
including
without
limitation
consequential or
incidental
damages.
“Uyplcal”
parameters
can
and
do
vary
indifferent
applications.
All operating
parameters,
induding
“Typicals
must be
validated
for
each
customer
application by
customer’s technical
experts.
Motorola
does
not
convey
any
license
under
itS patent
rights
nor the
rights
of
others.
Motorola products
are
not
designed,
intended,
or authorized
for
use
as
components
in
systems
intended
for
surgical
implant into
the
body,
or
other
applications
intended to
suppert
or
sustain
life,
or
tar
any
other
application
in
which
the
failure
of
the
Motorola
product could create
a
situation
where
personal
injury
or
death
may
occur.
Should
Buyer
purchase
or
use
Motorola
products
for
any
such
unintendedorunauthorized
application.Buyer
shall
indemnity and
hold
Motorola
and
its
officers,
employees,
subsidiaries,
atfiliates
and
distributors
harmless
against
all
daims,
costs,
damages,
and
expenses,
and
reasonable
attorney
fees
arising out
of,
directly
or
indirectly,
any
claim
of
personal
injury
or
death
assoaated
with
such
unintended
or
unauthorized
use,
even
if
such
claim
alleges
that
Motorola
was
negligent regarding
the
design
or manufacture
of
the
part.
Motorola
and
(~
are
registered
trademarks
of
Motorola,
Inc.
Motorola,
Inc.
is
an
Equal
Opportunity/Affirmative
Action
Employer.
The
Customer
should
ensure
that
it
has
the
most up
to
date
version
of
the
document
by
contacting
its local
Motorola
office.
This
document
supersedes
any
earlier
documentation
relating
to
the
products
referred
to herein.
The
information
contained
in
this
document
is
current
at
the
date
of
publication.
It
may
subsequently
be
updated,
revised
or
withdrawn.