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.

RTOS/CC2640R2F: How can I use “i2cTx()” in Sensor Controller Studio for read and write value from MPU6500

Part Number: CC2640R2F

Tool/software: TI-RTOS

HI

   I.m trying to get MPU6500 connect to cc2640r2-LAUNCHXL using SCS

this is the help doc about i2cTx:

//////////////////////////////////////////////////////

i2cTx

Prototype: i2cTx(txValue)

Transmits a single byte over I2C. The received acknowledgment value is stored in state.i2cStatus.

Parameter value(s)

  • txValue - The value to be transmitted 

////////////////////////////////////////////////////

And these is a example:

//////////////////////////////////////////////////

Examples

Accelerometer Polling

// Accelerometer (I2C address 0x86+W): Write X register address (0x04)
i2cStart();
i2cTx(0x86 | I2C_OP_WRITE);
i2cTx(0x04);

// If successful ...
if (state.i2cStatus == 0x0000) {

    // Accelerometer (I2C address 0x86+R): Read X/Y/Z register values
    i2cRepeatedStart();
    i2cTx(0x86 | I2C_OP_READ);
    i2cRxAck(output.x);
    i2cRxAck(output.y);
    i2cRxNack(output.z);
}
i2cStop();

// Handle errors, if any ...
if (state.i2cStatus != 0x0000) {
    ... Handle errors ...
} 
//////////////////////////////////////////////////////////////

so how to locate I2c address and register address by using i2cTx to read and write from sensor?

I can not find useful example for my project. 

  • Hello,

    See below for an example on how to write to a device with ADDRESS (ALS_I2C_ADDR) and Writing a 16bit value (ALS_CFG_ONE_SHOT) to a register location (ALS_REG_CFG).

    Execution Code

    // Configure and start the next measurement
    i2cStart();
    //This sends the address + write bit
    i2cTx(I2C_OP_WRITE | ALS_I2C_ADDR);
    //This sends register address you wish to write to
    i2cTx(ALS_REG_CFG);
    //This send the MSB value you wish to write to the register location
    i2cTx(ALS_CFG_ONE_SHOT >> 8);
    //This send the LSB value you wish to write to the register location
    i2cTx(ALS_CFG_ONE_SHOT >> 0);
    i2cStop();
    
    // Read the result after ~100 milliseconds + a 20% margin
    evhSetupTimer1Trigger(0, 120, 2);
    
    // Schedule the next execution
    fwScheduleTask(1);

    Event Handler A Code

    // If a measurement was successfully started during the last execution ...
    if (state.i2cStatus == 0x0000) {
        
        // Select the result register
        i2cStart();
        //This sends the address + write bit
        i2cTx(I2C_OP_WRITE | ALS_I2C_ADDR);
        //This sends register address you wish to write to
        i2cTx(ALS_REG_RESULT);
        
        // If successful ...
        if (state.i2cStatus == 0x0000) {
            U16 resultRegH;
            U16 resultRegL;
            
            // Read the result
            i2cRepeatedStart();
            //This sends the address + read bit    
            i2cTx(I2C_OP_READ | ALS_I2C_ADDR);
            //This reads the first byte value and saves it in resultRegH
            i2cRxAck(resultRegH);
            //This reads the second byte value and saves it in resultRegH
            i2cRxNack(resultRegL);
            i2cStop();
        } else {
            i2cStop();
        }
    }

    I hope this helps,

    AB