An89 – Cirrus Logic AN89 User Manual
Page 9

AN89
AN89Rev2
9
**************************************************************************************
* Routine - read_register
* Input
- COMMANDBYTE
* Output - HIGHBYTE, MIDBYTE, LOWBYTE
*
* This subroutine reads an internal register of the ADC.
**************************************************************************************
read_register LDA
COMMANDBYTE ; Load ACCA with COMMANDBYTE
JSR
send_spi
; transfer byte
JSR
receive_spi
; receive byte
STA HIGHBYTE
; Move ACCA with HIGHBYTE
JSR
receive_spi
; receive byte
STA MIDBYTE
; Move ACCA with MIDBYTE
JSR
receive_spi
; receive byte
STA LOWBYTE
; Move ACCA with LOWBYTE
RTS
; Exit Subroutine
**************************************************************************************
* Routine - send_spi
* Input
- Byte to be transmitted is placed in ACCA
* Output - none
*
* This subroutine sends a byte to the ADC.
**************************************************************************************
send_spi:
STA SPDR
; Move ACCA to SPDR
wait0
BRCLR SPIF,SPSR,wait0
; Loop until byte is transmitted
RTS
; Exit Subroutine
**************************************************************************************
* Routine - receive_spi
* Input
- none
* Output - Byte received is placed in ACCA
* This subroutine receives a byte from the ADC.
**************************************************************************************
receive_spi:
CLRA
; Load ACCA register with Zero
STA SPDR
; Initiate a transfer of all Zero’s
wait1
BRCLR SPIF,SPSR,wait1
; Reset Flag SPIF bit
LDA SPDR
; Move SPDR to ACCA
RTS
; Exit Subroutine