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.

CC2340R5: Can CC2340R5 support i2c Slave mode?

Part Number: CC2340R5

hi Experts,

Can CC2340R5 support i2c Slave mode? Is there example in SDK?

BR,

frank

  • Hi Frank,

    The answer is the same as with the SimpleLink CC13XX/CC26XX products: https://e2e.ti.com/f/1/t/1223193 

    This mode is not supported by TI Drivers Libraries so you would need to develop a solution using the Driverlib resources.

    Regards,
    Ryan

  • Ryan,

    which function can I use to set the callback function for interrupt like below?

    I2CIntRegister(I2C0_BASE, i2c_callback);

    BR,

    frank

     

  • I believe that you are looking for I2CTargetEnableInt from <sdk_directory>\source\ti\devices\cc23x0r5\driverlib\i2c.h, in which case you would check I2CTargetIntStatus and implement a custom callback solution if necessary.  I2CIntRegister does not exist within the SIMPLELINK-LOWPOWER-F3-SDK

    Regards,
    Ryan

  • Ryan,

    I2CTargetEnableInt is just to enable interrupt with specific interrupt flags, right?

    i want to have handler to handle the interrupt.

    Should I create a task and a while loop to check I2CTargetIntStatus? 

    BR,

    frank

  • You have the correct idea as to how this application can be accomplished.

    Regards,
    Ryan

  • Ryan,

    the while loop is for block mode.

    Is that possible to use callback mode in slave mode? 

    if using block mode, the task would occupy the resource and power consumption, right? My customer's application is very sensitive to power consumption.

    BR,

    frank

  • Between I2C Driverlib functions I2CTargetEnable and I2CTargetEnableInt, I expect it is possible to use callback mode.  Please try to reference this E2E thread to develop your solution for the CC2340R5.

    Regards,
    Ryan

  • Ryan,

    I refer to the same e2e thread. It uses function below which I already mentioned. But I cannot find it from CC2340R5 SDK.

    I2CIntRegister(I2C0_BASE, i2c_callback);

     

    Can you tell me which function I can use to install the callback function?

     

    BR,

    frank

  • Try IntRegister(INT_I2C0_IRQ, i2c_callback); from the Interrupt Driverlib (also see IntEnable).

    Regards,
    Ryan

  • Ryan,

    I can run slave mode. but the power consumption is very high, around 1.5mA.

    I only connect 3.3V to the CC2340R5 PG2 evm.

    I found that I need to put the code in the thread. If not, i2c doesn't response the ACK to controller.

    while (1) {

    // i2C write transaction
    if(I2CTargetStatus(I2C0_BASE) == I2C_TARGET_ACT_TREQ) {
    I2CTargetPutData(I2C0_BASE, 0xff);
    }
    }

    if I remove this code, the power consumption is very low, about few uA.

    do you know how to fix this?

    below is the code about how I init the target i2c. 

    I2C_Params_init(&i2cParams);
    i2cParams.bitRate = I2C_400kHz;
    i2c = I2C_open(CONFIG_I2C_TMP, &i2cParams);
    if (i2c == NULL)
    {
    Display_printf(display, 0, 0, "Error Initializing I2C\n");
    while (1) {}
    }
    else
    {
    Display_printf(display, 0, 0, "I2C Initialized!\n");
    }


    I2CTargetInit(I2C0_BASE, 0x48);
    IntRegister(INT_I2C0_IRQ, i2c_callback);
    IntEnable(INT_I2C0_IRQ);
    I2CTargetEnableInt(I2C0_BASE, (I2C_TARGET_INT_STOP | I2C_TARGET_INT_START | I2C_TARGET_INT_DATA));

    BR,

    frank

  • Having code within a while loop keeps the device active, hence the high power consumption.  Are you able to service this functionality from the i2c_callback so that the device can return to sleep?

    Regards,
    Ryan

  • Ryan,

    yes, I2c_callback works correctly.

    The I2C thread is always active. If I don't put below code in i2c thread, the i2c would not work (no ACK).

    I think that something wrong in my code. i2c should return ACK automatedly, right? Maybe i2c initialization?

    Any suggestion is welcome.

    while (1) {


    }

    BR,

    frank

  • I'm asking whether I2CTargetStatus/I2CTargetPutData could be serviced from the callback or an event the callback sets a flag for, instead of existing inside the while loop.  I explained previously that the I2C TI Driver only supports controller modes (not target) so the use of this module's APIs like I2C_Params_init and I2C_open could certainly be the cause.  You will need to initialize and open the I2C module using only/all Driverlib references.

    Regards,
    Ryan

  • Ryan,

    Which function should I exchange with I2C_Params_init() and  I2C_open()? So, I can run i2c target mode as interrupt and keep ic power consumption as low as possible.

    By the way, I set power policy to doWFI. It works without "while(1). The power consumption has no much difference and still 1.x mA.


    /* Create I2C for usage */
    I2C_Params_init(&i2cParams);
    i2cParams.bitRate = I2C_400kHz;

    i2c = I2C_open(CONFIG_I2C_TMP, &i2cParams);

    I2CTargetEnable(I2C0_BASE);
    I2CTargetInit(I2C0_BASE, 0x48);
    IntRegister(INT_I2C0_IRQ, i2c_callback);
    IntEnable(INT_I2C0_IRQ);
    I2CTargetEnableInt(I2C0_BASE, (I2C_TARGET_INT_STOP | I2C_TARGET_INT_START | I2C_TARGET_INT_DATA));
    Power_setPolicy(PowerCC23X0_config_doWFI.policyFxn);

    By the way, I use rtos GPIOInterrupt example project. the power consumption current is the same 1.x mA.

    BR,

    frank

  • You can refer to the source of I2C_Params_init and I2C_open from the I2C TI Driver inside <sdk_directory>/source/ti/drivers/i2c to convert these functions into the necessary hardware register changes.  You already had I2CTargetInit and have added I2CTargetEnable, you should also consider I2CTargetSetAddress and ensure that the correct PORTCFG bits are set for the IOC registers which correspond to the SDA/SCL pins.  In this regard you should also refer to the GPIO_setConfigAndMux from the GPIO TI Driver, <sdk_directory>/source/ti/drivers/i2c

    Regards,
    Ryan