An74 – Cirrus Logic AN74 User Manual
Page 2

AN74
2
AN74Rev2
diagram. While reading this application note,
please refer to the Appendix for the code listing.
Initialize
Initialize is a subroutine that configures P1 (Port 1)
on the 80C51 and places the CS5525/6/9 into the
command-state. First, P1’s data direction is config-
ured as depicted in Figure 1 (for more information
on configuring ports refer to 80C51 Data Sheet).
After configuring the port, the controller enters a
delay state to allow time for the CS5525/6/9’s pow-
er-on-reset and oscillator to start-up (oscillator
start-up time is typically 500ms). The last step is to
reinitialize the serial port on the ADC (reinitializ-
ing the serial port is unnecessary here, the code was
added for demonstration purposes only). This is
implemented by sending the converter sixteen
bytes of logic 1’s followed by one final byte, with
its LSB at logic 0. Once sent, the sequence places
the serial port of the ADC into the command-state,
where it awaits a valid command.
After retuning to main, the software demonstrates
how to calibrate the converter’s offset.
Self-Offset Calibration
Calibrate is a subroutine that calibrates the con-
verter’s offset. Calibrate first sends 0x000001
(Hex) to the configuration register. This instructs
the converter to perform a self-offset calibration.
Then the Done Flag (DF) bit in the configuration
register is polled until set. Once DF is set, it indi-
cates that a valid calibration was performed. To
minimize digital noise (while performing a calibra-
tion or a conversion), many system designers may
find it advantageous to add a software delay equiv-
alent to a conversion or calibration cycle before
polling the DF bit.
Read/Write Gain Register
To modify the gain register the command-byte and
data-byte variables are first initialized. Then the
subroutine write_to_register uses these variables to
set the contents of the gain register in the CS5525/
6/9 to 0x800000 (HEX). To do this,
write_to_register calls transfer_byte four times
(once for the command byte and three additional
times for the 24 bits of data). Transfer_byte is a
subroutine used to ‘bit-bang’ a byte of information
from the 80C51 to the CS5525/6/9. A byte is trans-
ferred one bit at a time, MSB (most significant bit)
first, by placing a bit of information on P1.1 (SDI)
and then pulsing P1.3 (SCLK). The byte is trans-
ferred by repeating this process eight times. Figure
3 depicts the timing diagram for the write-cycle in
the CS5525/6/9’s serial port. This algorithm dem-
onstrates how to write to the gain register. It does
not perform a gain calibration. To perform a gain
calibration, follow the procedures outlined in the
data sheet.
To verify that 0x800000(HEX) was written to the
gain register, read_register is called. It duplicates
the read-cycle timing diagram depicted in Figure 4.
Read_register first asserts CS. Then it calls
transfer_byte
once to transfer the command-byte to
the CS5525/6/9. This places the converter into the
Figure 2. CS5525/6/9 Software Flowchart
START
INITIALIZE
SELF-OFFSET CAL.
MODIFY GAIN
ACQUIRE CONVERSION
MICROCONTROLLER & CS5525/6/9