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.

HOW TO USE I2C_write for AIC3204

Other Parts Discussed in Thread: TMS320VC5505

Hi

I was trying to use the library function I2C_write  (CSL library function for 320c5505)  to configure the AIC3204 of my USBSTICK .

the function parameters say only the I2C device address , databuffer etc . With this function how

we can write to the differnt pages of AIC3204 ?? , Could some one give some help on these please .

I tried the USBSTK5505 function its working .

Thanks

Dingle

  • There is some example code provided on Spectrum Digital's Support site for the TMS320VC5505 eZDSP USB Stick in the "Test Code" that might be of interest to refer to.  It helps provide some insight into the format of the I2C transactions required to communicate to the AIC3204.

    That said, fundamentally you need to reference the AIC3204 datasheet, in the Control Interface section, to understand how the I2C transactions need to be implemented to write to the various AIC3204 registers.  This is indicated in Figure 5-54 and Figure 5-55 for I2C writes and I2C reads to the AIC3204 registers.  From an I2C physical layer perspective, it simply requires a Device Address, Command bit (read or write) and then data.  This is detailed in the I2C specification.  The device address will be provided in the AIC3204 datasheet, which is 0011000b.

    In addition, there are example setups in Section 5.22.

     

    Keep in mind, the CSL, or Chip Support Library, provides functions and APIs that are relevant for the on-chip peripherals and not necessarily geared for specific board hardware configurations, such as connecting the I2C interface to a particular codec like the AIC3204.  The eZDSP could have been developed with a different codec, but still use the I2C interface to control it.  If so, it would not make sense to have the CSL, or Chip Support Library, have specific functions for an AIC3204 when an actual different codec was used on the eZDSP.

  • Hi Brandon

    Thank You very much for the reply . The code from Spectrum digital is not using CSL and I have tried and tested 

    thier code . I did understand how they initilaise it with the USBSTK5505 library . I was trying to implement the same thing using

    CSL library  . My intention is to initilise the I2c registers  of DSP first  ( so that I can send init. codes to CODEC )

    with the required parameters  and  then to initilise the CODEC by sending  the the different parameters one by one through the I2c bus


    bus , after properly initilising CODEC  I want to play a  sine wave of 1khz to the headphone using I2S  . 

     I am pasting the code below , when I RUN this code it will print  'TIME OUT ERROR '

    but if I single step it wont flash that error , so I think its a timing error . could you please have a look and point me in the right direction .

    thanks a lot

    Dingle

    /*--------------------------------------------------CODE----------------------------------*/

    #include <csl_i2c.h>
    #include <stdio.h>
    #include <usbstk5505.h>
    #define XmitL 0x10
    #define XmitR 0x20
    #define CSL_I2C_TEST_PASSED      (0)
    #define CSL_I2C_TEST_FAILED      (1)

    #define CSL_I2C_DATA_SIZE        (64)
    #define CSL_EEPROM_ADDR_SIZE     (2)
    #define CSL_I2C_OWN_ADDR         (0x2F)
    #define CSL_I2C_SYS_CLK          (12.228)
    //#define CSL_I2C_SYS_CLK          (40)
    //#define CSL_I2C_SYS_CLK          (60)
    //#define CSL_I2C_SYS_CLK          (75)
    //#define CSL_I2C_SYS_CLK          (100)
    #define CSL_I2C_BUS_FREQ         (10)
    #define CSL_I2C_EEPROM_ADDR         (0x50)
    #define CSL_I2C_CODEC_ADDR         (0x18)

    CSL_I2cSetup     i2cSetup;
    CSL_I2cConfig    i2cConfig;
    CSL_Status  CSL_i2caic3204init(void);
    CSL_Status  AIC3204_write(Uint16 ,Uint16 );
    CSL_Status  AIC3204_read(Uint16 );
    void mywait( Uint16 );   

    void main(void)
    {
        CSL_Status    result;   
       
        Int16 j, i = 0;
        Int16 sample;
        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
        };     
       
        
        /* Configure Serial Bus */
        SYS_EXBUSSEL |= 0x0100;                                             // Configure Serial bus 0 for I2S0    
       
    /*-------------------------------------I2C init starts here -------------------------------------------*/

      printf("I2C Initilisation started \n");
       
        result = CSL_i2caic3204init ();
        if(result == CSL_I2C_TEST_PASSED)
        {
            printf("I2C  init  Passed!!\n");
        }
        else
        {
            printf("I2C  init Failed!!\n");
        }

    /*------------------------------CODEC initilisation starts here --------------------------------------------*/

    result=AIC3204_write(0,0);
    result=AIC3204_write(1,1);
    result=AIC3204_write(0,1);
    result=AIC3204_write(1,8);
    result=AIC3204_write(2,1);
    result=AIC3204_write(0,0);

    //pll
    result=AIC3204_write(27,0x0d);
    result=AIC3204_read(27);                    // -------------- to read back  the value written --- for testing
    result=AIC3204_write(28,0x00);
    result=AIC3204_read(28);  //                    
    result=AIC3204_write(4,3);
    //pll clk
    result=AIC3204_write(6,8);
    result=AIC3204_write(7,15);
    result=AIC3204_write(8,0xdc);
    result=AIC3204_read(8);
    result=AIC3204_write(30,0x88);
    result=AIC3204_read(30);

    result=AIC3204_write(5,0x91);

    result=AIC3204_write(13,0);
    //dac oversampling
    result=AIC3204_write(14,0x80);
    result=AIC3204_write(20,0x80);
    //decimation
    result=AIC3204_write(11,0x88);
    result=AIC3204_write(12,0x82);
    result=AIC3204_write(18,0x88);
    result=AIC3204_write(19,0x82);
    //dacrouting and powerup
    result=AIC3204_write(0,1);
    result=AIC3204_write(0x0c,8);
    result=AIC3204_write(0x0d,8);
    result=AIC3204_write(0,0);

    result=AIC3204_write(64,2);
    result=AIC3204_write(65,0);
    result=AIC3204_write(63,0xd4);
    result=AIC3204_write(0,1);

    result=AIC3204_write(0x10,0x3a);
    result=AIC3204_write(0x11,0x3a);
    result=AIC3204_write(9,0x30);
    result=AIC3204_write(0,0);
    mywait(1000);
    //adc routing and powerup
    result=AIC3204_write(0,1);
    result=AIC3204_write(0x34,0x30);

    result=AIC3204_write(0x37,0x30);
    result=AIC3204_write(0x36,3);
    result=AIC3204_write(0x39,0xc0);
    result=AIC3204_write(0x3b,0);

    result=AIC3204_write(0x3c,0);
    result=AIC3204_write(0,0);
    result=AIC3204_write(0x51,0xc0);
    result=AIC3204_write(0x52,0);

    result=AIC3204_write(0,0);
    mywait(2000);
    /* -------------------------------------------CODEC init. is over -------------------------------------------------------*/

    /*--------------------------------------------play the sine wave -------------------------------------------------------*/
    for ( i = 0 ; i < 400 ; i++ )
        {
            for ( j = 0 ; j < 1000 ; j++ )
            {
                for ( sample = 0 ; sample < 48 ; sample++ )
                {
                    /* Write sine table samples */
                    I2S0_W0_MSW_W = (sinetable[sample]) ;
                      I2S0_W0_LSW_W = 0;
                      while((XmitR & I2S0_IR) != 0)
                       I2S0_W1_MSW_W = (sinetable[sample]) ;
                      I2S0_W1_LSW_W = 0;
                }
            }
        }

       /* Disble I2S */
        I2S0_CR = 0x00;
        SW_BREAKPOINT;

    }
    /* ---------------------------------------Main function ends here -----------------------------------------*/

    /*------------------------------------------------------------I2c init , setup function ----------------------------*/
    CSL_Status  CSL_i2caic3204init(void)
    {
       
        CSL_Status         status;
        CSL_Status         result,result1;
        Uint16     SStop;
        volatile Uint16    looper;
        result = CSL_I2C_TEST_FAILED;
        result1 =CSL_I2C_TEST_PASSED;

        /* Initialize I2C module */
        status = I2C_init(CSL_I2C0);
        if(status != CSL_SOK)
        {
            printf("I2C module Init Failed!!\n");
            return(result);
        }
        /* Setup I2C module */
        i2cSetup.addrMode    = CSL_I2C_ADDR_7BIT;
        i2cSetup.bitCount    = CSL_I2C_BC_8BITS;
        i2cSetup.loopBack    = CSL_I2C_LOOPBACK_DISABLE;
        i2cSetup.freeMode    = CSL_I2C_FREEMODE_DISABLE;
        i2cSetup.repeatMode  = CSL_I2C_REPEATMODE_DISABLE;
        i2cSetup.ownAddr     = CSL_I2C_OWN_ADDR;
        i2cSetup.sysInputClk = CSL_I2C_SYS_CLK;
        i2cSetup.i2cBusFreq  = CSL_I2C_BUS_FREQ;
        SStop                = ((CSL_I2C_START) | (CSL_I2C_STOP));

        status = I2C_setup(&i2cSetup);
        if(status != CSL_SOK)
        {
            printf("I2C module Setup Failed!!\n");
            return(result);
        }
        return(result1);   
    }
     /*---------------------------------------------------------------------------------------------------------*/   
                              // my function to write into aic3204 regs

    CSL_Status  AIC3204_write(Uint16 regnum,Uint16 regval)
    {
       
        Uint16 cmd[2];
        CSL_Status status;
        Uint16     SStop;
        cmd[0]=regnum &0x007f;
        cmd[1]=regval;
        SStop            = ((CSL_I2C_START) | (CSL_I2C_STOP));
        status = I2C_write(cmd,2,CSL_I2C_CODEC_ADDR,TRUE,SStop,CSL_I2C_MAX_TIMEOUT);
        if(status != CSL_SOK )
         { printf("aicwrite failed \n" );
          if(status == CSL_ESYS_INVPARAMS   ) {printf ( "INVALID PARAMETERS \n");}
          if(status == CSL_I2C_BUS_BUSY_ERR ) {printf ( "BUS BUSY \n"); }
          if(status == CSL_I2C_TIMEOUT_ERROR ) {printf ( "TIME OUT ERROR \n"); }
          if(status == CSL_I2C_NACK_ERR ) {printf ("NO ACK\n"); }
         
         }
        return(status);
    }
     //------------------------- my function for delay------------------------------------//
    void mywait(Uint16 value)   
    {
        Uint16 x;
        for(x=0;x<value;x++)
        { ; }
    }   
    //---------------------------CODEC I2C  read ----------------------------------------------//
    CSL_Status  AIC3204_read(Uint16 regnum)
    {
       
        Uint16 cmd[2];
        CSL_Status status;
        Uint16     SStop;
        cmd[0]=regnum &0x007f;
        cmd[1]=0;
        SStop            = ((CSL_I2C_START) | (CSL_I2C_STOP));
        status = I2C_read(cmd,1,CSL_I2C_CODEC_ADDR,TRUE,SStop,CSL_I2C_MAX_TIMEOUT,FALSE);
        if(status != CSL_SOK )
         { printf("aicread failed \n" );
          if(status == CSL_ESYS_INVPARAMS   ) {printf ( "INVALID PARAMETERS \n");}
          if(status == CSL_I2C_BUS_BUSY_ERR ) {printf ( "BUS BUSY \n"); }
          if(status == CSL_I2C_TIMEOUT_ERROR ) {printf ( "TIME OUT ERROR \n"); }
          if(status == CSL_I2C_NACK_ERR ) {printf ("NO ACK\n"); }
         
         }
         printf("value from register is %d\n",cmd[0]);
        return(status);
    }

  • Is the CSL_I2C_TIMEOUT_ERROR observed on the first AIC3204 access, or subsequent access?

    Looking at the actual CSL code for the I2C_write() API, there are a few places where this error could be generated.  It would be helpful to understand where in the I2C_write, the status flag is getting set with this value.  I would suggest placing breakpoints in the csl_i2c.c code in the areas where a return with this status is made to identify what is being attempting when the timeout occurs.