This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/TLV320AIC3104: I2C-Communication with AIC31 and TM4C123GH6PM Microcontroller

Part Number: TLV320AIC3104

Tool/software: Code Composer Studio

Hi all,

the communication between the microcontroller and the audio-codec ist not working. It get stucked in the function "WriteReg_AIC" in the 5th line. I want to configure the audio-codec as ADC and DAC but I cant´t get any communication to it. Can anybody help me?

void Init_I2C (void)
{
	//SysCtlPeripheralReset(SYSCTL_PERIPH_I2C1);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C1);		// enable I2C

	//SysCtlPeripheralReset(SYSCTL_PERIPH_GPIOA);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);	// enable GPIOA

	while(!SysCtlPeripheralReady(SYSCTL_PERIPH_I2C1) && !SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOA));	// wait until modules are ready

	GPIOPinTypeI2CSCL(GPIO_PORTA_BASE, GPIO_PIN_6);		// configure pin for use as I2CSCL
	GPIOPinTypeI2C(GPIO_PORTA_BASE, GPIO_PIN_7);		// configure pin for use as I2CSDA

	GPIOPinConfigure(GPIO_PA6_I2C1SCL);		// configure pin muxing
	GPIOPinConfigure(GPIO_PA7_I2C1SDA);

	I2CMasterInitExpClk(I2C1_BASE, SysCtlClockGet(), false);	// initalize I2C Master (100 Kbps)
}


_Bool WriteReg_AIC(uint32_t ucReg, uint32_t ucBits)
{
    I2CMasterSlaveAddrSet(I2C1_BASE, SLAVE_ADDR_AIC3104, false);
    I2CMasterDataPut(I2C1_BASE, ucReg);
    while(I2CMasterBusBusy(I2C1_BASE));
    I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_SEND_START);
    while(I2CMasterBusy(I2C1_BASE));
    if(I2CMasterErr(I2C1_BASE) != I2C_MASTER_ERR_NONE) return false;

    I2CMasterDataPut(I2C1_BASE, ucBits);
    I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
    while(I2CMasterBusy(I2C1_BASE));
    if(I2CMasterErr(I2C1_BASE) != I2C_MASTER_ERR_NONE) return false;

    return true;
}

void Init_ADC(void)
{
	WriteReg_AIC(19, 0x07);		// LINE1LP to Left-ADC, single-ended, gain=0dB, power up, soft-stepping=off
	WriteReg_AIC(22, 0x07);		// LINE1RP to Right-ADC, single-ended, gain=0dB, power up, soft-stepping=off
	WriteReg_AIC(15, 0x80);		// left-ADC PGA is not muted, gain=0dB
	WriteReg_AIC(16, 0x80);		// right-ADC PGA is not muted, gain=0dB
}

void Init_DAC(void)
{
	WriteReg_AIC(7, 0x0A);		// left DAC to left channel and right DAC to right channel, fs(ref)=48kHz
	WriteReg_AIC(37, 0xE0);		// power up left and right DAC, HPLCOM is single ended
	WriteReg_AIC(41, 0x00);		// DAC_L1 and DAC_R1 for routing to Line out and HP OUT, left and right DAC have independent volume control
	WriteReg_AIC(43, 0x00);		// left volume, mute=off, gain=0db
	WriteReg_AIC(44, 0x00);		// right volume, mute=off, gain=0db

	WriteReg_AIC(47, 0x80);		// DAC_L1 to HPLOUT (headphone)
	WriteReg_AIC(51, 0x0F);		// power up HPLOUT
	WriteReg_AIC(64, 0x80);		// DAC_R1 to HPROUT (headphone)
	WriteReg_AIC(65, 0x0F);		// power up HPROUT

	WriteReg_AIC(82, 0x80);		// DAC_L1 to LEFT_LOP/M (line out)
	WriteReg_AIC(86, 0x09);		// power up LEFT_LOP/M
	WriteReg_AIC(92, 0x80);		// DAC_R1 to RIGHT_LOP/M (line out)
	WriteReg_AIC(93, 0x09);		// power up RIGHT_LOP/M
}

void Init_AIC3104(void)
{
	Init_I2C();

	WriteReg_AIC(0, 0x00);		// page select
	WriteReg_AIC(1, 0x80);		// software reset

	WriteReg_AIC(8, 0xC0);		// BCLK and WCLK as output (master mode)
	WriteReg_AIC(9, 0x00);		// I2S mode, 16 bits (word length)
	WriteReg_AIC(10, 0x00);		// no data offset

	Init_ADC();
	Init_DAC();
}

  • Hi, Sadullah,

    We can check the TLV320AIC3104 configuration here in the Audio Converters Forum, but this problem seems to be more related to the programming of the function used. Also, from the context of the code, the issue may be related to the I²C bus state.  Probably my colleagues from the Code Composer Forum could give you a more accurate answer on this issue.

    Best Regards,

      -Diego Meléndez López
       Audio Applications Engineer