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.

TM4C1294NCPDT: I2C communication: How to do a write to slave address and read from the same slave address without a stop condition in between (Tm4c is the master controller)?

Part Number: TM4C1294NCPDT

Hi,

I am trying to communicate with a certain I2C based IC and wanted to read some values from a register. The procedure to read page over I2C is to first send write command to the salve address followed by the register no. which will be acknowledged by the slave, then without sending the stop condition, send the read command with the slave address which will be again acknowledged by the slave . After that we need to send the burst read command to continuously read slave data and in the end master will acknowledge and send the stop bit.

I attempted at doing this with the following piece of code. However, I am not getting proper acknowledges and sometimes the data which I try to write in register is corrupted. What am I doing wrong?

//
// To read the power consumed
//
void I2C8ReadPower(uint8_t ui8SlaveAddr )
{
    uint32_t error = 0;

    //
    // Set the slave address for the I2C Base
    //
    I2CMasterSlaveAddrSet(I2C8_BASE, ui8SlaveAddr, false);



    //
    // Send the I2C address bus(power) and the register value to be read
    // on the I2c Bus.
    //
    I2CMasterDataPut(I2C8_BASE, READ_POWER_ADDRESS);

    I2CMasterControl(I2C8_BASE, I2C_MASTER_CMD_BURST_SEND_START);

    SysCtlDelay(10000);
    while (I2CMasterBusy(I2C8_BASE))
    {

    }

    error |= I2CMasterErr(I2C8_BASE);

    if (error == 0x16)
    {
        //
        // Arbitration error
        //
        while (1)
        {}
    }
    //
    // Read the power
    //
    I2CMasterSlaveAddrSet(I2C8_BASE, ui8SlaveAddr, true);


    I2CMasterControl(I2C8_BASE, I2C_MASTER_CMD_BURST_RECEIVE_START);

    SysCtlDelay(10000);


    while(I2CMasterBusy(I2C8_BASE))
    {

    }

    gui8_power[2] = I2CMasterDataGet(I2C8_BASE);


    I2CMasterControl(I2C8_BASE, I2C_MASTER_CMD_BURST_RECEIVE_CONT);

    SysCtlDelay(10000);


    while(I2CMasterBusy(I2C8_BASE))
    {

    }

    gui8_power[1] = I2CMasterDataGet(I2C8_BASE);


    I2CMasterControl(I2C8_BASE, I2C_MASTER_CMD_BURST_RECEIVE_FINISH);

    SysCtlDelay(10000);

    while(I2CMasterBusy(I2C8_BASE))
    {

    }

    gui8_power[0] = I2CMasterDataGet(I2C8_BASE);


    I2CMasterControl(I2C8_BASE, I2C_MASTER_CMD_BURST_SEND_STOP);
    SysCtlDelay(10000);


    while(I2CMasterBusy(I2C8_BASE))
    {

    }

Here, the Logic analyser result is:

The data in front of 0x23 and 0x48 should be NAck and 0XA0 should be acknowledged by the master

  • Hello Apoorv,

    APOORV GARG said:
    The data in front of 0x23 and 0x48 should be NAck and 0XA0 should be acknowledged by the master

    I am not sure I follow. This is for the Read Page Protocol, right? If so, the only NACK I see is on the final byte received and everything else is an ACK. Which is what is displayed by your capture. So I am not sure what the issue is.

    Also as it looks like you have a Saleae logic analyzer, could you upload the full capture onto E2E so I can view it? Maybe that would help me see what is not correct with the transfer.

    Lastly, have you been referring to our I2C app note for TM4C129x devices? http://www.ti.com/lit/an/spma073/spma073.pdf - it will be very helpful for you (even as you get beyond this particular issue).