Application Note AN 38
Interfacing the X25650 to the
Motorola 68HC11 Microcontroller
by Applications Staff
The following code demonstrates how Xicor's high to serial data out (SO), and the PCS0/CS pin connected
density SPI serial EEPROMs could be interfaced to the to chip select (CS). Additional code can be found on the
68HC11 microcontroller when connected as shown in Xicor web site at http://www.xicor.com that will imple-
Figure 1. The interface uses the SPI port, with the SCK ment interfaces between Motorola microcontrollers and
pin connected to the serial clock (SCK), the MOSI pin other Xicor serial devices.
connected to serial data in (SI), the MISO pin connected
X25650
Figure 1. Interfacing an X25650 to the 68HC11 microcontroller using the SPI port.
October, 2000 www.xicor.com 1 of 5
Application Note AN 38
*******************************************************************************
** DESCRIPTION:
** The purpose of this program is to show the use of the M68HC11
** assembly language to program the XICOR SPI EEPROMs. The "WIP"
** status polling (ACKPOL program) is a unique feature of the SPI memories.
** The processor interfaces the EEPROM through its Serial Peripheral
** Interface Port (SPI). The SCK pin is connected to the serial clock (SCK),
** MOSI to serial data in(SI) , MISO to the serial data out (SO), and PCS0/CS
** to the CS input of the EEPROM. The main section of the code calls up other
** modules in order to demonstrate the procedure to be followed when
** reading/writing from/to the device.
*******************************************************************************
*******************************************************************************
* INTERNAL RAM LOCATIONS
ADDRL EQU $FF MEMORY ADDRESS LOW BYTE
ADDRH EQU ADDRL-1 MEMORY ADDRESS HIGH BYTE
PATTERN EQU ADDRH-1 PATTERN REGISTER
STACK EQU PATTERN-1 STACK TOP
* CONSTANTS
WREN_CMD EQU 006 WRITE ENABLE
WRITE_CMD EQU 002 WRITE DATA TO EEPROM
READ_CMD EQU 003 READ EEPROM DATA
WRDI_CMD EQU 006 WRITE DISABLE
RDSR_CMD EQU 005 READ STATUS REGISTER COMMAND
DUMMY EQU $FF DUMMY STATUS OF MOSI PIN DURING BYTE READ
SPE_BIT EQU $40
SPIF_BIT EQU $80 BIT POSITION OF THE SPIF
CE_BIT EQU $20 BIT POSITION FOR PCS0/CS
* EQUATES FOR USE WITH INDEX OFFSET = $1000
PORTD EQU $08
DDRD EQU $09
SPCR EQU $28
SPDR EQU $2A
SPSR EQU $29
BAUD EQU $2B
SCDAT EQU $2F
SCSR EQU $2E
SCCR2 EQU $2D
* ASSEMBLER REQUIREMENT- CPU TYPE
P68H11
PAGE
* START OF USER CODE
ORG $E000
TEST:
www.xicor.com 2 of 5
October, 2000
Application Note AN 38
lds #STACK * LOAD STACK POINTER
ldx #$1000 * SET REGISTER BASE
* INITIALIZE THE SPI
ldaa #$3F
staa DDRD,X * PORT-D PINS ALL SET AS OUTPUTS
ldaa #$50
staa SPCR,X * MODE = 0, CLK = 1MHZ
ldaa #$00
staa PATTERN * DATA PATTERN TO WRITE
ldy #$100
sty ADDRH * MEMORY ADDRESS TO WRITE
tab * RECALL THE DATA PATTERN
ldy ADDRH * LOAD THE MEMORY ADDRESS
jsr wr_byte * WRITE THE BYTE
jsr ACK_POLL * WAIT TILL DEVICE COMPLETS INTERNAL WRITE
jsr rd_byte * READ THE BYTE
jmp *
*******************************************************************************
*** Name: EE_WREN
*** Description: Enable write operation to the EEPROM
*** Function: This program sends out the command to enable the writes and
*** the store operations to the EEPROM
*** Calls: None
*** Input: None
*** Output: None
*** Register Usage: B
*******************************************************************************
EE_wren:
bclr PORTD,X,#CE_BIT * ACTIVATE CE
ldaa #WREN_CMD * WRITE ENABLE COMMAND
jsr outbyt * OUTPUT THE COMMAND
bset PORTD,X,#CE_BIT * DEACTIVATE CE
rts
*******************************************************************************
*** Name: OUTBYT
*** Description: Sends a byte to the EEPROM
*** Function: This program shifts out a byte, MSB first to the EEPROM.
*** Calls: None
*** Input: A = Byte to be sent
*** Return Value: None
*** Register Usage: None
*******************************************************************************
outbyt:
staa SPDR,X
outbyt1:
brclr SPSR,X,#SPIF_BIT,outbyt1 *WAIT FOR LAST ONE TO COMPLETE
rts
*******************************************************************************
*** Name: RD_BYTE
October, 2000 www.xicor.com 3 of 5
Application Note AN 38
*** Description: Reads content of the EEPROM at a specific location.
*** Function: This program sends out the command to read the content of a memory
*** location specified in the (E) register.
*** Calls: EE_read_cmd, outbyt
*** Input: Y = Address of the byte
*** Output: B = READ VALUE
*** Register Usage: B
*******************************************************************************
rd_byte:
bclr PORTD,X,#CE_BIT * ACTIVATE CE
jsr EE_read_cmd * ISSUE READ COMMAND
pshy * SAVE ADDR
tsy
ldaa 0,y * RECALL THE MSB OF ADDRESS
jsr outbyt * SEND IT TO EEPROM
ldaa 1,y * RECALL THE LSB OF ADDRESS
jsr outbyt * SEND IT TO EEPROM
ldaa #DUMMY * SHIFT IN THE DATA FROM EEPROM
jsr outbyt
ldaa SPDR,X * LOAD RECEIVED DATA FROM SPI
bset PORTD,X,#CE_BIT * DEACTIVATE CE
puly
rts
*******************************************************************************
*** Name: EE_READ_CMD
*** Description: Sends the read command to the EEPROM
*** Function: This program sends a read command to the EEPROM
*** Calls: outbyt
*** Input: E = BYTE ADDRESS
*** Return Value: A = RECEIVED BYTE
*** Register Usage: B, E, IZ
*******************************************************************************
EE_read_cmd:
ldaa #READ_CMD * SEND READ COMMAND TO THE EEPROM
jmp outbyt * SEND THE COMMAND
*******************************************************************************
*** Name: WR_BYTE
*** Description: Writes a byte to the EEPROM at a specific location.
*** Function: This program writes the byte in the (B) register to the EEPROM
*** location specified by the (E) register.
*** Calls: EE_wren, EE_write_cmd, outbyt
*** Input: Y = byte Address, B = Data to write
*** Output: None
*** Register Usage: A,B
*******************************************************************************
wr_byte:
jsr EE_wren * SEND WRITE ENABLE COMMAND
bclr PORTD,X,#CE_BIT * ACTIVATE CE
jsr EE_write_cmd * ISSUE WRITE COMMAND
pshy * SAVE ADDR
tsy
www.xicor.com 4 of 5
October, 2000
Application Note AN 38
ldaa 0,y * RECALL THE MSB OF ADDRESS
jsr outbyt * SEND IT TO EEPROM
ldaa 1,y * RECALL THE LSB OF ADDRESS
jsr outbyt * SEND IT TO EEPROM
tba
jsr outbyt * SEND IT TO EEPROM
bset PORTD,X,#CE_BIT * DEACTIVATE CE
puly * RECALL ADDR
rts
*******************************************************************************
*** Name: EE_write_cmd
*** Description: Sends the write command to the EEPROM
*** Function: This program creats the write command sequence and transmits
*** it to the EEPROM.
*** Calls: outbyt
*** Input: Y = BYTE ADDRESS
*** Return Value: None
*** Register Usage: A
*******************************************************************************
EE_write_cmd:
ldaa #WRITE_CMD * SEND WRITE COMMAND TO THE EEPROM
jmp outbyt
*******************************************************************************
*** Name: ACK_POLL
*** Description: Verifies if the EEPROM is ready and accepting commands
*** Function: This program sends the status register read command to the EEPROM
*** and returns to the caller when the WIP bit in the status byte is
** cleared or the maximum number of retries is reached.
*** Calls: outbyt
*** Input: None
*** Return Value: None
*** Register Usage: A,B
*******************************************************************************
ACK_POLL:
ackpol1:
bclr PORTD,X,#CE_BIT * ACTIVATE CE
ldaa #RDSR_CMD * READ STATUS COMMAND
jsr outbyt * SEND THE COMMAND
ldaa #DUMMY * DUMMY COMMAND
jsr outbyt * SEND THE COMMAND
bset PORTD,X,#CE_BIT * DEACTIVATE CE
ldaa SPDR,X * LOAD RECEIVED DATA FROM SPI
asra
bcc ackpol1
rts
ORG $FFFE
FDB TEST
END
October, 2000 www.xicor.com 5 of 5
This datasheet has been download from:
www.datasheetcatalog.com
Datasheets for electronics components.