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.

TMS320C6657: I2C Test. Examples and firmware development general cuestions.

Part Number: TMS320C6657
Other Parts Discussed in Thread: TMDSEVM6657, , SYSBIOS

Dear Sirs,
I need some aclarations regarding CCS, examples and firmware development. Maybe my questions are simple and basic, but could help to other people.
My experience on this field is limited and I have a lot of confussion on this.
We have bought TMDSEVM6657 evaluation board for TMS320C6657.
I am tryng to create my own test for I2C on the eeprom of the board. Once I understand how it works I will try to use the I2C bus
to control other external I2C chips on a custom board plug on the 80 pins expansion conector of the evaluation board.
I have installed CCS 9.3.0 and processor_sdk_rtos_c665x_6_03_106. I have generated the PDk examples. I am able to run "platform_test_evmc6657l" project successfully.

(1)
I have imported to my workspace the example "I2C_BasicExample_C6657_Evm_c66xExampleProject".
This example has the main file "main_eeprom_read.c"
From my other experience on C development, the code start to execute on the main function. In this example,
the main is:
********
int main(void)
{
    if (Board_initI2C() == false)
    {
        return (0);
    }

    /* Start BIOS */
    BIOS_start();
    return (0);
}

*****

Revising the code, it seems that the test in this example is executed on the function "void i2c_test(UArg arg0, UArg arg1)".
I am tryng to find BIOS_start() function to see how this function call to "i2c_test" but I was not able to find it. Please could
you tell me where I can find it? Does Bios_start() call i2c_test()?  or How it works?

(2) in my tests, I have change some code of this project but I would like to keep a copy of original project.
I have delete the project from CCS and inport again the examples to have the original project but without success: changes still are there.
What is the best method to keep a original copy of the project and have my own projec to make changes and tests?

(3) to test the eeprom by my own project,  I am thinking on something like this:
*********

#define I2C_ADDR         0x0300           // Read and write test start address for Cerro project
#define I2C_SIZE_TEST        10

/*
 *  ======== test function Cerro========
 *  Write 10 bytes on eeprom position 0x0300 and then read those bytes
 *
/*
void i2c_own_test(UArg arg0, UArg arg1)
{

    UART_printf("\n first line of my test program\n");//write this sentece on serial port, connector USB1, a 115200.
    I2C_Params i2cParams;
    I2C_Handle handle = NULL;
    I2C_Transaction i2cTransaction;
    char txBuf_cerro[10] = {0x0f,0x1f,0x2f,0x3f,0x4f,0x5f,0x6f,0x7f,0x8f,0x9f};//ten data to be written
    char rxBuf_cerro[10] = {0x00, };//buffer to read the data
    bool status,test_pass=FALSE;
    int16_t transferStatus;

    // Set the I2C EEPROM write/read address
    txBuf_cerro[0] = (I2C_ADDR >> 8) & 0xff; // EEPROM memory high address byte
    txBuf_cerro[1] = I2C_ADDR & 0xff;        // EEPROM memory low address byte

    I2C_init();
    I2C_Params_init(&i2cParams);

    handle = I2C_open(I2C_EEPROM_INSTANCE, &i2cParams);

    I2C_transactionInit(&i2cTransaction);

    i2cTransaction.slaveAddress = I2C_EEPROM_ADDR;
    i2cTransaction.writeBuf = (uint8_t *)&txBuf_cerro[0];
    i2cTransaction.writeCount = I2C_SIZE_TEST;
    i2cTransaction.readBuf = (uint8_t *)&rxBuf_cerro[0];
    i2cTransaction.readCount = I2C_SIZE_TEST;
    i2cTransaction.timeout   = I2C_TRANSACTION_TIMEOUT;

    transferStatus = I2C_transfer(handle, &i2cTransaction);


    if(I2C_STS_SUCCESS != transferStatus)
       {
           I2C_log("\n Data Transfer failed with transfer status %d \n",transferStatus);
           test_pass=FALSE;
       }

    else {
        I2C_log("\n Write and read successes %d \n",transferStatus);
        UART_printf("\n Write and read successes\n");
    }

    I2C_close(handle);
 }
**********************


I would check if the test is correct on the "Variables" window for comparing the transmit and received buffers or maybe printing the buffers on the screen to compare.
How/where should I add the previous code on the project?

Could I use this code to write/read to other I2C devices just changing the slaveadress and data to be transmitted?

If I had to change the "speed" or other I2c parameters, where is the place to do it?

Thanks in advance,
Joaquin.

  • Joaquin,

    Thanks for your detailed questions.

    1. If you are looking for I2C basic example code - that is a bare metal code - without BIOS_start(), you can utilize the CSL I2C example.

    It is located at "C:\ti\pdk_c665x_2_0_16\packages\ti\csl\example\i2c\i2c_led_blink".

    /*
     *  Copyright (C) 2013-2017 Texas Instruments Incorporated - http://www.ti.com/
     *
     *  Redistribution and use in source and binary forms, with or without
     *  modification, are permitted provided that the following conditions
     *  are met:
     *
     *    Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     *    Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the
     *    distribution.
     *
     *    Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     *
     */
     /**
     *  \file   main.c
     *
     *  \brief This file demonstrates I2C dal by writing data to blink
     *         LED on and off.
     *
     */
    
    /* ========================================================================== */
    /*                             Include Files                                  */
    /* ========================================================================== */
    #include <stdint.h>
    #include <stdio.h>
    #include <ti/csl/csl_i2c.h>
    #include <ti/csl/soc.h>
    
    /* ========================================================================== */
    /*                           Macros & Typedefs                                */
    /* ========================================================================== */
    
    #if defined (SOC_TDA3XX) || defined (SOC_DRA78x)
    /* I2C address of TCA6424 expander - 2. */
    #define HSI2C_SLAVE_ADDR            ((uint8_t) 0x22U)
    #elif defined (SOC_J721E)
    /* I2C address of TCA6424 expander - 1. */
    #define HSI2C_SLAVE_ADDR            ((uint8_t) 0x21U)
    #elif defined (SOC_AM574x) || defined (SOC_AM572x) || defined (SOC_AM571x)
    /* I2C address of TPIC2810  */
    #define HSI2C_SLAVE_ADDR            ((uint8_t) 0x60U)
    #else
    /* I2C address of PCF8575 expander. */
    #define HSI2C_SLAVE_ADDR            ((uint8_t) 0x20U)
    #endif
    
    /* Turn on the LEDs. */
    #define HSI2C_EXP_PORT0_LED_ON      ((uint8_t) 0x00U)
    
    /* Turn off the LEDs. */
    #define HSI2C_EXP_PORT0_LED_OFF     ((uint8_t) 0xFFU)
    
    /* Number of times led toggles. */
    #define HSI2C_LED_TOGGLE_NO         (10U)
    
    /* Led toggle check value*/
    #define HSI2C_LED_TOGGLE_END        (0U)
    
    /* Transfer Size */
    #define HSI2C_TRANSFER_SIZE         (5U)
    
    #if defined (SOC_TDA3XX) || defined (SOC_DRA78x) || defined (SOC_J721E)
    #define TCA6424_CMD_AUTO_INC            ((uint8_t) 0x80U)
    
    /* Output register to change state of output BIT set to 1, output set HIGH */
    #define TCA6424_REG_OUTPUT0             ((uint8_t) 0x04U)
    #define TCA6424_REG_OUTPUT1             ((uint8_t) 0x05U)
    #define TCA6424_REG_OUTPUT2             ((uint8_t) 0x06U)
    
    /* Configuration register. BIT = '1' sets port to input, BIT = '0' sets
     * port to output */
    #define TCA6424_REG_CONFIG0             ((uint8_t) 0x0CU)
    #define TCA6424_REG_CONFIG1             ((uint8_t) 0x0DU)
    #define TCA6424_REG_CONFIG2             ((uint8_t) 0x0EU)
    
    #endif
    
    /* ===========================================================================*/
    /*                          Global Variables                                  */
    /* ===========================================================================*/
    uint8_t dataToSlave[HSI2C_TRANSFER_SIZE];
    
    #if defined (SOC_J721E)
    uint32_t gI2cAddr = CSL_I2C0_CFG_BASE;
    #else
    uint32_t gI2cAddr = SOC_I2C1_BASE;
    #endif
    
    /* ========================================================================== */
    /*                          Function Declarations                             */
    /* ========================================================================== */
    void SetupI2C(void);
    void sampleDelay(int32_t delay);
    void SetupI2CTransmit(uint8_t *data, uint32_t numBytes);
    static void ioexpDataWrite(uint8_t *data);
    static void initialize_ioexp(void);
    
    /* ========================================================================== */
    /*                          Function Definitions                              */
    /* ========================================================================== */
    int main()
    {
        volatile uint8_t done = 1;
        uint8_t          data;
        /*
        ** Configures I2C to Master mode to generate start codition
        ** on I2C bus and to transmit data at a bus speed of  100khz
        */
    
        uint32_t         num;
    
        SetupI2C();
    
        initialize_ioexp();
    
        for (num = HSI2C_LED_TOGGLE_NO; num != HSI2C_LED_TOGGLE_END; num--)
        {
            data = HSI2C_EXP_PORT0_LED_ON;
            /*
             * **Transmits command byte and data to I/0 expander
             * **through I2C bus
             */
            ioexpDataWrite(&data);
            sampleDelay(0xFFFF);
    
            data = HSI2C_EXP_PORT0_LED_OFF; /*data to OFF LED*/
            ioexpDataWrite(&data);
            sampleDelay(0xFFFF);
        }
    
        while (done) ;
    
        return 0;
    }
    
    static void initialize_ioexp(void)
    {
    #if defined (SOC_TDA3XX) || defined (SOC_DRA78x) || defined (SOC_J721E)
        /* TCA6424 ioexpander pins should be configure as output
         * In config register write 1 for input, 0 for output */
        dataToSlave[0] = TCA6424_REG_CONFIG0 | TCA6424_CMD_AUTO_INC;
        dataToSlave[1] = 0x0U;
        SetupI2CTransmit(&dataToSlave[0], 2);
    #endif
    }
    
    #if defined (SOC_TDA3XX) || defined (SOC_DRA78x)
    /* On tda3xx leds are connected on TCA6424 ioexpander - 2
     * LEDs are connected on port 0 first 4 bits, and ioexpander has 3 ports */
    static void ioexpDataWrite(uint8_t *data)
    {
        dataToSlave[0] = TCA6424_REG_OUTPUT0 | (uint32_t) TCA6424_CMD_AUTO_INC;
        dataToSlave[1] = ((*data) & 0x0FU);
        dataToSlave[2] = 0U;
        dataToSlave[3] = 0U;
        SetupI2CTransmit(&dataToSlave[0], 4);
    }
    #elif defined (SOC_J721E)
    /* On j721e leds are connected on TCA6424 ioexpander - 1
     * LEDs are connected on port 2 last 2 bits, and ioexpander has 3 ports */
    static void ioexpDataWrite(uint8_t *data)
    {
        dataToSlave[0] = TCA6424_REG_OUTPUT0 | (uint32_t) TCA6424_CMD_AUTO_INC;
        dataToSlave[1] = 0U;
        dataToSlave[2] = 0U;
        dataToSlave[3] = ((*data) & 0xC0U);
        SetupI2CTransmit(&dataToSlave[0], 4);
    }
    #elif defined (SOC_AM574x) || defined (SOC_AM572x) || defined (SOC_AM571x)
    /* On idkam572x leds are connected on TPCI2810 need to write a subaddress */
    static void ioexpDataWrite(uint8_t *data)
    {
        dataToSlave[0] = 0x11U;
        dataToSlave[1] = *data;
        SetupI2CTransmit(&dataToSlave[0], 2);
        dataToSlave[0] = 0x22U;
        SetupI2CTransmit(&dataToSlave[0], 1);
    }
    #else
    /* On tda2xx and ti814x leds are connected on PCF8575 ioexpander
     * LEDs are connected on port 0 last 4 bits, and ioexpander has 2 ports */
    static void ioexpDataWrite(uint8_t *data)
    {
        dataToSlave[0] = (((*data) << 4U) & 0xF0U);
        dataToSlave[1] = 0U;
        SetupI2CTransmit(&dataToSlave[0], 2);
    }
    
    #endif
    
    void SetupI2C(void)
    {
        /* Do a software reset */
        I2CSoftReset(gI2cAddr);
    
        /* Enable i2c module */
        I2CMasterEnable(gI2cAddr);
    
        while (!I2CSystemStatusGet(gI2cAddr)) ;
    
        /* Put i2c in reset/disabled state */
        I2CMasterDisable(gI2cAddr);
    
        /* Configure i2c bus speed to 100khz */
    #if defined (SOC_AM574x) || defined (SOC_AM572x) || defined (SOC_AM571x)
        I2CMasterInitExpClk(gI2cAddr, 96000000,
                            4000000U, 100000);
    #else
        I2CMasterInitExpClk(gI2cAddr, 24000000,
                            8000000, 100000);
    #endif
    
        I2COwnAddressSet(gI2cAddr, 0,
                         I2C_OWN_ADDR_0);
    
        I2CSyscInit(gI2cAddr, 0x08);
    
        /*Set Rx and Tx FIFO threshold value and reset the fifo*/
        I2CFIFOThresholdConfig(gI2cAddr, 0, I2C_TX_MODE);
    
        I2CFIFOThresholdConfig(gI2cAddr, 0, I2C_RX_MODE);
    
        /* Set i2c slave address */
        I2CMasterSlaveAddrSet(gI2cAddr, HSI2C_SLAVE_ADDR);
        
        /* Bring i2c out of reset */
        I2CMasterEnable(gI2cAddr);
    
        /* Enable free run mode */
        I2CMasterEnableFreeRun(gI2cAddr);
    }
    
    void SetupI2CTransmit(uint8_t *data, uint32_t numBytes)
    {
        uint32_t i;
        
        I2CFIFOClear(gI2cAddr, I2C_TX_MODE);
        I2CFIFOClear(gI2cAddr, I2C_RX_MODE);
    
        /*Clear all interrupt status*/
        I2CMasterIntClearEx(gI2cAddr, I2C_INT_ALL);
        
        /* Set data count */
        I2CSetDataCount(gI2cAddr, numBytes);
    
        /*
        ** Configure i2c as master-transmitter and to generate stop condition
        */
        I2CMasterControl(gI2cAddr, I2C_CFG_MST_TX);
        
        /* generate start */
        I2CMasterStart(gI2cAddr);
    
        /* wait for bus busy */
        while(I2CMasterBusBusy(gI2cAddr)==0)
        {
        }
    
        for (i = 0; i < numBytes; i++)
        {
            /*Wait for transmit interrupt to occur*/
            while (I2CMasterIntRawStatusEx(gI2cAddr,
                                           I2C_INT_TRANSMIT_READY) != 0x10) ;
    
            /* Send the data */
            I2CMasterDataPut(gI2cAddr, data[i]);
    
            /*Disable transmit ready and stop condition interrupt*/
            I2CMasterIntClearEx(gI2cAddr, I2C_INT_TRANSMIT_READY);
        }
        
        /* generate stop when requested */
        I2CMasterStop(gI2cAddr);
    
        sampleDelay(5000);
    
        /*Clear data buffer length*/
        I2CSetDataCount(gI2cAddr, 0);
    }
    
    void sampleDelay(int32_t delay)
    {
        volatile int32_t i, j;
    
        for (i = 0; i < delay; i++)
        {
            for (j = 0; j < 100; j++) ;
        }
    }
    /********************************* End of file ******************************/
    
    

    Question No: 2:

    Answer: 

    1. You can either create another workspace and import the same project and modify for your own development.

    In this way, you can refer the existing code as well as your own code.

    2. Zip the original code and safe it as a copy. Modify the unzipped one and keep using it. Whenever you want to revert, you can do so.

    3. There are other software management tools like SVN, code colloborator etc to maintain the software version changes for maintaining the revision for reverting the older versions as needed.

    Regards

    Shankari G

  • Hello Shankari,

    Thank you very much for your reply.

    (1) Regarding point 1 of my first e-mail, Is there any documentation where I can learn the basic of BIOS_start()?

    (2) OK, I am tryng to create a Bare metal core to test the I2C example you have given me, and for that, in CCS, File>New CCS project> Basic Examples> Hello world...then I "Build" and I get 11 warnings (see picture attached). If I try to run the project, it does not work. Please, How can I correct those warning? I have been looking for the solution in the forums but I didnt find a good answer to it.

    My idea is, once I have a very simple project running, copy the I2C example in the hello.c and then test it.

    Thanks in advance,

    Joaquin.

  • Hello again,

    One more detail I forget to tell you before, is there any way to build this project so I can import it? I only have the "main.c" in "C:\ti\pdk_c665x_2_0_16\packages\ti\csl\example\i2c\i2c_led_blink".

    Thanks,

    Joaquin

  • Joaquin,

    Question 1  ---  (1) Regarding point 1 of my first e-mail, Is there any documentation where I can learn the basic of BIOS_start()?

    Answer:

    Yes, BIOS user guide is available. Download here : - Bios_User_Guide.pdf

    Alternately, after you install processor_sdk_rtos_c665x_6_03_00_106, you will find more docs about BIOS located at "C:\ti\bios_6_76_03_01"

    ----

    Question 2

    Creating a ccs project using the CSL example of I2c.

    Answer: 

    Let me create for you and get back.

    Regards

    Shankari G

  • Joaquin,

    When I tried creating a CCS project for the sample CSL I2C example for C6657, I realized that the code is made only for the following devices such as 

    SOC_TDA3XX, SOC_DRA78x, SOC_J721E, SOC_AM574x, SOC_AM572x, SOC_AM571x

    and not for SOC_C6657. There seems to be a porting effort for C6657.

    The PDK package is a common bundle for many devices. And, hence, the example source given under the CSL/example/ are for other devices.

    ----

    The only existing option for I2C for C6657 is ----- "C:\ti\pdk_c665x_2_0_16\packages\MyExampleProjects\I2C_BasicExample_C6657_Evm_c66xTestProject"

    along with the SYSBIOS code.

    ---

    I am able to build the I2C_BasicExample_C6657_Evm_c66xTestProject in CCS and able to run on the C6657 board successfully. 

    It is able to read and write the EEPROM memory. Were you able to run this I2C_BasicExample_C6657_Evm_c66xTestProject  on the C6657 board?

    ---

    were you able to look at the BIOS user guide ? which i sent in my previous post? (  Download here : - Bios_User_Guide.pdf )

    Regards

    Shankari G

  • Hello Shankari,

    Thank you very much for your support.

    I understand the about the CSL examples. No problem. I am able to run I2C_BasicExample_C6657_Evm_c66xTestProject and modified it to test two other devices in the bus in a external board plug in the evaluation board. So no problem on this, It works.

    I have look at the BIOS manual but it is too far away of my competencies. For the moment, I only need test the hardware, so with the basic examples is enought.

    My next step is to test UPP. Can you recommend me where/how to start?  As it is different subjet of this post, if you prefer, I can open a new one.

    Regards,

    Joaquin.

  • Joaquin,

    Glad to hear that you were able to make it with the I2C_BasicExample_C6657_Evm_c66xTestProject  itself.

    : -)

    Already you opened a new thread for UPP, I guess. It is better to be new thread.

    Regards

    Shankari G