地址是按例程设置的
/* codec's TWI address, this is the upper 7 bits, the lowest bit will
be 0 for write (0x36), and 1 for read (0x37) */
#define CODEC_TWI_ADDRESS 0x1b
分步进入TWI函数时MCOMP始终不能置位
unsigned char ResetControl[] = { 0x1e, 0x00};
unsigned char LeftLineIn[] = { 0x00, 0x01b};
unsigned char RightLineIn[] = { 0x02, 0x01b};
unsigned char LeftHpOut[] = { 0x04, 0x07f};
unsigned char RightHpOut[] = { 0x06, 0x07f};
unsigned char AnalogControl[] = { 0x08, 0x010};
unsigned char DigitalControl[] = { 0x0a, 0x000};
unsigned char PowerDownControl[] = { 0x0c, 0x000};
unsigned char DigitalAudioFormat[] ={ 0x0e, 0x042};
unsigned char SamplingControl[] = { 0x10, 0x001};
unsigned char ActiveControl[] = { 0x12, 0x001};
int TWI_Error = 0;
TWISuccess = 0;
while (TWISuccess == 0 && TWI_Error < 100)
{
TWISuccess = 1;
Reset_TWI(); /* reset the TWI interface */
TWI_MasterMode_Write( CODEC_TWI_ADDRESS, ResetControl, 1, 2);
TWI_MasterMode_Write( CODEC_TWI_ADDRESS, LeftLineIn, 1, 2);
TWI_MasterMode_Write( CODEC_TWI_ADDRESS, RightLineIn, 1, 2);
TWI_MasterMode_Write( CODEC_TWI_ADDRESS, LeftHpOut, 1, 2);
TWI_MasterMode_Write( CODEC_TWI_ADDRESS, RightHpOut, 1, 2);
TWI_MasterMode_Write( CODEC_TWI_ADDRESS, AnalogControl, 1, 2);
TWI_MasterMode_Write( CODEC_TWI_ADDRESS, DigitalControl, 1, 2);
TWI_MasterMode_Write( CODEC_TWI_ADDRESS, PowerDownControl, 1, 2);
TWI_MasterMode_Write( CODEC_TWI_ADDRESS, DigitalAudioFormat, 1, 2);
TWI_MasterMode_Write( CODEC_TWI_ADDRESS, SamplingControl, 1, 2);
if(TWISuccess)
for (j=0; j<0x1ffffff; j++) asm("nop;");
/*** lastly activate the digital engine *******************/
TWI_MasterMode_Write( CODEC_TWI_ADDRESS, ActiveControl, 1, 2);
if(!TWISuccess)
TWI_Error++;
}