beautypg.com

An131 – Cirrus Logic AN131 User Manual

Page 11

background image

AN131

AN131REV2

11

JSR

send_spi

;Transfer low byte

RTS

;Return

;*****************************************************************************
;* Routine - read_register
;* Input - COMMAND
;* Output - HIGHBYTE, MIDBYTE, LOWBYTE
;* This subroutine is used to read from the internal registers of the
;* CS5521/22/23/24/28
;*****************************************************************************

read_register

LDA

COMMAND

;Load ACCA with COMMAND

JSR

send_spi

;Send command byte

JSR

receive_spi

;Receive a byte

STA

HIGHBYTE

;Store value in HIGHBYTE

JSR

receive_spi

;Receive a byte

STA

MIDBYTE

;Store value in MIDBYTE

JSR

receive_spi

;Receive a byte

STA

LOWBYTE

;Store value in LOWBYTE

RTS

;Return

;*****************************************************************************
;* Routine - send_spi
;* Input - Byte to be send is placed in ACCA
;* Output - none
;* This subroutine sends a byte to the ADC using the SPI port.
;*****************************************************************************

send_spi

STA

SPDR

;Move ACCA to the SPI Data Register

wait0:

BRCLR

SPIF,SPSR,wait0

;Loop until byte has been transmitted

RTS

;Return

;*****************************************************************************
;* Routine - receive_spi
;* Input - none
;* Output - Received byte is placed in ACCA
;* This subroutine receives a byte from the ADC using the SPI port
;*****************************************************************************

receive_spi

CLRA

;Load ACCA Register with all Zeros

STA

SPDR

;Transfer 8 0’s to clock next byte

wait1:

BRCLR

SPIF,SPSR,wait1

;Reset SPIF bit

LDA

SPDR

;Get received information

RTS

;Return

;*****************************************************************************