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.

I2C communication clear buffer?

Other Parts Discussed in Thread: LP-CC2652R7

Hello, I am using the LP-CC2652R7

I was writing code for a water pressure sensor that can change its baud rate. I will have the code repeat the write address for reading the pressure on the rope but I also need to set the baud rate for the Rope this is the code I have so far.
uint8_t writeReadRope[8] = {0x03, 0x00, 0x00, 0x00, 0x02, 0xCF, 0x91 };
uint8_t writeBuad[8] = {0x06, 0x00, 0x30, 0x04, 0x80, 0x82, 0xCF } ;
uint8_t readBuffer[8];
I2C_init();
Display_init();
GPIO_init();
GPIO_setConfig(Vp_EN, GPIO_CFG_OUT_STR_HIGH);
GPIO_setConfig(V5_EN, GPIO_CFG_OUT_STR_HIGH);
I2C_Params params;
I2C_Params_init(&params);
params.bitRate = I2C_100kHz;
I2C_Handle i2cHandle = I2C_open(SENSORS, &params);
I2C_Transaction transaction = {0};
transaction.targetAddress = SENS_ADDR;
transaction.writeBuf = writeBuad;
transaction.writeCount = sizeof(writeBuad);
transaction.targetAddress = SENS_ADDR;
transaction.writeBuf = writeReadRope;
transaction.writeCount = sizeof(writeReadRope);
transaction.readBuf = readBuffer;
transaction.readCount = sizeof(readBuffer);

My one concern is would I need to clear the RXBuffer if I where to write the writeBuad into the TX buffer, in order to receive the read data from writeReadRope? Because the Sensor returns 8 bytes of data from querying writeBuad, would I need to receive the writeBuad data in a different RX buffer or is there a way to clear the RX buffer before writing the ReadRope to the TX?

  • Hello Anthony Tran,

    How are you? To help resolve your issue I recommend first looking at the information we provide in our SDK about I2C; then take a look at our TI Driver APIs, specifically the I2C.h file reference, and the I2CCC26XX.h file reference which provides a usage summary and a set of examples to help you with development of I2C. In these examples you should look for the I2C transfers between the changing of "writeBuf", look at the "Chained Transactions" in the I2CCC26XX.h. As another recommendation, possibly move towards the format/code that the examples provide rather than your current pseudo-code. Then monitor the lines with a logic analyzer, or oscilloscope (if not already), and see if you need to read more into the sensor's datasheet as needed. 

    Thanks,
    Alex F

  • Hello Alex Fager,
    While Testing on the Lines I have found in fact that writing to the buffer will indeed return from the buffer the only way to remedy this was to add 
    transaction.readBuf = 0;
    transaction.readCount = 0;
    The 0 values as stated in the I2C form makes it that the RX buffer for that instance is not used and discarded 

    Thank you,
    Anthony