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.

LAUNCHXL-CC1312R1: I2C Communication w/ slave device

Part Number: LAUNCHXL-CC1312R1


Hello E2E Experts,

Good day.

 I'm currently trying to port an arduino library that uses the Wire.h library for I2C communication. I'm currently using TI's i2c.h solution and have found the documentation here https://software-dl.ti.com/simplelink/esd/simplelink_cc13x0_sdk/2.40.00.20/exports/docs/tidrivers/doxygen/html/_i2_c_8h.html very helpful, but I have a question about reading and writing *to a specific register*. As an example, the library I'm porting might have a line like     

write(0x01 /* the slave's register to write to */,
      
      &variable_to_write,
      sizeof(variable_to_write),
      0xAB /* the address of the slave */
)

 The Wire.h primitives are here https://github.com/garmin/LIDARLite_Arduino_Library/blob/master/src/LIDARLite_v3HP.cpp  .

 

My main question is if I'm responsible for just writing the reg address (0x01), and then writing the data. To confirm my understanding, that would mean that the i2c.h example 

I2C_Transaction i2cTransaction;
uint8_t writeBuffer[3];
writeBuffer[0] = 0xAB;
writeBuffer[1] = 0xCD;
writeBuffer[2] = 0xEF;
i2cTransaction.slaveAddress = 0x50;
i2cTransaction.writeBuf = writeBuffer;
i2cTransaction.writeCount = 3;
i2cTransaction.readBuf = NULL;
i2cTransaction.readCount = 0;
status = I2C_transfer(i2cHandle, &i2cTransaction);
if (status == false) {
    // Unsuccessful I2C transfer
}

has the effect of writing 0xCDEF to register 0xAB of the slave device at 0x50, correct?

Thank you in advance.

Regards,

CSC

  • Hi TI-CSC, 

    The understanding of Patrick is correct. The first byte of the writeBuf is used as register address of the I2C peripheral, while the following values are written into the selected register. 

    I would suggested the costumer to have look at the i2ctmp007 examples available in the examples/rtos/<device>/drivers/ folder. This examples shows how to operate the temperature sensor on the TI SENSORS-BOOSTERPACK and it's a very good start to see how the I2C driver should be used.

    Regards,

    Fausto

  • Hello Fausto,

    I've looked into the code you've pointed me, too, and I was able to get it up and running on my Launchpad, but I seem to keep getting an I2C_STATUS_ARB_LOST when I try to communicate with the I2C slave device. According to the documentation, I2C_STATUS_ARB_LOST is when multi-master arbitration fails, but my setup is just the launchpad (a single master) and sensor. Is there something I need to do besides I2C_init before I can start communicating with the slave device?

    Thank you in advance.

    Regards,

    CSC

  • Hello Fausto,

    I replaced the pull-up resistors with a larger resistance (4.7kOhm) and it resolved my issue, thank you for all of your help.

    Regards,

    CSC

  • Hi CSC,

    Thank you for your update. I will close the thread then.

    Regards,

    Fausto