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.

TMS320DM6446: TMS320DM6446

Part Number: TMS320DM6446

I have to do Write and Read to PCA2129 using I2C peripheral of TMS320dm6446.

I am checking the data being transmitted out from I2C of TMS320DM6446 on Oscilloscope which is not matching with the actual data written in the code.

Pls suggest what could be the issue ?

The code being used is as under:



#include "stdio.h"
#include "davincievm.h"
#include "davincievm_uart.h"
#include <csl_spi.h>
#include <csl_spiAux.h>
#include <davincievm_gpio.h>
 
#include "stdlib.h"

#include "davincievm.h"


#include "string.h"

 
 
void main( void )
{
 
Uint32 i;
Uint32 jj;
 
unsigned char add_regI2c=0,I2C_len=0,I2C_SLAddr, cntRD;
 
DAVINCIEVM_GPIO_init();
 
 PINMUX0 &=0xffff7fE0;
 
 DAVINCIEVM_GPIO_setDirection(12, 0);
 DAVINCIEVM_GPIO_setOutput(12, 1);
 
    
 
   PINMUX1 &=0xffffff7f;
   PINMUX1 |=0x00000080;
   DAVINCIEVM_I2C_reset();
 
     add_regI2c=0x03;
     //I2C_len = 0x02;
     //I2C_SLAddr = 0xA2;
     while(1)
     {
      DAVINCIEVM_I2C_write(0xA2, &add_regI2c, 3);
      
      DAVINCIEVM_I2C_read(0xA3, &RDsec, 0x01);
 
     cntRD++;
     }
}
 
 
 
 
 
//Following files are added as header/source/include
 
///////////////////////////////////////////////////////////////////////////////////////////////////////
/*
 *  Copyright 2005 by Spectrum Digital Incorporated.
 *  All rights reserved. Property of Spectrum Digital Incorporated.
 *
 *  Not for distribution.
 */
 
/*
 *  I2C implementation
 *
 */
 
#include "davincievm_i2c.h"
 
/* ------------------------------------------------------------------------ *
 *                                                                          *
 *  DAVINCIEVM_I2C_init( )                                                  *
 *                                                                          *
 *      Enable and initalize the I2C module                                 *
 *                                                                          *
 *      The I2C clk is set to run at 20 KHz                                 *
 *                                                                          *
 * ------------------------------------------------------------------------ */
Int16 DAVINCIEVM_I2C_init( )
{
    #ifdef ARM_SIDE
 
        CSL_Status status;
        CSL_I2cClkSetup i2c_clksetup;
        CSL_I2cHwSetup  i2c_hwsetup;
        CSL_I2cParam    i2c_param;
 
        CSL_i2cInit( 0 );
        i2c_handle = CSL_i2cOpen( &i2c_obj, 0, &i2c_param, &status );
 
        i2c_clksetup.prescalar      = 26;
        i2c_clksetup.clklowdiv      = 20;
        i2c_clksetup.clkhighdiv     = 20;
 
        i2c_hwsetup.mode            = 1;    // 0: Slave mode        1: Master mode
        i2c_hwsetup.dir             = 0;    // 0: Rx mode           1: Tx mode
        i2c_hwsetup.addrMode        = 0;    // 0: 7-bit mode        1: 10-bit mode//0
        i2c_hwsetup.sttbyteen       = 0;    // 0: Normal mode       1: Start byte mode //0
        i2c_hwsetup.ownaddr         = 1;    // #: Own address//0
        i2c_hwsetup.ackMode         = 0;    // 0: ACK mode          1: NACK mode
        i2c_hwsetup.runMode         = 0;    // 0: No Free run mode  1: Free run mode//1
        i2c_hwsetup.repeatMode      = 0;    // 0: No repeat mode    1: Repeat mode
        i2c_hwsetup.loopBackMode    = 0;    // 0: No loopback       1: Loopback mode//0
        i2c_hwsetup.freeDataFormat  = 0;    // 0: No Free data fmt  1: Free data fmt
        i2c_hwsetup.resetMode       = 1;    // 0: Reset             1: Out of reset//0
        i2c_hwsetup.bcm             = 0;    // 0: Not compatible    1: Compatible
        i2c_hwsetup.inten           = 0;    // #: Intr enable mask
        i2c_hwsetup.clksetup        = &i2c_clksetup;
 
        status = CSL_i2cHwSetup( i2c_handle, &i2c_hwsetup );
 
        CSL_i2cHwControl( i2c_handle, CSL_I2C_CMD_OUTOFRESET, 0 );
        return 0;
 
    #elif DSP_SIDE
 
        I2C_ICMDR   = 0;                    // Reset I2C
        I2C_ICPSC   = 26;                   // Config prescaler for 27MHz
        I2C_ICCLKL  = 5;                    // Config clk LOW for 50kHz
        I2C_ICCLKH  = 5;                    // Config clk HIGH for 50kHz
        I2C_ICMDR  |= ICMDR_IRS;            // Release I2C from reset
        return 0;
 
    #endif
}
 
/* ------------------------------------------------------------------------ *
 *                                                                          *
 *  DAVINCIEVM_I2C_close( )                                                 *
 *                                                                          *
 * ------------------------------------------------------------------------ */
Int16 DAVINCIEVM_I2C_close( )
{
    #ifdef ARM_SIDE
 
        CSL_i2cHwControl( i2c_handle, CSL_I2C_CMD_RESET, 0 );
        CSL_i2cClose( i2c_handle );
        return 0;
 
    #elif DSP_SIDE
 
        I2C_ICMDR = 0;                      // Reset I2C
        return 0;
 
    #endif
}
 
/* ------------------------------------------------------------------------ *
 *                                                                          *
 *  DAVINCIEVM_I2C_reset( )                                                 *
 *                                                                          *
 *                                                                          *
 *                                                                          *
 * ------------------------------------------------------------------------ */
Int16 DAVINCIEVM_I2C_reset( )
{
    DAVINCIEVM_I2C_close( );
    DAVINCIEVM_I2C_init( );
    return 0;
}
 
/* ------------------------------------------------------------------------ *
 *                                                                          *
 *  DAVINCIEVM_I2C_write( i2caddr, data, len )                              *
 *                                                                          *
 *      I2C write in Master mode                                            *
 *                                                                          *
 *      i2caddr <- I2C slave address                                        *
 *      data    <- I2C data ptr                                             *
 *      len     <- # of bytes to write                                      *
 *                                                                          *
 * ------------------------------------------------------------------------ */
Int16 DAVINCIEVM_I2C_write( Uint16 i2caddr, Uint8* data, Uint16 len )
{
    Uint16 i;
    Int32 timeout   = 0x20000;
    Int32 timecount = 0;
 
    #ifdef ARM_SIDE
 
        Uint16 response;
 
        CSL_i2cHwControl( i2c_handle, CSL_I2C_CMD_SET_DATA_COUNT, &len );
        CSL_i2cHwControl( i2c_handle, CSL_I2C_CMD_SET_SLAVE_ADDR, &i2caddr );
        CSL_i2cHwControl( i2c_handle, CSL_I2C_CMD_DIR_TRANSMIT, 0 );
        CSL_i2cHwControl( i2c_handle, CSL_I2C_CMD_START, 0 );
 
        DAVINCIEVM_wait( 10 );
 
        for ( i = 0 ; i < len ; i++ )
        {
            CSL_i2cWrite( i2c_handle, &data[i] );
 
            timecount = 0;
            do
            {
                CSL_i2cGetHwStatus( i2c_handle, CSL_I2C_QUERY_TX_RDY, &response );
 
                timecount++;
                if ( timecount >= timeout )
                {
                    DAVINCIEVM_I2C_reset( );
                    return 1000;
                }
 
            } while( response == 0 );
        }
 
      //CSL_i2cHwControl( i2c_handle, CSL_I2C_CMD_STOP, 0 );
 
        return 0;
 
    #elif DSP_SIDE
 
        I2C_ICCNT = len;                    // Set len
        I2C_ICSAR = i2caddr;                // Set I2C slave address
        I2C_ICMDR = ICMDR_STT               // Config for master write
                  | ICMDR_TRX
                  | ICMDR_MST
                  | ICMDR_IRS
                  | ICMDR_FREE
                  ;
 
        DAVINCIEVM_wait( 10 );              // Short delay
 
        for ( i = 0 ; i < len ; i++ )
        {
            I2C_ICDXR = data[i];            // Write
 
            timecount = 0;
            do
            {
                timecount++;
                if ( timecount >= timeout )
                {
                    DAVINCIEVM_I2C_reset( );
                    return 1000;
                }
            } while ( ( I2C_ICSTR & ICSTR_ICXRDY ) == 0 );// Wait for Tx Ready
        }
 
        I2C_ICMDR |= ICMDR_STP;             // Generate STOP
        return 0;
 
    #endif
}
 
/* ------------------------------------------------------------------------ *
 *                                                                          *
 *  DAVINCIEVM_I2C_read( i2caddr, data, len )                               *
 *                                                                          *
 *      I2C read in Master mode                                             *
 *                                                                          *
 *      i2caddr <- I2C slave address                                        *
 *      data    <- I2C data ptr                                             *
 *      len     <- # of bytes to write                                      *
 *                                                                          *
 * ------------------------------------------------------------------------ */
Int16 DAVINCIEVM_I2C_read( Uint16 i2caddr, Uint8* data, Uint16 len )
{
    Uint16 i;
    Int32 timeout   = 0x20000;
    Int32 timecount = 0;
 
    #ifdef ARM_SIDE
 
        Uint16 response;
 
        CSL_i2cHwControl( i2c_handle, CSL_I2C_CMD_SET_DATA_COUNT, &len );
        CSL_i2cHwControl( i2c_handle, CSL_I2C_CMD_SET_SLAVE_ADDR, &i2caddr );
        CSL_i2cHwControl( i2c_handle, CSL_I2C_CMD_DIR_RECEIVE, 0 );
        CSL_i2cHwControl( i2c_handle, CSL_I2C_CMD_START, 0 );
 
        DAVINCIEVM_wait( 10 );
 
        for ( i = 0 ; i < len ; i++ )
        {
            timecount = 0;
            do
            {
                CSL_i2cGetHwStatus( i2c_handle, CSL_I2C_QUERY_RX_RDY, &response );
 
                timecount++;
                if ( timecount >= timeout )
                {
                    DAVINCIEVM_I2C_reset( );
                    return 1000;
                }
 
            } while( response == 0 );
 
            CSL_i2cRead( i2c_handle, &data[i] );
        }
 
      //CSL_i2cHwControl( i2c_handle, CSL_I2C_CMD_STOP, 0 );
 
        return 0;
 
    #elif DSP_SIDE
 
        I2C_ICCNT = len;                    // Set len
        I2C_ICSAR = i2caddr;                // Set I2C slave address
        I2C_ICMDR = ICMDR_STT               // Config for master read
                  | ICMDR_MST
                  | ICMDR_IRS
                  | ICMDR_FREE
                  ;
 
        for ( i = 0 ; i < len ; i++ )
        {
            timecount = 0;
            do
            {
                timecount++;
                if ( timecount >= timeout )
                {
                    DAVINCIEVM_I2C_reset( );
                    return 1000;
                }
            } while ( ( I2C_ICSTR & ICSTR_ICRRDY ) == 0 );// Wait for Rx Ready
            data[i] = I2C_ICDRR;            // Read
        }
 
        I2C_ICMDR |= ICMDR_STP;             // Generate STOP
        return 0;
 
    #endif
}
 
/* ------------------------------------------------------------------------ *
 *                                                                          *
 *  DAVINCIEVM_I2C_read_variable( i2caddr, data, len )                      *
 *                                                                          *
 *      I2C read in Master mode                                             *
 *                                                                          *
 *      i2caddr <- I2C slave address                                        *
 *      data    <- I2C data ptr                                             *
 *      len     <- # of bytes to write                                      *
 *                                                                          *
 * ------------------------------------------------------------------------ */
Int16 DAVINCIEVM_I2C_read_variable( Uint16 i2caddr, Uint8* data, Uint16 len )
{
    Uint16 i;
    Int32 timeout   = 0x20000;
    Int32 timecount = 0;
 
    #ifdef ARM_SIDE
 
        Uint16 response;
 
        CSL_i2cHwControl( i2c_handle, CSL_I2C_CMD_SET_DATA_COUNT, &len );
        CSL_i2cHwControl( i2c_handle, CSL_I2C_CMD_SET_SLAVE_ADDR, &i2caddr );
        CSL_i2cHwControl( i2c_handle, CSL_I2C_CMD_DIR_RECEIVE, 0 );
        CSL_i2cHwControl( i2c_handle, CSL_I2C_CMD_START, 0 );
 
        DAVINCIEVM_wait( 10 );
 
        for ( i = 0 ; i < len ; i++ )
        {
            if ( i == 1 )
            {
                len = data[0];
                CSL_i2cHwControl( i2c_handle, CSL_I2C_CMD_SET_DATA_COUNT, &len );
            }
 
            timecount = 0;
            do
            {
                CSL_i2cGetHwStatus( i2c_handle, CSL_I2C_QUERY_RX_RDY, &response );
 
                timecount++;
                if ( timecount >= timeout )
                {
                    DAVINCIEVM_I2C_reset( );
                    return 1000;
                }
 
            } while( response == 0 );
 
            CSL_i2cRead( i2c_handle, &data[i] );
        }
 
      //CSL_i2cHwControl( i2c_handle, CSL_I2C_CMD_STOP, 0 );
 
        return 0;
 
    #elif DSP_SIDE
 
        I2C_ICCNT = len;                    // Set len
        I2C_ICSAR = i2caddr;                // Set I2C slave address
        I2C_ICMDR = ICMDR_STT               // Config for master read
                  | ICMDR_MST
                  | ICMDR_IRS
                  | ICMDR_FREE
                  ;
 
        for ( i = 0 ; i < len ; i++ )
        {
            if ( i == 1 )
            {
                len = data[0];
                I2C_ICCNT = len;            // Set len
            }
 
            timecount = 0;
            do
            {
                timecount++;
                if ( timecount >= timeout )
                {
                    DAVINCIEVM_I2C_reset( );
                    return 1000;
                }
            } while ( ( I2C_ICSTR & ICSTR_ICRRDY ) == 0 );// Wait for Rx Ready
            data[i] = I2C_ICDRR;            // Read
        }
 
        I2C_ICMDR |= ICMDR_STP;             // Generate STOP
        return 0;
 
    #endif
}
 
 
 
//////////////////////////////////////////////////////////////////////////////////////////////////////////
 
 
 
/*
 *  Copyright 2005 by Spectrum Digital Incorporated.
 *  All rights reserved. Property of Spectrum Digital Incorporated.
 *
 *  Not for distribution.
 */
 
/*
 *  I2C header file
 *
 */
 
#ifndef I2C_
#define I2C_
 
#include "davincievm.h"
 
#ifdef ARM_SIDE
 
    #include "csl_i2c.h"
    static CSL_I2cHandle i2c_handle;
    static CSL_I2cObj    i2c_obj;
 
#elif DSP_SIDE
 
#endif
 
/* ------------------------------------------------------------------------ *
 *                                                                          *
 *  I2C Prototypes                                                          *
 *                                                                          *
 * ------------------------------------------------------------------------ */
Int16 DAVINCIEVM_I2C_init ( );
Int16 DAVINCIEVM_I2C_close( );
Int16 DAVINCIEVM_I2C_write( Uint16 slaveaddr, Uint8* data, Uint16 len );
Int16 DAVINCIEVM_I2C_read ( Uint16 slaveaddr, Uint8* data, Uint16 len );
 
#endif
 
 
   
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//more I2C related header files are added in include  EX: csl_i2c.h etc.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

  • Hi Sanjay,

    Regarding SW support, refer to the below e2e post:

    e2e.ti.com/.../622094

    Regards,
    Pavel
  • Hi Pavel Botev,
    Can you answer with more clarity.
    Most of the emails mentioned in the link provided by you is having sales email ID.
    hope you have understood our current requirement.
    we are looking for Transmit and Receive S/w through I2C peripheral and also posted the s/w which I am using but the I2C data o/p waveform on the scope is not correct. Please suggest the modification required in the s/w posted.

    regards
    sanjay
  • Sanjay,

    For any detailed software support, please contact any of the select partners recommended below. They have extensive DM64x software expertise and systems experience.

    They are (alphabetical order):

    D3 Engineering (sales@d3engineering.com)

    eInfochips (ajat.dhawal@einfochips.com)

    Ittiam Systems (ids-mkt@ittiam.com)

    Path Partner Technology (sales@pathpartnertech.com)

    Z3 Technologies (sales@z3technology.com)

    Regards,
    Pavel
  • Hi,

    As the issue being faced is generic in nature related to standard I2C interface in TI ARM processors, and I am looking for a urgent soltion to my issue so kindly respond to the issue described below:

    I have to do Write and Read to PCA2129 using I2C peripheral of

    TMS320dm6446 configured as mater.  I am checking the data (including slave address) being transmitted out from I2C of

    TMS320DM6446 on Oscilloscope which is not matching with the actual data

    written in the code.

    The I2C code being used, Datasheet of

    PCA2129,  waveform captured on the scope and schematic of the module is attached for reference.

    Oscillator frequency used on

    our board is 27 Mhz (i/p to TMS320DM6446).

    Pls suggest what

    could be the issue ?

    Note- protocol of I2C required for PCA2129

    is mentioned on page -56 of the datasheet of PCA2129.

    please let us know if you need any more details.

    Request  to respond asap as we need to resolve the issue urgently.

    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    The code being used is as under:



    #include "stdio.h"
    #include "davincievm.h"
    #include "davincievm_uart.h"
    #include <csl_spi.h>
    #include <csl_spiAux.h>
    #include <davincievm_gpio.h>
     
    #include "stdlib.h"

    #include "davincievm.h"


    #include "string.h"

     
     
    void main( void )
    {
     
    Uint32 i;
    Uint32 jj;
     
    unsigned char add_regI2c=0,I2C_len=0,I2C_SLAddr, cntRD;
     
    DAVINCIEVM_GPIO_init();
     
     PINMUX0 &=0xffff7fE0;
     
     DAVINCIEVM_GPIO_setDirection(12, 0);
     DAVINCIEVM_GPIO_setOutput(12, 1);
     
        
     
       PINMUX1 &=0xffffff7f;
       PINMUX1 |=0x00000080;
       DAVINCIEVM_I2C_reset();
     
         add_regI2c=0x03;
         //I2C_len = 0x02;
         //I2C_SLAddr = 0xA2;
         while(1)
         {
          DAVINCIEVM_I2C_write(0xA2, &add_regI2c, 1);   //send slave address(0xA2, followed by one byte data i.e. the address of the second register(0x03H) of PCA2129
          
          DAVINCIEVM_I2C_read(0xA3, &RDsec, 0x01);     //read only one byte from the Second register(0x03H) of PCA2129  

     
         cntRD++;
         }
    }
     
    //Note: refer to the I2C protocol of PCA2129 on page 56 of the addaached data sheet of PCA2129
     
     
     
     
    //Following files are added as header/source/include
     
    ///////////////////////////////////////////////////////////////////////////////////////////////////////
    /*
     *  Copyright 2005 by Spectrum Digital Incorporated.
     *  All rights reserved. Property of Spectrum Digital Incorporated.
     *
     *  Not for distribution.
     */
     
    /*
     *  I2C implementation
     *
     */
     
    #include "davincievm_i2c.h"
     
    /* ------------------------------------------------------------------------ *
     *                                                                          *
     *  DAVINCIEVM_I2C_init( )                                                  *
     *                                                                          *
     *      Enable and initalize the I2C module                                 *
     *                                                                          *
     *      The I2C clk is set to run at 20 KHz                                 *
     *                                                                          *
     * ------------------------------------------------------------------------ */
    Int16 DAVINCIEVM_I2C_init( )
    {
        #ifdef ARM_SIDE
     
            CSL_Status status;
            CSL_I2cClkSetup i2c_clksetup;
            CSL_I2cHwSetup  i2c_hwsetup;
            CSL_I2cParam    i2c_param;
     
            CSL_i2cInit( 0 );
            i2c_handle = CSL_i2cOpen( &i2c_obj, 0, &i2c_param, &status );
     
            i2c_clksetup.prescalar      = 26;
            i2c_clksetup.clklowdiv      = 20;
            i2c_clksetup.clkhighdiv     = 20;
     
            i2c_hwsetup.mode            = 1;    // 0: Slave mode        1: Master mode
            i2c_hwsetup.dir             = 0;    // 0: Rx mode           1: Tx mode
            i2c_hwsetup.addrMode        = 0;    // 0: 7-bit mode        1: 10-bit mode//0
            i2c_hwsetup.sttbyteen       = 0;    // 0: Normal mode       1: Start byte mode //0
            i2c_hwsetup.ownaddr         = 1;    // #: Own address//0
            i2c_hwsetup.ackMode         = 0;    // 0: ACK mode          1: NACK mode
            i2c_hwsetup.runMode         = 0;    // 0: No Free run mode  1: Free run mode//1
            i2c_hwsetup.repeatMode      = 0;    // 0: No repeat mode    1: Repeat mode
            i2c_hwsetup.loopBackMode    = 0;    // 0: No loopback       1: Loopback mode//0
            i2c_hwsetup.freeDataFormat  = 0;    // 0: No Free data fmt  1: Free data fmt
            i2c_hwsetup.resetMode       = 1;    // 0: Reset             1: Out of reset//0
            i2c_hwsetup.bcm             = 0;    // 0: Not compatible    1: Compatible
            i2c_hwsetup.inten           = 0;    // #: Intr enable mask
            i2c_hwsetup.clksetup        = &i2c_clksetup;
     
            status = CSL_i2cHwSetup( i2c_handle, &i2c_hwsetup );
     
            CSL_i2cHwControl( i2c_handle, CSL_I2C_CMD_OUTOFRESET, 0 );
            return 0;
     
        #elif DSP_SIDE
     
            I2C_ICMDR   = 0;                    // Reset I2C
            I2C_ICPSC   = 26;                   // Config prescaler for 27MHz
            I2C_ICCLKL  = 5;                    // Config clk LOW for 50kHz
            I2C_ICCLKH  = 5;                    // Config clk HIGH for 50kHz
            I2C_ICMDR  |= ICMDR_IRS;            // Release I2C from reset
            return 0;
     
        #endif
    }
     
    /* ------------------------------------------------------------------------ *
     *                                                                          *
     *  DAVINCIEVM_I2C_close( )                                                 *
     *                                                                          *
     * ------------------------------------------------------------------------ */
    Int16 DAVINCIEVM_I2C_close( )
    {
        #ifdef ARM_SIDE
     
            CSL_i2cHwControl( i2c_handle, CSL_I2C_CMD_RESET, 0 );
            CSL_i2cClose( i2c_handle );
            return 0;
     
        #elif DSP_SIDE
     
            I2C_ICMDR = 0;                      // Reset I2C
            return 0;
     
        #endif
    }
     
    /* ------------------------------------------------------------------------ *
     *                                                                          *
     *  DAVINCIEVM_I2C_reset( )                                                 *
     *                                                                          *
     *                                                                          *
     *                                                                          *
     * ------------------------------------------------------------------------ */
    Int16 DAVINCIEVM_I2C_reset( )
    {
        DAVINCIEVM_I2C_close( );
        DAVINCIEVM_I2C_init( );
        return 0;
    }
     
    /* ------------------------------------------------------------------------ *
     *                                                                          *
     *  DAVINCIEVM_I2C_write( i2caddr, data, len )                              *
     *                                                                          *
     *      I2C write in Master mode                                            *
     *                                                                          *
     *      i2caddr <- I2C slave address                                        *
     *      data    <- I2C data ptr                                             *
     *      len     <- # of bytes to write                                      *
     *                                                                          *
     * ------------------------------------------------------------------------ */
    Int16 DAVINCIEVM_I2C_write( Uint16 i2caddr, Uint8* data, Uint16 len )
    {
        Uint16 i;
        Int32 timeout   = 0x20000;
        Int32 timecount = 0;
     
        #ifdef ARM_SIDE
     
            Uint16 response;
     
            CSL_i2cHwControl( i2c_handle, CSL_I2C_CMD_SET_DATA_COUNT, &len );
            CSL_i2cHwControl( i2c_handle, CSL_I2C_CMD_SET_SLAVE_ADDR, &i2caddr );
            CSL_i2cHwControl( i2c_handle, CSL_I2C_CMD_DIR_TRANSMIT, 0 );
            CSL_i2cHwControl( i2c_handle, CSL_I2C_CMD_START, 0 );
     
            DAVINCIEVM_wait( 10 );
     
            for ( i = 0 ; i < len ; i++ )
            {
                CSL_i2cWrite( i2c_handle, &data[i] );
     
                timecount = 0;
                do
                {
                    CSL_i2cGetHwStatus( i2c_handle, CSL_I2C_QUERY_TX_RDY, &response );
     
                    timecount++;
                    if ( timecount >= timeout )
                    {
                        DAVINCIEVM_I2C_reset( );
                        return 1000;
                    }
     
                } while( response == 0 );
            }
     
          //CSL_i2cHwControl( i2c_handle, CSL_I2C_CMD_STOP, 0 );
     
            return 0;
     
        #elif DSP_SIDE
     
            I2C_ICCNT = len;                    // Set len
            I2C_ICSAR = i2caddr;                // Set I2C slave address
            I2C_ICMDR = ICMDR_STT               // Config for master write
                      | ICMDR_TRX
                      | ICMDR_MST
                      | ICMDR_IRS
                      | ICMDR_FREE
                      ;
     
            DAVINCIEVM_wait( 10 );              // Short delay
     
            for ( i = 0 ; i < len ; i++ )
            {
                I2C_ICDXR = data[i];            // Write
     
                timecount = 0;
                do
                {
                    timecount++;
                    if ( timecount >= timeout )
                    {
                        DAVINCIEVM_I2C_reset( );
                        return 1000;
                    }
                } while ( ( I2C_ICSTR & ICSTR_ICXRDY ) == 0 );// Wait for Tx Ready
            }
     
            I2C_ICMDR |= ICMDR_STP;             // Generate STOP
            return 0;
     
        #endif
    }
     
    /* ------------------------------------------------------------------------ *
     *                                                                          *
     *  DAVINCIEVM_I2C_read( i2caddr, data, len )                               *
     *                                                                          *
     *      I2C read in Master mode                                             *
     *                                                                          *
     *      i2caddr <- I2C slave address                                        *
     *      data    <- I2C data ptr                                             *
     *      len     <- # of bytes to write                                      *
     *                                                                          *
     * ------------------------------------------------------------------------ */
    Int16 DAVINCIEVM_I2C_read( Uint16 i2caddr, Uint8* data, Uint16 len )
    {
        Uint16 i;
        Int32 timeout   = 0x20000;
        Int32 timecount = 0;
     
        #ifdef ARM_SIDE
     
            Uint16 response;
     
            CSL_i2cHwControl( i2c_handle, CSL_I2C_CMD_SET_DATA_COUNT, &len );
            CSL_i2cHwControl( i2c_handle, CSL_I2C_CMD_SET_SLAVE_ADDR, &i2caddr );
            CSL_i2cHwControl( i2c_handle, CSL_I2C_CMD_DIR_RECEIVE, 0 );
            CSL_i2cHwControl( i2c_handle, CSL_I2C_CMD_START, 0 );
     
            DAVINCIEVM_wait( 10 );
     
            for ( i = 0 ; i < len ; i++ )
            {
                timecount = 0;
                do
                {
                    CSL_i2cGetHwStatus( i2c_handle, CSL_I2C_QUERY_RX_RDY, &response );
     
                    timecount++;
                    if ( timecount >= timeout )
                    {
                        DAVINCIEVM_I2C_reset( );
                        return 1000;
                    }
     
                } while( response == 0 );
     
                CSL_i2cRead( i2c_handle, &data[i] );
            }
     
          //CSL_i2cHwControl( i2c_handle, CSL_I2C_CMD_STOP, 0 );
     
            return 0;
     
        #elif DSP_SIDE
     
            I2C_ICCNT = len;                    // Set len
            I2C_ICSAR = i2caddr;                // Set I2C slave address
            I2C_ICMDR = ICMDR_STT               // Config for master read
                      | ICMDR_MST
                      | ICMDR_IRS
                      | ICMDR_FREE
                      ;
     
            for ( i = 0 ; i < len ; i++ )
            {
                timecount = 0;
                do
                {
                    timecount++;
                    if ( timecount >= timeout )
                    {
                        DAVINCIEVM_I2C_reset( );
                        return 1000;
                    }
                } while ( ( I2C_ICSTR & ICSTR_ICRRDY ) == 0 );// Wait for Rx Ready
                data[i] = I2C_ICDRR;            // Read
            }
     
            I2C_ICMDR |= ICMDR_STP;             // Generate STOP
            return 0;
     
        #endif
    }
     
    /* ------------------------------------------------------------------------ *
     *                                                                          *
     *  DAVINCIEVM_I2C_read_variable( i2caddr, data, len )                      *
     *                                                                          *
     *      I2C read in Master mode                                             *
     *                                                                          *
     *      i2caddr <- I2C slave address                                        *
     *      data    <- I2C data ptr                                             *
     *      len     <- # of bytes to write                                      *
     *                                                                          *
     * ------------------------------------------------------------------------ */
    Int16 DAVINCIEVM_I2C_read_variable( Uint16 i2caddr, Uint8* data, Uint16 len )
    {
        Uint16 i;
        Int32 timeout   = 0x20000;
        Int32 timecount = 0;
     
        #ifdef ARM_SIDE
     
            Uint16 response;
     
            CSL_i2cHwControl( i2c_handle, CSL_I2C_CMD_SET_DATA_COUNT, &len );
            CSL_i2cHwControl( i2c_handle, CSL_I2C_CMD_SET_SLAVE_ADDR, &i2caddr );
            CSL_i2cHwControl( i2c_handle, CSL_I2C_CMD_DIR_RECEIVE, 0 );
            CSL_i2cHwControl( i2c_handle, CSL_I2C_CMD_START, 0 );
     
            DAVINCIEVM_wait( 10 );
     
            for ( i = 0 ; i < len ; i++ )
            {
                if ( i == 1 )
                {
                    len = data[0];
                    CSL_i2cHwControl( i2c_handle, CSL_I2C_CMD_SET_DATA_COUNT, &len );
                }
     
                timecount = 0;
                do
                {
                    CSL_i2cGetHwStatus( i2c_handle, CSL_I2C_QUERY_RX_RDY, &response );
     
                    timecount++;
                    if ( timecount >= timeout )
                    {
                        DAVINCIEVM_I2C_reset( );
                        return 1000;
                    }
     
                } while( response == 0 );
     
                CSL_i2cRead( i2c_handle, &data[i] );
            }
     
          //CSL_i2cHwControl( i2c_handle, CSL_I2C_CMD_STOP, 0 );
     
            return 0;
     
        #elif DSP_SIDE
     
            I2C_ICCNT = len;                    // Set len
            I2C_ICSAR = i2caddr;                // Set I2C slave address
            I2C_ICMDR = ICMDR_STT               // Config for master read
                      | ICMDR_MST
                      | ICMDR_IRS
                      | ICMDR_FREE
                      ;
     
            for ( i = 0 ; i < len ; i++ )
            {
                if ( i == 1 )
                {
                    len = data[0];
                    I2C_ICCNT = len;            // Set len
                }
     
                timecount = 0;
                do
                {
                    timecount++;
                    if ( timecount >= timeout )
                    {
                        DAVINCIEVM_I2C_reset( );
                        return 1000;
                    }
                } while ( ( I2C_ICSTR & ICSTR_ICRRDY ) == 0 );// Wait for Rx Ready
                data[i] = I2C_ICDRR;            // Read
            }
     
            I2C_ICMDR |= ICMDR_STP;             // Generate STOP
            return 0;
     
        #endif
    }
     
     
     
    //////////////////////////////////////////////////////////////////////////////////////////////////////////
     
     
     
    /*
     *  Copyright 2005 by Spectrum Digital Incorporated.
     *  All rights reserved. Property of Spectrum Digital Incorporated.
     *
     *  Not for distribution.
     */
     
    /*
     *  I2C header file
     *
     */
     
    #ifndef I2C_
    #define I2C_
     
    #include "davincievm.h"
     
    #ifdef ARM_SIDE
     
        #include "csl_i2c.h"
        static CSL_I2cHandle i2c_handle;
        static CSL_I2cObj    i2c_obj;
     
    #elif DSP_SIDE
     
    #endif
     
    /* ------------------------------------------------------------------------ *
     *                                                                          *
     *  I2C Prototypes                                                          *
     *                                                                          *
     * ------------------------------------------------------------------------ */
    Int16 DAVINCIEVM_I2C_init ( );
    Int16 DAVINCIEVM_I2C_close( );
    Int16 DAVINCIEVM_I2C_write( Uint16 slaveaddr, Uint8* data, Uint16 len );
    Int16 DAVINCIEVM_I2C_read ( Uint16 slaveaddr, Uint8* data, Uint16 len );
     
    #endif
     
     
       
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //more I2C related header files are added in include  EX: csl_i2c.h etc.

    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    waveform with only write function enabled in the code is as under: (slave address 0xA2  and data 0x03 is not matching ! )

    waveform with only Read function enabled in the code is as under: (slave address 0xA2  and data 0x03 is not matching ! )

    // Schematic under use:

    Pull up on the data and clk line is 0.9K  and VCC=1.8 V.

    Kindly suggest asap.

      

    Regards

    Sanjay Kumar Singh
    Manager.
    Crypto & Datacom, C-D&E,
    Bharat Electronics Ltd.
    Bangalore-560013.
    PH: +91-80-22195844

  • Hi Pavel, still I have not got any response from the links provided by you.

    kindly request to answer the generic queries for the I2C as under:

    add_regI2c[0]=0x0F;

    add_regI2c[1]=0x06;

    DAVINCIEVM_I2C_write(0x51, &add_regI2c[0], 0x02);

    The above instruction doesn't issue a valid STOP waveform !!!

    Kindly let us know what could be the reason for the Davinci ARM not

    issuing a proper STOP ?