Professional Documents
Culture Documents
AN429
INTRODUCTION
Freescale Semiconductor, Inc...
HARDWARE CONFIGURATION
This application note describes the software and hardware Figure 1 shows a simple system with four MCM2814
necessary to use the MCM2814 serial EEPROM with the EEPROMs connected directly to the MG68332 OSPI. The
MC68332 Queued Serial Peripheral Interface, or OSPI. MCM2814 is a serially accessed 256 byte FEPROM, which
can be used in either IC or SPI protocol systems. In this
As wellas giving specific details on accessing the MCM281 4 application SPI mode is selected by pulling the MCM281 4
EEPROM with the OSPI. this application note can also be MODE pin to the ..-5V supply level, Vdd. As the MCM2814
used to provide general information on configuring and using generates its programming voltage (Vpp) internally, only a
the OSPI with SPI compatible devices. single 5V supply is necessary.
The main areas covered are hardware configuration, the In the simplest configuration, selection of the individual
general operation of the OSPI and a description of software EEPROMs is accomplished by connecting the OSPI slave
which allows programming and reading data from the select lines, PCSO-3, directly to the MCM2814 SPI slave
MGM2814. Information on interfacing the software with select lines, SPISS. With this configuration a maximum of
high level ‘C’ language programs is also covered, with a short four EEPROMs or other SPI devices can be individually
demonstration program included. selected.
P053
P052
PcS1
PcSo —
The SPI bus consists of two serial data lines, a clock line and as on the SPI, the OSPI can be configured to automatically
one or more slave select lines. The two data lines, MOSI and carry out a number of transfers without intervention from the
MISO, are used by the master device on the bus to transmit processor. Each transfer can be individually configured to
and receive data respectively. The clock and slave select access a specific device by using the PCSO-3 lines. Individual
lines, designated SCK and P050-3 on the OSPI. are gener- control of the number of bits per transfer, bus timing delays
ated by the master, which in this case is the OSPI. and the state of the PCS lines between transfers is also
possible.
When the SPI master accesses a particular SPI device, the
slave select linefor thatparticular device is driven low before The transfer data and control information is contained in
the required number of bits are transferred during SCK three queues:- the receive data queue RECRAM, the trans-
transitions. mit data queue TRANRAM and the command data queue
COMD.RAM. The transmit and receive queues are 16 bits
The SPI protocol defines that data transmission and recep- wide, although each SPI transfer can be from 8 to 16 bits
;,on always occur simultaneously, as while data is transmit- long, defined by BITS of register SPCRO and BITSE of the
ed from the master on the MOSI line, data is being received command entries. The command data queue is byte wide,
~iongthe MISO line. If the master only has to read data from with each byte configuring various aspects of one transfer,
Freescale Semiconductor, Inc...
levice, it may transmit uninitialised or ‘don’t care’ values such as the number of bits in the transfer, bus delays and
:i’ng MOSI, and conversely if the master only has to write device selection. Figure 2 shows the bit usage of the
~ta to a device it may ignore the data received along MISO. command bytes.
3 enhancements of the OSPI over the SPI consist mainly All three queues are 16 entries deep, resulting in 32 bytes
the queued architecture of the OSPI. Rather than having each for the transmit and receive data queues and 16 bytes
program each individual transfer before it is transmitted, for the command queue bits.
P053-0 Defines the state of the slave select lines PCS3-0 during transfer
The MC68332 assembly language software, NVMRWC, The write routine starts at <ee_write>, and is able to write
contains routines to both read and write EEPROM data via up to 4 bytes of data starting at any location, as long as all of
the OSPI, and is configured to be called as a function from the bytes are within a 4 byte boundary. This limitation is due
a C language program. to the operation of the MCM2814, which is detailed in the
data sheet for the device. Program flow for the write action
The read routine is entered at <ee_read>, and is used to read and an example transfer are shown in figures 5 and 6.
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.
xx xx Entry 2
xx xx Entry 3
Wait until QSPI has finished any
pending transfers before initializing
<OSPINIT>
-L .1
I—— 15
Receive Data Queue REC.RAM
2~X 87 XX 0
Entry 0
Initialize transmit data queue, command
queue and main QSPI control registers ~I~QA~1a Entry 1
using parameters from C’ call Entry 2
~xI~$2~dat~ ~a~1a Entry 3
K
U—” Command Queue CMD.RAM
CONT/BITSE/DT/DSCK PCS3-0
7 6 5 4 3210
Has OSPI finished transfers? 1 1 1 0 0010 Entry 0
1 1 1 0 0010 Entry 1
1 1 1 0 0010 Entry 2
0 1 1 0 0010 Entry 3
)
Freescale Semiconductor, Inc.
Get passed parameters from ‘0’ call Receive Data Queue REC.RAM
15 87 0
XX XX Entry 0
:uitialize transmit data queue, command XX XX Entry 1
queue and main OSPI control registers XX XX Entry 2
using parameters from ‘C’ call Xx XX Entry 3
XX XX Entry 4
XX XX Entry 5
Start transfers by enabling OSPI
CONT/BITSE/DT/DSCK PCS3-0
7 65 4 3210
Has programming delay 0 0 1 0 0001 Entry 0
elapsed? NO 1 0 1 0 0001 Entry 1
1 0 1 0 0001 Entry 2
1 0 1 0 0001 Entry 3
YES 0 0 1 0 0001 Entry 4
0 0 1 0 0001 Entry 5
Initialise SPCR2 to send L 4
Vpp OFF command
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.
The routines <ee_read> and <ee_write> return with all listed registers as long words starting at the address pointed
processor registers restored to their origimal state. To ac- to by the stack pointer A7. As the LINK instruction sets A7
complish this, the registers are written to the stack on entry, to point to the lowest address of the reserved 28 bytes, all
and recovered before returning. The instruction, LINK of the registers are stored in this area. Figure 7 shows the
A6,#&-28, creates a 28 byte stack frame for this purpose by stack organisation in detail.
moving the stack pointer. A7, past the reserved area, and
loading A6 to act as the frame pointer. The MOVEM instruction is used again at the end of the
program, with the order of the operands reversed, to recover
Storing the processor registers is accomplished in a single the register values, and the reserved stack area is deallo-
instruction by the MOVEM (move multiple) command. cated by the UNLK (unlink) instruction. This recovers the
MOVEM.L DO/D1/D2/D3/AO/A1/A2,(A71 stores all of the original value of the specified local stack pointer, A6, and
resets the main stack pointer, A7, to its previous value.
Freescale Semiconductor, Inc...
Un-used stack
I
(Stack pointer A7 ‘C’ return address
before LINK) Parameter ‘DEV’
Parameter ‘ADDR’ Stack condition
Parameter ‘BYTE COUNT’ on entry
Address of array ‘BYTE BUFFER
br
Before the OSPI is used for an EEPROM read or write, it is high. The OSPI is also set to non wired-or outputs and SPI
initialised to the desired startup state. The subroutine master with a clock rate of 100KHz at this point.
<OSPIN IT> allows the OSPI to complete any pending trans-
fers before it is stopped and initialised. At this stage initiali- Note that if it is known the OSPI will be idle and in a suitable
sation consists mainly of configuring the OSPI hardware by state when an EEPROM read or write is requested, or if it is
assigning the lines MISO,MOSI,SCK and PCSO-3 to the acceptable to halt the OSPI with transfers pending, the
OSPI. with MOSI and PCSO-3 set as outputs which default initialisation subroutine could be simplified,
.A.’hen either reading or writing EEPROM data, the software Note that Al is the memory address of the main C array,
~sto retrieve the parameters that the C program has placed rather than the actual data. This allows NVMRWC to read or
.~ the stack. NVMRWC is configured to work with a C modify the data in the array when necessary by using Al as
2ompiler that passes the variables in the stack locations a pointer. An example of this is when the EEPROM data is
‘wn in figure 7. If the C compiler passes the variables in passed back to the array after a read in the routine <PAS-
Freescale Semiconductor, Inc...
fferent manner, the program must be altered accord- SLOOP>. This program section uses a MOVE instruction to
v. The parameters are initially stored in the MC68332 copy a byte of data from the OSPI receive data queue to the
mal registers as follows:- array, and a decrement if false, or DBF instruction to cause
the program to loop around until a count register reaches 0.
I — Address in MC68332 memory of the C data As the MOVE instruction occupies one word, the MC68332
array, <BYTE_BUFFER> automatically enters ‘Loop Mode’ when this program sec-
tion is encountered. When in this mode, no instruction
0 — Number of bytes to transfer, <BYTE_COUNT> fetches are made to memory, thus greatly speeding execu-
tion.
— MCM2814 starting byte address, <ADDR>
The transmit dataqueue has to be initialised with the correct with the receive queue holding up to 29 bytes of received
sequence of MCM2814 commands and data before an EEPROM data.
EE PROM read or writecan be carried out. Reading data from When writing data to the EEPROM, the following sequence
the E EPROM uses the simplest sequence, consisting of the
following> is transmitted:-
MCM2814 READ command 1SA7) Vpp ON command ($A6)
Starting byte address to be read WRITE DATA command (SA2)
Starting byte address to be programmed
The remainder of the transmit queue does not need to be
initialised, as after this sequence has been sent the up to 4 bytes of data
MCM28l 4 transmits data, and no longer monitors incoming Vpp OFF command CSA4)
data. Because the MCM281 4 remains selected between all
of the individual byte transfers, the full 16 bit width of the Because the EEPROM has to be deselected at various
data queues can be used to increase the maximum possible points during the sequence, all transfers are 8 bit only. An
transfer size. The example in figure 4 shows that the read example transfer is shown in figure 6.
code and the byte address are sent as one 16 bit transfer,
AN429/D
<“OROLA For More Information On This Product,
Go to: www.freescale.com
Freescale Semiconductor, Inc.
The command queue is configured with the device selection are clear in the COMD entries corresponding to the Vpp ON
state during and between transfers, timing information and command, the last data byte and the Vpp OFF command.
bit size information.
As all EEPROM writes are byte size, BITSE is clear for all of
For an EEPROM read or write sequence the device select the command queue entries. This forces the OSPI to use the
code remains constant throughout, as all of the transfers are default transfer size, which is 8 bits. For the EEPROM read
intended for a single device. This device select code, which operation all transfers are 16 bit, so BITSE is set for all of the
is determined from the parameter <DEV>, is written into the COMD entries. This causes the OSPI to use the transfer size
PCSO-3 field of all of the COMD entries used. programmed into the BITS field of register SPCRO, which
has previously been set to 16. If necessary, the BITS field can
An MCM2814 read sequence is treated as one command, be used to selectalternative transfer sizes from 8 to 16 bits.
and the device must remain selected for its full duration,
even between the individual transfers. To accomplish this To conform with the MCM2814 timing spec. a delay is
the CONT bits are set for all of the COMD entries except the generated after each transfer by setting bit DT in the com-
one which controls the last transfer. mand queue entries, causing the OSPI to use the 5p~S delay
specified in control register SPCR1.
Freescale Semiconductor, Inc...
Before the OSPI transfers can be started, the main configu- OSPI constantly loops around a group of queue entries, are
ration register SPCR2 is configured. This register holds the set to disable this function.
first and last OSPI entry numbers that are to be sent which
are dependent on the type of transfer and parameters, eg. OSPI transfers are started by setting the OSPI enable bit,
the number of bytes to read/write. The WRAP control bits, SPE, of SPCR1. The program then loops, testing for comple-
which control the OSPI wrapping operation in which the tion of transfers by polling the SPI finished flag, SPIF. of the
status register SPSR.
A small demonstration C program, EECALL, shows the way R (Read Data) One call is made to the assembly language
— —
that a C program can utilise the assembly language program routine <EE_READ> using the previously set parameters.
NVMRWC as well as demonstrating its functions. Several The returned data is printed in ASCII format, with each byte
functions can be invoked by a single keypress. These func- separated by a slash (.1) character.
tions are:-
D (EE PROM Dump) The entire contents ofone EE PROM
— —
bly language routine <EE_WRITE> using the parameters T (Text Entry) —When this option is selected, the user can
—
which have been set previously. The user is prompted to enter a text message of undefined length to be programmed
enter the data to be programmed, byte by byte. This data is into EEPROM. To terminate the message a hash l#) must be
entered as single ASCII characters, with no carriage return entered. Programming is carried out character by character,
necessary. by using a call to <EE_WRITE> to program each byte
void
pstring (s)
char *5;
Freescale Semiconductor, Inc...
while (*s)
putchar(*s++);
main()
byte error;
if (c — ‘W’)
yutchar (c);
byte_buffer[0]—c;
error — ee write (dev,tadd,tbc,byte_buffer);
++tadd;
if (c — R’)
putchar (byte_buffer[i]);
Freescale Semiconductor, Inc...
putchar( ‘I’);
pstring (“\n\r”);
if (c — ‘0’)
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”);
pstring(”EXIT PROGRAl’1\n\r”);
AN429/D MOTOROLA
For More Information On This Product, 9
Go to: www.freescale.com
Freescale Semiconductor, Inc.
section .data
*********** ****************************************
* EEPROM read
****** *********************************************
\N429/D MOTOROLA
For More Information On This Product, 11
Go to: www.freescale.com
Freescale Semiconductor, Inc.
* *** CALCULATE LAST QSPI ENTRY NO. AND INCORPORATE IN SPCR2
MOVE.B DO,Dl Make working copy of BYTE_COUNT
ADD.B •$02,D1 BYTE_COUNT +2
ASR.B ~1,D1 (BYTE_COUNT+2) /2
MOVE.B D1,SPCR2 Put into SPCR2 MSB
MOVE.B #S0O, SPCR2+1 and 00 as start entry in LSB
* EEPROM write
****** **** *************** ************ **************
AN429/D MOTOROLA
For More Information On This Product, 13
Go to: www.freescale.com
Freescale Semiconductor, Inc.
** **** * *** *** ****** ** ******************************
* QSPINIT
* Orderly stop and initialise QSPI hardware
***** * * ** * ***** ****** ******************************
* Is QSPI active
TST.B SPCRl Test SPE bit to see if QSPI enabled
BPL MISS Goto MISS if disabled
* Disable QSPI
ANDI.B •S7F,SPCR1 Clear SPE bit
Freescale Semiconductor, Inc...
export ee_write
export ee read
AN429/D MOTOROLA
For More Information On This Product, 15
Go to: www.freescale.com
Freescale Semiconductor, Inc.
E-mail:
support@freescale.com
Japan:
Freescale Semiconductor Japan Ltd.
Headquarters
ARCO Tower 15F Information in this document is provided solely to enable system and software
1-8-1, Shimo-Meguro, Meguro-ku, implementers to use Freescale Semiconductor products. There are no express or
implied copyright licenses granted hereunder to design or fabricate any integrated
Tokyo 153-0064 circuits or integrated circuits based on the information in this document.
Japan Freescale Semiconductor reserves the right to make changes without further notice to
0120 191014 or +81 3 5437 9125 any products herein. Freescale Semiconductor makes no warranty, representation or
support.japan@freescale.com guarantee regarding the suitability of its products for any particular purpose, nor does
Freescale Semiconductor assume any liability arising out of the application or use of
Asia/Pacific: any product or circuit, and specifically disclaims any and all liability, including without
Freescale Semiconductor Hong Kong Ltd. limitation consequential or incidental damages. “Typical” parameters which may be
provided in Freescale Semiconductor data sheets and/or specifications can and do
Technical Information Center vary in different applications and actual performance may vary over time. All operating
2 Dai King Street parameters, including “Typicals” must be validated for each customer application by
All products
Tai Po sold on Motorola’s
areIndustrial Estate Terms & Conditions of Supply. Inordering a customer’s
product covered by this document the Customer agrees to be bound by those
technical experts. Freescale Semiconductor does not convey any license
Terms & Conditions and nothing
Tai Po, N.T., Hong Kong contained in this document constitutes or farms pan ofa contract Iwith the exception of the contents of this Notice). A copy
under its patent rights nor the rights of others. Freescale Semiconductor products are
of Motorola’s Terms & Conditionsof Supply isavailable on request. not designed, intended, or authorized for use as components in systems intended for
+800 2666 8080
support.asia@freescale.com surgical implant into the body, or other applications intended to support or sustain life,
or for any other application in which the failure of the Freescale Semiconductor product
Motorola reserves the right to make changes without further notice toany products herein. Motorola makes no warranty, representation or guarantee regarding
could create a situation where personal injury or death may occur. Should Buyer
For Literature
the suitability Requests
of its products Only: purpose, nor does Motorola assume
for any particular any liability
purchase or usearising out of the application
Freescale or use of
forany
anyproduct or arcuit,
and specificaily
Freescale disclaims any and ail liability,
Semiconductor includingwithout
Literature Distributionlimitation
Centerconsequential or incidental damages.Semiconductor products
“Uyplcal” parameterscan and such unintended
dovary indifferent or
unauthorized application, Buyer shall indemnify and hold Freescale Semiconductor
applications.
P.O. Box All operating
5405 parameters, induding “Typicals must be validated for each customer application by customer’s technical experts. Motorola does
and its officers, employees, subsidiaries, affiliates, and distributors harmless against all
not convey
Denver,any license under80217
Colorado itS patent rights nor the rights of others. Motorola products are not designed, intended, or authorized for use as components in
claims, costs, damages, and expenses, and reasonable attorney fees arising out of,
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
directly or indirectly, any claim of personal injury or death associated with such
1-800-441-2447
the Motorola product couldorcreate
303-675-2140
a situation where personal injury or death may occur. orShould Buyer purchase
unintended unauthorized evenorif use
suchMotorola products
that for any such
Fax: 303-675-2150
unintendedorunauthorized application.Buyer shall indemnity and hold Motorola and its officers, employees,use,subsidiaries, claim alleges
atfiliates Freescale
and distributors harmless
Semiconductor was negligent regarding the design or manufacture of the part.
against all
daims, costs, damages, and expenses, and reasonable attorney fees arising out of, directly or indirectly, any claim of personal injury or death
LDCForFreescaleSemiconductor@hibbertgroup.com
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.
U MOTOROLA
Jut PRtNTED IN THE USA 1993 lAPS AN42~IO
For More Information On This Product,
Go to: www.freescale.com I IllJill 111111 III11111IIIIIliii IllliiiIIIliii