An131 – Cirrus Logic AN131 User Manual
Page 10
![background image](/manuals/466455/10/background.png)
AN131
10
AN131REV2
;*****************************************************************************
;* Routine - convert
;* Input - none
;* Output - conversion results in memory locations HIGHBYTE, MIDBYTE and
;*
LOWBYTE. This algorithm performs single conversions on
;*
Setup 1. See the CS5521/22/23/24/28 data sheet for multiple
;*
conversions or conversions on other channels.
;* This subroutine performs a Single conversion using Setup 1
;*****************************************************************************
convert
LDA
#$0B
;Command to read Configuration Register
STA
COMMAND
;Prepare COMMAND byte
JSR
read_register;Read Config. Register
LDA
HIGHBYTE
;Get High Byte in ACCA
AND
#$F8
;Mask MC, LP and RC bits to 0
STA
HIGHBYTE
;Put info back into High Byte location
LDA
#$03
;Command to write back to config Register
STA
COMMAND
;Prepare Command Byte
JSR
write_register;Write Configuration Register
;*** Receive Conversion Data ***
LDA
#$80
;Command to convert on Setup 1
JSR
send_spi
;Send Command to ADC
poll_sdo2:
BRSET
2,PORTD,poll_sdo2
;Wait for SDO to fall
LDA
#$00
;Load A with all 0’s
JSR
send_spi
;Send all 0’s to ADC
JSR
receive_spi
;Get high conversion byte
STA
HIGHBYTE
;Move info to High Byte location
JSR
receive_spi
;Get middle conversion byte
STA
MIDBYTE
;Move info to Middle Byte location
JSR
receive_spi
;Get low conversion byte
STA
LOWBYTE
;Move info to Low Byte location
RTS
;Return
;*****************************************************************************
;* Routine - write_register
;* Input - COMMAND, HIGHBYTE, MIDBYTE, LOWBYTE
;* Output - none
;* This subroutine is used to write information to the internal registers of
;* the CS5521/22/23/24/28
;*****************************************************************************
write_register
LDA
COMMAND
;Load ACCA with COMMAND
JSR
send_spi
;Transfer command byte
LDA
HIGHBYTE
;Load ACCA with HIGHBYTE
JSR
send_spi
;Transfer high byte
LDA
MIDBYTE
;Load ACCA with MIDBYTE
JSR
send_spi
;Transfer middle byte
LDA
LOWBYTE
;Load ACCA with LOWBYTE