An74 – Cirrus Logic AN74 User Manual

Page 9

Advertising
background image

AN74

AN74Rev2

9

/**************************************************************************************
* Routine - read_register
* Input

- command

* Output - low_byte, mid_byte, high_byte
*
* This subroutine reads an internal register of the ADC
/**************************************************************************************/
void

read_register(char command){
if(mode == 1) P1 = 0xF4;

/*Assert CS if necessary */

transfer_byte(command);

/*Transfer Command Byte to CS5525/6/9*/

high_byte = receive_byte();

/*Receive Command Byte from CS5525/6/9*/

mid_byte = receive_byte();

/*Receive Command Byte from CS5525/6/9*/

low_byte = receive_byte();

/*Receive Command Byte from CS5525/6/9*/

if(mode == 1)P1 = 0xF5;

/*Deassert CS if necessary */

}

/**************************************************************************************/
* Routine - acquire_conversion
* Input

- command

* 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.
/**************************************************************************************/
void

acquire_conversion(char command){
/*** Read Configuration Register to Prevent Previously Set Bits from being Altered ***/
read_register(0x94);

/*Read Configuration Register*/

low_byte = low_byte|0x20;

/*Assert Port Flag Bit*/

write_to_register(0x84,low_byte, mid_byte, high_byte);/*Actually Send Commands*/

/*Acquire a Conversion*/
if(mode == 1)P1

= 0xF4;

/*Assert CS if necessary*/

transfer_byte(0xC0);

/*Transfer Command to CS5525/6/9*/

toggle_sdo();

/*Clear SDO*/

high_byte = receive_byte();

/*Receive Command Byte from CS5525/6/9*/

mid_byte = receive_byte();

/*Receive Command Byte from CS5525/6/9*/

low_byte = receive_byte();

/*Receive Command Byte from CS5525/6/9*/

if(mode == 1) P1

= 0xF5;

/*Deassert CS if necessary*/

}

Advertising