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.

Not able to get a handle using I2C_Open() on CC2650 using reference code from TI document

Other Parts Discussed in Thread: CC2640, CC2650

Using: SmartRF06 Eval board with CC2650EM board, QFN48 7x7 RGZ,  TI-RTOS In Use

Using the document  "SimpleLink™ Bluetooth® low energy CC2640 wireless MCU Software Developer’s Guide" (swru393.pdf) as a guide.  (I could not find an equivalent document for the CC2650)

Referring to the I2C section of the document, I followed the following steps precisely (using the same LED1/LED2 pins as on the example).  I had a compilation error on the #pragma statement and I made the change highlighted in yellow.

1. Comment out the LED pins and define the I2C pins in Board.h:
//#define Board_LED1 IOID_25
//#define Board_LED2 IOID_27
#define Board_SDA IOID_25
#define Board_SCL IOID_27


2. Replace the LED configuration in the initial GPIO config table with the I2C pin configuration in
Board.c
PIN_Config BoardGpioInitTable[] = {
Board_SDA | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
Board_SCL | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,


3. Also in Board.c, declare the necessary I2C structures:
/* Place into subsections to allow the TI linker to remove items properly */
#if defined(__TI_COMPILER_VERSION__)
#pragma DATA_SECTION(I2C_config, ".const:i2cCC26XX_config")
#pragma DATA_SECTION(i2cCC26XXHWAttrs, ".const:i2cCC26XXHWAttrs")
#endif
/* Include drivers */
#include <ti/drivers/I2C/I2CCC26XX.h>
/* I2C objects */
I2CCC26XX_Object i2cCC26XXObjects[CC2650_I2CCOUNT];
/* I2C hardware parameter structure, also used to assign UART pins */
const I2CCC26XX_HWAttrs i2cCC26XXHWAttrs[CC2650_I2CCOUNT] = {
{ /* CC2650_I2C0 */
.baseAddr = I2C0_BASE,
.intNum = INT_I2C,
.powerMngrId = PERIPH_I2C0,
.sdaPin = Board_SDA,
.sclPin = Board_SCL
},
};
/* I2C configuration structure */
const I2C_Config I2C_config[] = {
{ &I2CCC26XX_fxnTable, &i2cCC26XXObjects[0], &i2cCC26XXHWAttrs[0] },
{ NULL, NULL, NULL }
};

1. Include the I2C driver:

#include <ti/drivers/I2C.h>

2. Declare the I2C handle and parameter structures as local variables:
static I2C_Handle SbpI2cHandle;
static I2C_Params SbpI2cParams;

3. Initialize the I2C driver in SimpleBLEPeripheral_init())

I2C_Params_init(&SbpI2cParams);
SbpI2cHandle = I2C_open(CC2650_I2C0, &SbpI2cParams);

with this code, I2C_open always returns NULL (no exceptions or crashes occur with this code).

I have inserted the call to I2C_init in the main() function,

int main(void)

{
/* Call board init functions. */
Board_initGeneral();

Board_initI2C();
Board_initUART();
Board_initSPI();

I made sure I selected "Use I2C Driver" in the RTOS cfg file.

I call I2C_open with the following code...

/* Create I2C for usage */
I2C_Params_init(&i2cParams);

i2cParams.bitRate = I2C_400kHz;
i2cParams.transferMode = I2C_MODE_CALLBACK;
i2cParams.transferCallbackFxn = I2C_TransferCallback;
i2cHandle = I2C_open(CC2650_I2C0, &i2cParams);

if (i2cHandle == NULL)
{
System_printf("Error Initializing I2C\n");
}

I verified that the I2C Clock and Data lines are connected to the correct pins on the development board.

What could be probable causes of the I2C_Open() call always returning NULL?

  • Hello. Yes, that change does appear necessary. Does the I2C work if you do not initialize UART and SPI? The code from the document is an extremely basic example. There are other considerations to take into account when adding multiple drivers. There is also a much more in-depth example of I2C in the SensorTag proejct.
  • I2C_open typically returns null if it is already opened or if the PIN_open inside the driver is not getting a pin handle for the pins it wants to use.
    This can happen if some other peripheral drivers already has taken ownership of the pins using PIN_open or if the application has done this.
    Make sure you don't use the same pins for many purposes in the board files.

    You can add the I2C source file to your project and set a breakpoint in the driver to easier see what is going on. Files:
    C:\ti\tirtos_simplelink_2_11_01_09\packages\ti\drivers\I2C.c
    C:\ti\tirtos_simplelink_2_11_01_09\packages\ti\drivers\i2c\I2CCC26XX.c

    Best regards,
    Svend
  • Thank you so much for answering my question as I asked it.