📄 spi.asm
字号:
st7/ ; The first line is reserved
; for specifying the instruction set
; of the targetted processor
;+------------------------------------------------------------------------------+
;| |
;| SPI COMMUNICATION BETWEEN ST7 AND EEPROM |
;| |
;| Copyright (c), STMicroelectronics |
;| |
;+------------------------------------------------------------------------------+
;| The present source code which is for guidance only aims at providing |
;| customers with information regarding their products in order for them to save|
;| time. As a result, STMicroelectronics shall not be held liable for any direct|
;| indirect or consequential damages with respect to any claims arising from the|
;| content of such a source code and/or the use made by customers of the |
;| information contained herein in connexion with their products. |
;+------------------------------------------------------------------------------+
;| |
;| File: spi.asm |
;| |
;+----------------------+-----------------------+-------------------------------+
;| DATE | VERSION | HISTORY/CHANGES |
;| (MM/DD/YY) | VX.Y | |
;+----------------------+-----------------------+-------------------------------+
;| 11/12/01 | 2.0 | ST72251 ----> ST72264 |
;+----------------------+-----------------------+-------------------------------+
;|SOFTWARE DESCRIPTION: |
;| ST7 SPI software driver for a communication between an ST7 and an ST95040 |
;| EEPROM. |
;| Polling software strategy without error management. |
;| |
;|PIN ALLOCATION: |
;| PB3: slave (EEPROM) selection |
;| All SPI pins: MISO, MOSI, CLK (/SS software driven) |
;+------------------------------------------------------------------------------+
TITLE "spi.ASM"
; This title will appear on each
; page of the listing file
MOTOROLA ; This directive forces the Motorola
; format for the assembly (default)
;+------------------------------------------------------------------------------+
;| FILES INCLUSION |
;+------------------------------------------------------------------------------+
#INCLUDE "st72264.inc" ; Include st72264 registers and
; Memory mapping file
#INCLUDE "constant.inc" ; Include general constants file
;+------------------------------------------------------------------------------+
;| DEFINES INCLUSION |
;+------------------------------------------------------------------------------+
#DEFINE DEV_P 3 ; Select the device's pin
;+------------------------------------------------------------------------------+
;| MAIN SECTION |
;+------------------------------------------------------------------------------+
WORDS ; Define subsequent addresses as words
segment 'rom'
.main
call ST7_init
call SPI_init
call write_enable ; Writing in the memory register enabled
ld X,#$F0 ; No protected block in memory
call write_SR
again1 call read_SR
btjt SPIDR,#0,again1 ; Waiting loop until WIP flag goes low,
; second step to clear SPIF
ld A,#$0 ; A = EEPROM memory address (0)
clr X ; Clear X.
.write_loop
call write_enable
call byte_write_l ; Write sequence
again call read_SR ; Waiting loop until WIP flag goes low,
btjt SPIDR,#0,again ; second step to clear SPIF
add A,#$10 ; Data written 16 bytes by 16 bytes
cp A,#$70 ; 112 bytes written?
jrult write_loop
clr X ; Clear X
.read_loop
ld A,#$0 ; A = EEPROM memory address (0)
call byte_read_l ; Read EEPROM from the address 0
loop
jra loop ; Endless loop
;+------------------------------------------------------------------------------+
;| SUB-ROUTINES SECTION |
;+------------------------------------------------------------------------------+
;********************************************************************************
;+------------------------------------------------------------------------------+
;| |
;| ST7 INITIALISATION |
;| |
;+------------------------------------------------------------------------------+
;|ROUTINE DESCRIPTION: |
;| This routine initialises the used pins of the ST7 |
;| |
;|INPUT PARAMETERS: |
;| None |
;| |
;|INTERNAL PARAMETERS: |
;| None |
;| |
;|OUTPUT PARAMETERS: |
;| None |
;+------------------------------------------------------------------------------+
.ST7_init
bset PBDDR,#3 ; PB3 output push pull
bset PBOR,#3
ret
;********************************************************************************
;********************************************************************************
;+------------------------------------------------------------------------------+
;| |
;| SPI INITIALISATION |
;| |
;+------------------------------------------------------------------------------+
;|ROUTINE DESCRIPTION: |
;| This routine initialises the SPI peripheral |
;| |
;|INPUT PARAMETERS: |
;| None |
;| |
;|INTERNAL PARAMETERS: |
;| A (accumulator) |
;| |
;|OUTPUT PARAMETERS: |
;| None |
;+------------------------------------------------------------------------------+
.SPI_init
bset SPICSR,#1 ; first configure SPICSR, then SPICR
bset SPICSR,#0 ; /SS pin to 1 : master configuration
ld A,#$5C ; SPI= interrupt disable, output enable,
; ST7=Master
ld SPICR,A ; Polarity=1 and Phase=1,
; clock = Core clock/8
ret
;********************************************************************************
;********************************************************************************
;+------------------------------------------------------------------------------+
;| |
;| WRITE ENABLE ROUTINE |
;| |
;+------------------------------------------------------------------------------+
;|ROUTINE DESCRIPTION: |
;| This routine enables the write access to the EEPROM |
;| |
;|INPUT PARAMETERS: |
;| Device pin (here 3 for PB3) |
;| |
;|INTERNAL PARAMETERS: |
;| A (accumulator) |
;| |
;|OUTPUT PARAMETERS: |
;| None |
;+------------------------------------------------------------------------------+
.write_enable
bres PBDR,#DEV_P ; Tie to low E2PROM S pin
; Send write enable instruction
ld Y,#$06
ld SPIDR,Y ; Value sent when put into the SPIDR
wait3 btjf SPICSR,#7,wait3 ; Wait for SPIF bit to go up (data sent)
ld Y,SPIDR ; Second step to clear the SPIF bit
; Deselect device
bset PBDR,#DEV_P ; Low to high transition on the S pin for
; the latch
ret
;********************************************************************************
;********************************************************************************
;+------------------------------------------------------------------------------+
;| |
;| WRITE ROUTINE |
;| |
;+------------------------------------------------------------------------------+
;|ROUTINE DESCRIPTION: |
;| This routine enables to write data value at memory address in lower page |
;| |
;|INPUT PARAMETERS: |
;| Device pin (here 3 for PB3), memory address, data value |
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -