An88 – Cirrus Logic AN88 User Manual
Page 9

AN88
AN88Rev2
9
;*************************************************************************************
;* Routine - calibrate
;* Input - none
;* Output - none
;* This subroutine instructs the CS5525/6/9 to perform self-offset calibration.
;*************************************************************************************
calibrate
MOVLW
0x84
; set command byte for config write
MOVWF
COMMANDBYTE ; set COMMAND BYTE
CLRF
HIGHBYTE
; clear HIGHBYTE
CLRF
MIDBYTE
; clear MIDBYTE
MOVLW
0x01
; get ready for self offset cal
MOVWF
LOWBYTE
; set LOWBYTE
CALL
write_register
; Write to Config Register
MOVLW
0x94
; set command byte for config read
MOVWF
COMMANDBYTE
; set COMMAND BYTE
poll_done: CALL
read_register
; Poll done flag until cal complete
BTFSS
LOWBYTE,3
; repeat if flag not set
goto
poll_done
RETURN
; Exit subroutine
;*************************************************************************************
;* Routine - convert
;* Input - none
;* Output - Conversion results in memory locations HIGHBYTE, MIDBYTE and
;*
LOWBYTE. This algorithm performs only single conversions. If
;* continuous conversions are needed the routine needs to be
;* modified. Port flag is zero.
;*
HIGHBYTE MIDBYTE LOWBYTE
;*
7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0
;* 16-bit results MSB
LSB 1 1 1 1 0 0 OD OF
;* 20-bit results MSB
LSB 0 0 OD OF
;* This subroutine initiates a single conversion.
;*************************************************************************************
convert
MOVLW
0xC0
; Set COMMANDBYTE for single CONV
MOVWF
COMMANDBYTE
BCF
PORTA,CS
; Clear Chip Select
CALL
send_spi
; Transmit command out SPI
MOVLW
0x94
; Set command byte for config read
MOVWF
COMMANDBYTE ; Send COMMAND BYTE
done1 CALL
read_register
; Poll done flag until CONV complete
BTFSS
LOWBYTE,3
; Repeat if Done Flag not Set
goto done1
MOVLW
0x96
; Set Byte to Read Conversion Reg.
MOVWF
COMMANDBYTE ; Store COMMAND BYTE
CALL
read_register
; Acquire the Conversion
BSF
PORTA,CS
; Set Chip Select
RETURN
; Exit subroutine