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.

cc2650 i2c, rxBuf issue

Other Parts Discussed in Thread: LMP91000, CC2650, SYSBIOS

Hi,

I am connecting the LMP91000 to the cc2650 via i2c. When I use the i2c_transfer fucntion the data does not get transfered to the rxBuf array. The value shows to be the '.' character. What is it that I am doing wrong here? Isnt the received data supposed to go to the ruxBuf?

Thanks,

Mustahsin

Code:

/* XDCtools Header files */

#include <xdc/std.h>

#include <xdc/runtime/System.h>

#include <ti/drivers/I2C.h>

#include <ti/drivers/i2c/I2CCC26XX.h>

/* BIOS Header files */

#include <ti/sysbios/BIOS.h>

#include <ti/sysbios/knl/Task.h>

/* TI-RTOS Header files */

// #include <ti/drivers/I2C.h>

#include <ti/drivers/PIN.h>

// #include <ti/drivers/SPI.h>

// #include <ti/drivers/UART.h>

// #include <ti/drivers/Watchdog.h>

/* Board Header files */

#include "Board.h"

#define TASKSTACKSIZE   512

Task_Struct task0Struct;

Char task0Stack[TASKSTACKSIZE];

/* Pin driver handle */

static PIN_Handle ledPinHandle;

static PIN_State ledPinState;

/*

 * Application LED pin configuration table:

 *   - All LEDs board LEDs are off.

 */

PIN_Config ledPinTable[] = {

    Board_LED0 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,

    Board_LED1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,

    PIN_TERMINATE

};

/*

 *  ======== heartBeatFxn ========

 *  Toggle the Board_LED0. The Task_sleep is determined by arg0 which

 *  is configured for the heartBeat Task instance.

 */

Void heartBeatFxn(UArg arg0, UArg arg1)

{

    while (1) {

        Task_sleep((UInt)arg0);

        I2C_Handle handle;

                       I2C_Params i2cParams;

                       I2C_Transaction i2cTrans;

                       uint8_t rxBuf[1];      // Receive buffer

                       uint8_t txBuf[0];      // Transmit buffer

                       // Configure I2C parameters.

                    // I2C_Params.I2C_TransferMode=I2C_MODE_CALLBACK;

                       I2C_Params_init(&i2cParams);

                       // Initialize master I2C transaction structure

                       I2CCC26XX_I2CPinCfg pinCfg;

                       pinCfg.pinSDA = Board_I2C0_SDA0;

                       pinCfg.pinSCL = Board_I2C0_SCL0;

                     //  i2cParams.custom = &pinCfg;

                       handle = I2C_open(Board_I2C, &i2cParams);

                       I2C_open(Board_I2C, &i2cParams);//

                     i2cTrans.writeCount   = 0;

                       i2cTrans.writeBuf     = txBuf;

                       i2cTrans.readCount    = 1;

                       i2cTrans.readBuf      = rxBuf;

                       i2cTrans.slaveAddress = 0x48;

                       I2C_transfer(handle, &i2cTrans);//

                         //  uint8_t a ;

                     I2C_close(handle);//    I2C_init();

                       Task_sleep((UInt)1000);

    }

}

/*

 *  ======== main ========

 */

int main(void)

{

    Task_Params taskParams;

    /* Call board init functions */

    Board_initGeneral();

    // Board_initI2C();

    // Board_initSPI();

    // Board_initUART();

    // Board_initWatchdog();

    /* Construct heartBeat Task  thread */

    Task_Params_init(&taskParams);

    taskParams.arg0 = 1000;

    taskParams.stackSize = TASKSTACKSIZE;

    taskParams.stack = &task0Stack;

    Task_construct(&task0Struct, (Task_FuncPtr)heartBeatFxn, &taskParams, NULL);

    /* Open LED pins */

    ledPinHandle = PIN_open(&ledPinState, ledPinTable);

    if(!ledPinHandle) {

        System_abort("Error initializing board LED pins\n");

    }

    PIN_setOutputValue(ledPinHandle, Board_LED1, 1);

    /* Start BIOS */

    BIOS_start();

    return (0);

}

screenshot of i2c0 data register

/* XDCtools Header files */#include <xdc/std.h>#include <xdc/runtime/System.h>#include <ti/drivers/I2C.h>#include <ti/drivers/i2c/I2CCC26XX.h>
/* BIOS Header files */#include <ti/sysbios/BIOS.h>#include <ti/sysbios/knl/Task.h>
/* TI-RTOS Header files */// #include <ti/drivers/I2C.h>#include <ti/drivers/PIN.h>// #include <ti/drivers/SPI.h>// #include <ti/drivers/UART.h>// #include <ti/drivers/Watchdog.h>
/* Board Header files */#include "Board.h"
#define TASKSTACKSIZE   512
Task_Struct task0Struct;Char task0Stack[TASKSTACKSIZE];
/* Pin driver handle */static PIN_Handle ledPinHandle;static PIN_State ledPinState;
/* * Application LED pin configuration table: *   - All LEDs board LEDs are off. */PIN_Config ledPinTable[] = {    Board_LED0 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,    Board_LED1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,    PIN_TERMINATE};
/* *  ======== heartBeatFxn ======== *  Toggle the Board_LED0. The Task_sleep is determined by arg0 which *  is configured for the heartBeat Task instance. */Void heartBeatFxn(UArg arg0, UArg arg1){    while (1) {        Task_sleep((UInt)arg0);        I2C_Handle handle;                       I2C_Params i2cParams;                       I2C_Transaction i2cTrans;                       uint8_t rxBuf[1];      // Receive buffer                       uint8_t txBuf[0];      // Transmit buffer                       // Configure I2C parameters.           txBuf[0]='b';                    // I2C_Params.I2C_TransferMode=I2C_MODE_CALLBACK;                       I2C_Params_init(&i2cParams);
                       // Initialize master I2C transaction structure                       I2CCC26XX_I2CPinCfg pinCfg;                       pinCfg.pinSDA = Board_I2C0_SDA0;                       pinCfg.pinSCL = Board_I2C0_SCL0;                     //  i2cParams.custom = &pinCfg;                       handle = I2C_open(Board_I2C, &i2cParams);                       I2C_open(Board_I2C, &i2cParams);//


                     i2cTrans.writeCount   = 0;                       i2cTrans.writeBuf     = txBuf;


                       i2cTrans.readCount    = 1;                       i2cTrans.readBuf      = rxBuf;                       i2cTrans.slaveAddress = 0x49;                       I2C_transfer(handle, &i2cTrans);//                           uint8_t a ;
                     I2C_close(handle);//    I2C_init();                       Task_sleep((UInt)1000);    }}
/* *  ======== main ======== */int main(void){    Task_Params taskParams;
    /* Call board init functions */    Board_initGeneral();    // Board_initI2C();    // Board_initSPI();    // Board_initUART();    // Board_initWatchdog();
    /* Construct heartBeat Task  thread */    Task_Params_init(&taskParams);    taskParams.arg0 = 1000;    taskParams.stackSize = TASKSTACKSIZE;    taskParams.stack = &task0Stack;    Task_construct(&task0Struct, (Task_FuncPtr)heartBeatFxn, &taskParams, NULL);
    /* Open LED pins */    ledPinHandle = PIN_open(&ledPinState, ledPinTable);    if(!ledPinHandle) {        System_abort("Error initializing board LED pins\n");    }
    PIN_setOutputValue(ledPinHandle, Board_LED1, 1);
    /* Start BIOS */    BIOS_start();
    return (0);}

  • Hi Mustahsin,

    A few quick things, which version of TIRTOS are you using? Have you configured your hardware correctly? (Pullup resistors for the I2C lines)

    Finally, could you check the return value of the I2C_open() / I2C_transfer calls to make sure that they're not returning errors?

    /* Example */
    if (I2C_open() != I2C_STATUS_SUCCESS) {
        System_printf("I2C error occurred");
        System_flush();
    }

    Best,

    Alexander

  • TI-RTOS CC13XX and CC26XX 2.16.00.08
    ccs : Version: 6.1.2.00015


    I2C_open() / I2C_transfer calls are not returning errors.

    I have added pull up resistors of 10k each
  • Okay thanks,

    I noticed that you commented out a few important lines of code such as I2C_init(), in addition to i2cParams.custom = &pinCfg;. Where exactly are you setting up the I2C pins?

    Best,
    Alexander
  • // pin initialization

    I2CCC26XX_I2CPinCfg pinCfg;

    pinCfg.pinSDA = Board_I2C0_SDA0;

    pinCfg.pinSCL = Board_I2C0_SCL0;

    I have not initialized the parameters my self. I understood they were initialized with default values. That seems to be the case.

    The i2c0 register shows that there are no errors. I am attaching the screenshots:

    I just want to know where the data is stored that I got from the I2C

  • Got it to work. to add this line of code

    uint16_t register_status = rxBuf[0];

    thanks for your help
  • Hi Mustahsin,

    You're correct in expecting the data read to be within the MDR register, however, the way your code is set up I don't see how you could receive data at the moment. It looks like you're not sending any data to the device, but are expecting data back.(The write count is set to 0) The transfer will reutrn a success as it expects to send 0 bytes and it did.

    I would also recommend un-commenting the line to assign the pins, just as a precaution.

    i2cParams.custom = &pinCfg;
    

    Best,

    Alexander