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 Bus

Part Number: TM4C1294NCPDT

Hi Team, Seeking for some assistance for a customer.

Wrapper to communicate on a i2c bus. this one looks like this: 

int8_t user_i2c_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr)
{
    int8_t rslt = 0; /* Return 0 for Success, non-zero for failure */
    uint8_t i = 0;

    /*
     * The parameter intf_ptr can be used as a variable to store the I2C address of the device
     */

    /*
     * Data on the bus should be like
     * |------------+---------------------|
     * | I2C action | Data                |
     * |------------+---------------------|
     * | Start      | -                   |
     * | Write      | (reg_addr)          |
     * | Stop       | -                   |
     * | Start      | -                   |
     * | Read       | (reg_data[0])       |
     * | Read       | (....)              |
     * | Read       | (reg_data[len - 1]) |
     * | Stop       | -                   |
     * |------------+---------------------|
     */


    I2CMasterSlaveAddrSet(I2C0_BASE, *(uint8_t *)intf_ptr, false);


    I2CMasterDataPut(I2C0_BASE, reg_addr);

    I2CMasterControl(I2C0_BASE,I2C_MASTER_CMD_SINGLE_SEND);
    while (I2CMasterBusy(I2C0_BASE)) {

    }


    I2CMasterSlaveAddrSet(I2C0_BASE, *(uint8_t *)intf_ptr, false);

    if ( len == 1){



        I2CMasterControl(I2C0_BASE,I2C_MASTER_CMD_SINGLE_RECEIVE);
        while (I2CMasterBusy(I2C0_BASE)) ;
        reg_data[0] = I2CMasterDataGet(I2C0_BASE);


    }else {

        I2CMasterControl(I2C0_BASE,I2C_MASTER_CMD_BURST_RECEIVE_START);
        while (I2CMasterBusy(I2C0_BASE)) ;
        reg_data[0] = I2CMasterDataGet(I2C0_BASE);

        for(i = 0 ; i < len -2 ; i++){

            I2CMasterControl(I2C0_BASE,I2C_MASTER_CMD_BURST_RECEIVE_CONT);
            while (I2CMasterBusy(I2C0_BASE)) ;
            reg_data[i+1] = I2CMasterDataGet(I2C0_BASE);

        }

        I2CMasterControl(I2C0_BASE,I2C_MASTER_CMD_BURST_RECEIVE_FINISH);
        while (I2CMasterBusy(I2C0_BASE)) ;
        reg_data[i+1] = I2CMasterDataGet(I2C0_BASE);

 return rslt;


    }


   

On the scope to see what is happening on the bus is see the following  :

The Address is correct and the Data send is also okay but i am wondering why the second slot is not a read slot. The master sends tow times the same. I nee the first slot like we see and the second slot must be a read slot on the same Adress. if you need some more informations pleas let me know. thank you for your help.

Thank you in advance for your help.

-Mark

  • Hi,

    The Address is correct and the Data send is also okay but i am wondering why the second slot is not a read slot.

    On your line 27, you specify the first write to I2C bus. On your line 38, you specify another write again. Both line 27 and 28 have the call below. 

    I2CMasterSlaveAddrSet(I2C0_BASE, *(uint8_t *)intf_ptr, false); // false is to write; true is to read. If you want to read, you need to change to true.