Hello Ingo,
I can see some issues with you proposed code. The specific lines involved are shown below.
mnemonic wrote:
SPI2TX:
psha ;save A for the rest of the whole program
lda SPI2TXDATA ;data to send on SPI2
lsra ;shift two times right
lsra ;RW Bit and ADD Bit must be all zero
sta spi2txfirstbyte;save actions on first Byte
lda SPI2TXDATA ;restore the original data
nsa ;nibble swap command saves left shift operations
lsla ;but it must done two times
lsla
and #$C0 ;clear Bits 5-0
sta spi2txsecondbyte ;save actions on second byte to complete transmition
brclr 5,SPI2S,* ;wait for Transmitter empty flag
bset 3,PTBD ;set chip select
mov #spi2txfirstbyte,SPI2D ;send first byte
brclr 5,SPI2S,* ;wait for transmitter empty flag
mov #spi2txsecondbyte,SPI2D ;send second byte
jsr delay ;small delay to held chip select
bclr 3,PTBD ;clear chip select
pula ;restore A for the rest of the whole program
rts
The registers spi2txfirstbyte and spi2txsecondbyte are clearly RAM locations, since they are being written. The use of immediate addressing is thus not valid. You would be sending the address of the RAM locations, rather than their contents.
I would recommend that, following the send of each byte, that you wait until the SPRF flag becomes set (and not bother about the SPTEF flag). This will also avoid the need for the delay routine call, since both byte transmissions will be complete when the flag becomes set after each byte.
Why do you think that a small gap between the sending of each byte is a problem? This is normally not so since the clock signal originates from the MCU. Is there a minimum clock frequency actually specified for the device?
The following code is a possible alternative approach, that does not require any RAM registers for its operation.
; SEND DATA TO DEVICE
; On entry, X = byte value to be sent; CF = ADR bit state
;
CS EQU 3 ; PTBD bit for CS
SPTEF EQU 5 ; SPI2S bits
SPRF EQU 7
;
SPI2SEND: PSHA ; Save current value
LDA #$FF ; Unused bits of 2nd byte are 1's
RORX ; Shift in ADR bit state
RORA
LSRX ; R/W bit is zero
RORA
BSET CS,PTBD ; Set CS active
BRCLR SPTEF,SPI2S,* ; Wait until SPTEF flag is set
STX SPI2D ; Send first byte
BRCLR SPRF,SPI2S,* ; Wait until SPRF flag is set
STA SPI2D ; Send second byte
BRCLR SPRF,SPI2S,* ; Wait until SPRF flag is set
BCLR CS,PTBD ; Set CS inactive
PULA ; Restore previous value
RTS
;
;
Regards,
Mac