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.

EVM5517 using both codecs

Hi All,

I am using the EVM5517 development board for developing an active noise control device. For this application, I need to be able to read and write audio to both of the codecs simultaneously. I read previous forum topics on this problem, as well as I researched the available schematics and code examples, however, I did not manage to make it work yet.

I am using the example codes from Spectrum Digital, specifically the AIC3204_1 and AIC 3204_2 example codes.

As I know, this problem is tricky, since both codecs use the same i2c address. I also found that it is possible as the i2c can be routed both codecs through a two pairs of diodes as presented page B-6 on the Spectrum Digital Technical document schematics.

My understanding is that I can select the I2C_SCL_BOTH and I2C_SDA_BOTH scenarios by adjusting the SEL_I2C_S0 and SEL_I2C_S1 parameters in the software through the p02 and p03 routes.

However when I modify these parameters selecting them either high or low in any combination, it still does not give me the desired goal.

In my trials, I modified the aic3204_test.c as:

//----------------------------------- Codec 1 --------------------------------------------------
    /* Configure Serial Port 0 */
    SYS_EXBUSSEL &= ~0x0300;   // 
    SYS_EXBUSSEL |=  0x0100;   // Serial Port mode 1 (I2S1 and GP[11:10]).

    /* Configure I2C mux for AIC3204-1 */	
    EVM5517_I2CGPIO_configLine(  2, 0 );
    //EVM5517_I2CGPIO_writeLine(  2, 0 ); // SEL _I2C_S0 = 0 --> required for codec-1
    EVM5517_I2CGPIO_writeLine(  2, 1 );  // SEL_I2C_S0 = 1 ---> required for codec2
    									// required for both codec 1 and codec 2 ???

    EVM5517_I2CGPIO_configLine(  3, 0 );
    EVM5517_I2CGPIO_writeLine(  3, 0);  // SEL_I2C_S1 = 0

    /* Set AIC_MCBSP_MODE to I2S (disable McBSP) */	
    EVM5517_I2CGPIO_configLine(  1, 0 );
    EVM5517_I2CGPIO_writeLine(  1, 1 );  // AIC_MCBSP_MODE = 1

    /* Set SEL_MMC0_I2S to I2S */	
    EVM5517_I2CGPIO_configLine(  8, 0 );
    EVM5517_I2CGPIO_writeLine(  8, 1 );  // SEL_MMC0_I2S = 1
    
    /* Release AIC3204 reset */
    EVM5517_I2CGPIO_configLine(  0, 0 );
    EVM5517_I2CGPIO_writeLine(  0, 0 );  // AIC_RST = 0


// --------------------------------------Codec 2 ----------------------------------------------

    /* Configure Serial Port 0 */
    SYS_EXBUSSEL &= ~0x7300;   //
    SYS_EXBUSSEL |=  0x4100;   // Enable I2S2 pins

      // -> these commented out are performed with codec-1   /* Configure I2C mux for AIC3204-2 */
     //EVM5517_I2CGPIO_configLine(  2, 0 );
     //EVM5517_I2CGPIO_writeLine(  2, 1 );  // SEL_I2C_S0 = 1

     //EVM5517_I2CGPIO_configLine(  3, 0 );
     //EVM5517_I2CGPIO_writeLine(  3, 0 );  // SEL_I2C_S1 = 0

     EVM5517_I2CGPIO_configLine(  4, 0 );
     EVM5517_I2CGPIO_writeLine(  4, 0);  // HPI_ON = 0

        /* Configure SPI2 mux for AIC3204-2 */
     EVM5517_I2CGPIO_configLine(  5, 0 );
     EVM5517_I2CGPIO_writeLine(  5, 1 );  // SPI_I2S2_S0 = 1

     EVM5517_I2CGPIO_configLine(  6, 0 );
     EVM5517_I2CGPIO_writeLine(  6, 1 );  // SPI_I2S2_S1 = 1

        /* Release AIC3204 reset */
     EVM5517_I2CGPIO_configLine(  0, 0 );
     EVM5517_I2CGPIO_writeLine(  0, 0 );  // AIC_RST = 0


// ----------------------------------------- end of codec 2 ----------------------------------------------------

I focused on modifying the following lines which I believe adjust the SEL_i2c_S0,S1 parameters:

EVM5517_I2CGPIO_writeLine( 2, 0 or 1 ) , EVM5517_I2CGPIO_writeLine( 3, 0 or 1 )

I also modified the aic3204_loop_stereo_in1.c to enable both I2S0 and I2S2 pins:

/* I2S settings */
I2S0_SRGR = 0x0015;
I2S0_ICMR = 0x0028; // Enable interrupts
I2S0_CR = 0x8012; // 16-bit word, Master, enable I2S

/* I2S settings */
I2S2_SRGR = 0x0015;
I2S2_ICMR = 0x0028; // Enable interrupts
I2S2_CR = 0x8012; // 16-bit word, Master, enable I2S

then I am trying to read and write to the two I2S channels by:

while((Rcv & I2S2_IR) == 0); // Wait for receive interrupt to be pending
data1[sample] = I2S2_W0_MSW_R; // 16 bit left channel received audio data
data2[sample] = I2S2_W1_MSW_R; // 16 bit right channel received audio data

while((Xmit & I2S0_IR) == 0); // Wait for receive interrupt to be pending
I2S0_W0_MSW_W = data1[sample]; // 16 bit left channel transmit audio data
I2S0_W1_MSW_W = data2[sample]; // 16 bit right channel transmit audio data

when p02 =0 and p03 = 0, only codec 1 works. when p02 =1 and p03 =0 only codec 2 works.

p02 = 1 and p03 =1 does not give me the desired scenario, whereI can read and write on both codecs.

How do I need to modify the code or the hardware to achieve my goal. Please help me what am I missing!

Thank you very much for your help in advance!

Best regards,
Gergely Orosz

  • Hi Gergely,

    Sorry, I didnt have enough time to look into your code. Instead I'll blindly give you a snippet of my code... some support!

    Make sure J27 (1-3=Off, 2-4=Off)
                        J28 (1-3=Off, 2-4=Off)
                        J29 (1-3=Off, 2-4=Off)
                        J30 (1-3=On,  2-4=On)

    Int16 aic3204_test( )

    {
    	Uint16 regval;
    	Int16 i;
    
        /* Test Instructions */
    	printf("For this test, make sure J27 (1-3=Off, 2-4=Off)\n");
        printf("                         J28 (1-3=Off, 2-4=Off)\n");
        printf("                         J29 (1-3=Off, 2-4=Off)\n");
        printf("                         J30 (1-3=On,  2-4=On)\n\n");
    
        /* Configure Serial Port 0 */
        SYS_EXBUSSEL &= ~0x7300;   // 
        SYS_EXBUSSEL |=  0x4100;   // Enable I2S2 pins
    
        for (i = 0; i < 8; i++)
        {
            EVM5517_I2CGPIO_read(  i, &regval );
            printf("GPIOEXP reg %d = %04x\n", i, regval);
        }
        printf("\n");
    
        EVM5517_I2CGPIO_configLine(  4, 1 );	//MM HPI_ON is an input (controlled by DIP)
    
        /* Configure I2C mux for AIC3204-BOTH */
        EVM5517_I2CGPIO_configLine(  2, 0 );
        EVM5517_I2CGPIO_writeLine(  2, 0 );  // SEL_I2C_S0 = 0
    
        for (i = 0; i < 8; i++)
        {
            EVM5517_I2CGPIO_read(  i, &regval );
            printf("GPIOEXP reg %d = %04x\n", i, regval);
        }
        printf("\n");
    
        /* Configure I2C mux for AIC3204-BOTH */
        EVM5517_I2CGPIO_configLine(  3, 0 );
        EVM5517_I2CGPIO_writeLine(  3, 1 );  // SEL_I2C_S1 = 1
    
    //   EVM5517_I2CGPIO_configLine(  4, 0 );
    //   EVM5517_I2CGPIO_writeLine(  4, 0 );  // HPI_ON = 0
    
        for (i = 0; i < 8; i++)
        {
            EVM5517_I2CGPIO_read(  i, &regval );
            printf("GPIOEXP reg %d = %04x\n", i, regval);
        }
        printf("\n");
    
        /* Configure SPI2 mux for AIC3204-2 */
    	EVM5517_I2CGPIO_configLine(  5, 0 );
        EVM5517_I2CGPIO_writeLine(  5, 1 );  // SPI_I2S2_S0 = 1
    
        EVM5517_I2CGPIO_configLine(  6, 0 );
        EVM5517_I2CGPIO_writeLine(  6, 1 );  // SPI_I2S2_S1 = 1
    
        /* Release AIC3204 reset */
        EVM5517_I2CGPIO_configLine(  0, 0 );
        EVM5517_I2CGPIO_writeLine(  0, 0 );  // AIC_RST = 0
    
        /* Codec tests */
        printf( " -> 1 KHz Tone on Headphone.\n" );
        if ( aic3204_tone_headphone( ) )
            return 1;
           
        EVM5517_wait( 100 );  // Wait 
        printf( " -> 1 KHz Tone on Stereo OUT.\n" );
        if ( aic3204_tone_stereo_out( ) )
            return 1;
           
        EVM5517_wait( 100 );  // Wait    
        printf( "<-> Audio Loopback from Stereo IN 1 --> to HP\n" );
        if ( aic3204_loop_stereo_in1( ) )
            return 1;
            
        EVM5517_wait( 100 );  // Wait    
        printf( "<-> Audio Loopback from Stereo IN 2 --> to Stereo OUT\n" );
        if ( aic3204_loop_stereo_in2( ) )
            return 1;
        
        EVM5517_wait( 100 );  // Wait    
        printf( "<-> Microphone --> to HP\n" );
        if ( aic3204_loop_mic_in( ) )
            return 1;
    
    	EVM5517_GPIO_setOutput( GPIO26, 0 );
        return 0;
    }

    Int16 aic3204_tone_headphone( )
    {
        /* Pre-generated sine wave data, 16-bit signed samples */
        Int16 sinetable[48] = {
            0x0000, 0x10b4, 0x2120, 0x30fb, 0x3fff, 0x4dea, 0x5a81, 0x658b,
            0x6ed8, 0x763f, 0x7ba1, 0x7ee5, 0x7ffd, 0x7ee5, 0x7ba1, 0x76ef,
            0x6ed8, 0x658b, 0x5a81, 0x4dea, 0x3fff, 0x30fb, 0x2120, 0x10b4,
            0x0000, 0xef4c, 0xdee0, 0xcf06, 0xc002, 0xb216, 0xa57f, 0x9a75,
            0x9128, 0x89c1, 0x845f, 0x811b, 0x8002, 0x811b, 0x845f, 0x89c1,
            0x9128, 0x9a76, 0xa57f, 0xb216, 0xc002, 0xcf06, 0xdee0, 0xef4c
        };
        Int16 j, i = 0;
        Int16 sample;
       
         /* Configure AIC3204 */
        AIC3204_rset(  0, 0x00 );      // Select page 0
        AIC3204_rset(  1, 0x01 );      // Reset codec
        AIC3204_rset(  0, 0x01 );      // Point to page 1
        AIC3204_rset(  1, 0x08 );      // Disable crude AVDD generation from DVDD
        AIC3204_rset(  2, 0x00 );      // Enable Analog Blocks
        /* PLL and Clocks config and Power Up */
        AIC3204_rset(  0, 0x00 );      // Select page 0
        AIC3204_rset( 27, 0x00 );      // BCLK and WCLK is set as i/p to AIC3204(Slave)
        AIC3204_rset(  4, 0x07 );      // PLL setting: PLLCLK <- BCLK and CODEC_CLKIN <-PLL CLK
        AIC3204_rset(  6, 0x08 );      // PLL setting: J
        AIC3204_rset(  7, 0 );         // PLL setting: HI_BYTE(D)
        AIC3204_rset(  8, 0 );         // PLL setting: LO_BYTE(D) 
        /* For 48 KHz sampling */
        AIC3204_rset(  5, 0x92 );      // PLL setting: Power up PLL, P=1 and R=2
        AIC3204_rset( 13, 0x00 );      // Hi_Byte(DOSR) for DOSR = 128 decimal or 0x0080 DAC oversamppling
        AIC3204_rset( 14, 0x80 );      // Lo_Byte(DOSR) for DOSR = 128 decimal or 0x0080
        AIC3204_rset( 20, 0x80 );      // AOSR for AOSR = 128 decimal or 0x0080 for decimation filters 1 to 6
        AIC3204_rset( 11, 0x88 );      // Power up NDAC and set NDAC value to 8
        AIC3204_rset( 12, 0x82 );      // Power up MDAC and set MDAC value to 2
        AIC3204_rset( 18, 0x88 );      // Power up NADC and set NADC value to 8
        AIC3204_rset( 19, 0x82 );      // Power up MADC and set MADC value to 2
        /* DAC ROUTING and Power Up */
        AIC3204_rset(  0, 0x01 );      // Select page 1
        AIC3204_rset( 12, 0x08 );      // LDAC AFIR routed to HPL
        AIC3204_rset( 13, 0x08 );      // RDAC AFIR routed to HPR
        AIC3204_rset(  0, 0x00 );      // Select page 0
        AIC3204_rset( 64, 0x02 );      // Left vol=right vol
        AIC3204_rset( 65, 0x00 );      // Left DAC gain to 0dB VOL; Right tracks Left
        AIC3204_rset( 63, 0xd4 );      // Power up left,right data paths and set channel
        AIC3204_rset(  0, 0x01 );      // Select page 1
        AIC3204_rset( 16, 0x06 );      // Unmute HPL , 6dB gain
        AIC3204_rset( 17, 0x06 );      // Unmute HPR , 6dB gain
        AIC3204_rset(  9, 0x30 );      // Power up HPL,HPR
        AIC3204_rset(  0, 0x00 );      // Select page 0
        EVM5517_wait( 500 );           // Wait
        /* ADC ROUTING and Power Up */
        AIC3204_rset(  0, 0x01 );      // Select page 1
        AIC3204_rset( 52, 0x0C );      // STEREO 1 Jack
    		                           // IN2_L to LADC_P through 40 kohm
        AIC3204_rset( 55, 0x0C );      // IN2_R to RADC_P through 40 kohmm
        AIC3204_rset( 54, 0x03 );      // CM_1 (common mode) to LADC_M through 40 kohm
        AIC3204_rset( 57, 0xC0 );      // CM_1 (common mode) to RADC_M through 40 kohm
        AIC3204_rset( 59, 0x00 );      // MIC_PGA_L unmute
        AIC3204_rset( 60, 0x00 );      // MIC_PGA_R unmute
        AIC3204_rset(  0, 0x00 );      // Select page 0
        AIC3204_rset( 81, 0xc0 );      // Powerup Left and Right ADC
        AIC3204_rset( 82, 0x00 );      // Unmute Left and Right ADC
        
        AIC3204_rset( 0,  0x00 );    
        EVM5517_wait( 200 );           // Wait
        
        /* Configure I2S0 as master */
        I2S0_SRGR = 0x0015;
        I2S0_ICMR = 0x0028;    // Enable interrupts
        I2S0_CR   = 0x8012;    // 16-bit word, Master, enable I2S
    
        /* I2S settings */
        I2S2_SRGR = 0x0015;
        I2S2_ICMR = 0x0028;    // Enable interrupts
        I2S2_CR   = 0x8012;    // 16-bit word, Master, enable I2S
    
        /* Play Tone */
        for ( i = 0 ; i < 5 ; i++ )
        {
            for ( j = 0 ; j < 1000 ; j++ )
            {
                for ( sample = 0 ; sample < 48 ; sample++ )
                {
                    I2S2_W0_MSW_W = (sinetable[sample]) ;  // Send left sample
                    I2S2_W0_LSW_W = 0;
                    I2S2_W1_MSW_W = (sinetable[sample]) ;  // Send right sample
                    I2S2_W1_LSW_W = 0;
                    while((Xmit & I2S2_IR) == 0);          // Wait for interrupt
                }
            }
        }
        /* Disble I2S */
        I2S2_CR = 0x00;
       
        return 0;
    }

    Hope this helps,
    Mark

  • Dear Mark!

    Thank you very much for your support! I implemented the changes from your code to mine, however, I still did not manage to achieve my aim.

    The jumpers are correct, they are only on J30 connecting 1-3 and 2-4.

    With the new bit of code I receive this in the console:

    EXBUSSEL = 1000
    01 Testing AIC3204...
    For this test, make sure J27 (1-3=Off, 2-4=Off)
    J28 (1-3=Off, 2-4=Off)
    J29 (1-3=Off, 2-4=Off)
    J30 (1-3=On, 2-4=On)

    GPIOEXP reg 0 = 00c2
    GPIOEXP reg 1 = 00fe
    GPIOEXP reg 2 = 00df
    GPIOEXP reg 3 = 00ff
    GPIOEXP reg 4 = 0000
    GPIOEXP reg 5 = 0000
    GPIOEXP reg 6 = 001f
    GPIOEXP reg 7 = 00ff

    GPIOEXP reg 0 = 00c2
    GPIOEXP reg 1 = 00fe
    GPIOEXP reg 2 = 00db
    GPIOEXP reg 3 = 00ff
    GPIOEXP reg 4 = 0000
    GPIOEXP reg 5 = 0000
    GPIOEXP reg 6 = 001b
    GPIOEXP reg 7 = 00ff

    GPIOEXP reg 0 = 00ca
    GPIOEXP reg 1 = 00fe
    GPIOEXP reg 2 = 00db
    GPIOEXP reg 3 = 00ff
    GPIOEXP reg 4 = 0000
    GPIOEXP reg 5 = 0000
    GPIOEXP reg 6 = 0013
    GPIOEXP reg 7 = 00ff

    I configured the aic3204_loop_stereo_in1.c to read and write to the second codec. With the new changes there is not data (zeros) appearing shown in the variables window. Please let me know if you need any further information about the code I am using!

    I really appreciate your help!

    Best regards,

    Gergely Orosz