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.

TIVA: Send 1 byte via I2C and receive 2 bytes

Hello,

I'm using the following code in order to send one byte to a temp. sensor and get back 2 bytes.

But according to the I2C monitor, sometimes, only one byte is received (and not 2).

After sending 1 byte I can not send stop but a "start". This is required by the device.

Can you please check that my code is OK ?

Thanks,

Zvika


I2CMasterSlaveAddrSet(I2C6_BASE, SLAVE_ADDRESS, false);

//Send 0xAA
I2CMasterDataPut(I2C6_BASE, 0xAA);
I2CMasterControl(I2C6_BASE, I2C_MASTER_CMD_BURST_SEND_START);
while(I2CMasterBusy(I2C6_BASE)){};

I2CMasterSlaveAddrSet(I2C6_BASE, SLAVE_ADDRESS, true);

I2CMasterControl(I2C6_BASE, I2C_MASTER_CMD_BURST_RECEIVE_START);
while(I2CMasterBusy(I2C6_BASE)){};
*data=I2CMasterDataGet (I2C6_BASE);

I2CMasterControl(I2C6_BASE, I2C_MASTER_CMD_BURST_RECEIVE_FINISH);
while(I2CMasterBusy(I2C6_BASE)){};
dummy=I2CMasterDataGet (I2C6_BASE);

  • Hello Zvika

    Try using the following code

    I2CMasterSlaveAddrSet(I2C6_BASE, SLAVE_ADDRESS, false);
    
    //Send 0xAA
    I2CMasterDataPut(I2C6_BASE, 0xAA);
    I2CMasterControl(I2C6_BASE, I2C_MASTER_CMD_BURST_SEND_START);
    while(!(I2CMasterBusy(I2C6_BASE))){};
    while(I2CMasterBusy(I2C6_BASE)){}; I2CMasterSlaveAddrSet(I2C6_BASE, SLAVE_ADDRESS, true); I2CMasterControl(I2C6_BASE, I2C_MASTER_CMD_BURST_RECEIVE_START); while(!(I2CMasterBusy(I2C6_BASE))){};
    while(I2CMasterBusy(I2C6_BASE)){}; *data=I2CMasterDataGet (I2C6_BASE); I2CMasterControl(I2C6_BASE, I2C_MASTER_CMD_BURST_RECEIVE_FINISH); while(!(I2CMasterBusy(I2C6_BASE))){};

    while(I2CMasterBusy(I2C6_BASE)){}; dummy=I2CMasterDataGet (I2C6_BASE);

    Regards

    Amit

  • Hi Amit,

    The <strong> tags are not doing what you wanted there, inside a code block.

    Zvi,

    Watch out for those <strong> tags.

  • Hi Amit,

    Thank you for your fast reply.

    I2CMasterBusy(I2C6_BASE) returns true if the bus is busy.

    So why calling to: while ( ! I2CMasterBusy(I2C6_BASE)){}  ?

    I tried your code. It does not work.

    Can you clarify ?

    Thanks,

    Zvika

  • Hello Zvi,

    After the control word is put, it takes some time for the I2C Controller to start the transaction. During this time the I2C Controller may not be busy and the original while loop may get skipped.

    By adding the new while loop, if the I2C Controller is not busy, it waits for it to get busy and then waits for it to complete. If the I2C Controller is already busy by the time the first loop is executed, it would move to the second loop.

    Since this is not working, I would have to ask you to send a scope shot or i2C Monitor details about when it is working how does the transaction look v/s when it does not work. Though this is described in the post, I would want to be clear. Also what is the slave device in this case?

    One more thing to check is if there is a clock low timeout that is occurring in the master controller?

    Regards

    Amit

  • Hello Zvi,

    I am a bit confused here. If the issue is not resolved then "Verify Answer" does not qualify.

    If you can send the details as the last post and we close the issue I would be more glad.

    Regards

    Amit

  • Hi Amit,

    I owe you an apology.

    I looked at your code and saw:

    while (! ....) and then while ( ) and it looks to me like a mistake.

    But after trying it, it solved the problem !!!

    Your help is highly appreciated.

    Best regards,

    Zvika