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.

CC2642R: I2C read multiple bytes get the same data.

Part Number: CC2642R

I use i2c in callback mode with no-rtos.

I2C_init();
I2C_Params_init(&i2cParams);
#if i2c_mode
i2cParams.transferCallbackFxn = i2cCallback;
i2cParams.transferMode = I2C_MODE_CALLBACK;
#else
i2cParams.transferMode = I2C_MODE_BLOCKING;
#endif
i2cParams.bitRate = I2C_400kHz;
i2cAcc = I2C_open(CONFIG_I2C_ACC, &i2cParams);
if (i2cAcc == NULL) {
while (1);
}
i2cTransaction.writeBuf = i2cTxBuffer;
i2cTransaction.readBuf = i2cRxBuffer;

here is read code

void readAccDataMultiByte()
{
i2cTxBuffer[0] = OUT_X_L;
//i2cTxBuffer[1] = readSlaveAddr;
i2cTransaction.writeCount = 1;
i2cTransaction.readCount = 6;
I2C_transfer(i2cAcc, &i2cTransaction);
}

callback code 

void i2cCallback(I2C_Handle handle, I2C_Transaction *msg, bool status)
{
    if (status == false)
    {
        if (msg->status == I2C_STATUS_ADDR_NACK) {
        // slave address not acknowledged
        }
        else if (msg->status == I2C_STATUS_CANCEL) {
        // transaction canceled by I2C_cancel()
        }
    }
    else
    {
        /*successful*/
        flagI2cCallback = 1;
    }
}

but the 6 bytes data i get the same value.

I notice RTOS/LAUNCHXL-CC2640R2: I2C_transfer function is not working in timer callback function - Bluetooth forum - Bluetooth®︎ - TI E2E support forums   the usage looks like the same ,but the solution is not relative.

  • Hello kai,

    Where do you initialize your i2cRxBuffer and where do you confirm the data is valid to be read through flagI2cCallback?  Does the I2C work as expected if you use TI-RTOS or blocking mode?  Have you used an oscilloscope or logic analyzer to confirm that data should be different than what is received?  What device are you connecting to and have you confirmed that the command should return six bytes of data?

    Regards,
    Ryan

  • uint8_t         i2cTxBuffer[1];
    uint8_t         i2cRxBuffer[6];

    assert the flagI2cCallback in the main loop,and set a breakpoint when the flagI2cCallback is ture.

    The i2c work well and I can read the correct data in blocking mode ,but it cost too much time so I try to use callback mode.

    the slave device contact is lis2dh12 ,an accelerometer.

    Particularly,in blocking mode I read data through 1 byte and 1addrees .

  • Ok, I find the question , form the datasheet said,

    the 7 LSb represent the actual register address while the MSb enables address auto increment.

    If the MSb of the SUB field is ‘1’, the SUB (register address) is automatically increased to allow multiple data read/writes.

    So I set the  MSB of read address 1 ,it worked well. 

    Thanks for your reply.