English
Language : 

SGTL5000XNAA3 Datasheet, PDF (44/84 Pages) Freescale Semiconductor, Inc – Low Power Stereo Codec with Headphone Amp
SGTL5000
DATASHEET
6. PROGRAMMING EXAMPLES
This section provides programming examples that show how to configure the chip.
The registers can be written/read by using I2C communication protocol. The chip
also supports SPI communication protocol but only register write operation is sup-
ported.
6.1. Prototype for Reading and Writing a Register
The generic register read write prototype will be used throughout this section as
shown below. The I2C or SPI implementation will be specific to the I2C/SPI hard-
ware used in the system.
// This prototype writes a value to the entire register. All
// bit-fields of the register will be written.
Write REGISTER REGISTERVALUE
// This prototype writes a value only to the bit-field specified.
// In the actual implemention, the other bit-fields should be
// masked to prevent them from being written. Also, the
// actual implementation should left-shift the BITFIELDVALUE
// by appropriate number to match the starting bit location of
// the BITFIELD.
Modify REGISTER -> BITFIELD, BITFIELDVALUE //Bitfield Location
// Example implementation
// Modify DAP_EN (bit 0) bit to value 1 to enable DAP block
Modify( DAP_CONTROL_REG, 0xFFFE, 1 << DAP_EN_STARTBIT );
// Example Implementation of Modify
void Modify( unsigned short usRegister,
unsigned short usClearMask,
unsigned short usSetValue )
{
unsigned short usData;
// 1) Read current value
ReadRegister( usRegister, &usData );
// 2) Clear out old bits
usData = usData & usClearMask;
// 3) set new bit values
usData = usData | usSetValue;
// 4) Write out new value created
WriteRegister( usRegister, usData );
}
44
SGTL5000 EA2 DS-0-3