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 Issue

Part Number: TM4C1294NCPDT

HI,

I am using TM4C1294NCPDT microcontroller, I have a slave IC configurable through I2C. Below is the piece of code I am ising to Configure and read ID from the slave.

void I2C_Init(){

       //enable I2C module 1
       SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C1);

       //reset module
       SysCtlPeripheralReset(SYSCTL_PERIPH_I2C1);

       //enable GPIO peripheral that contains I2C 1
       SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);

       // Configure the pin muxing for I2C0 functions on port B2 and B3.
       GPIOPinConfigure(GPIO_PG0_I2C1SCL);
       GPIOPinConfigure(GPIO_PG1_I2C1SDA);

       // Select the I2C function for these pins.
       GPIOPinTypeI2CSCL(GPIO_PORTG_BASE, GPIO_PIN_0);
       GPIOPinTypeI2C(GPIO_PORTG_BASE, GPIO_PIN_1);

       // Enable and initialize the I2C1 master module.  Use the system clock for
       // the I2C1 module.  The last parameter sets the I2C data transfer rate.
       // If false the data rate is set to 100kbps and if true the data rate will
       // be set to 400kbps.
       I2CMasterInitExpClk(I2C1_BASE,(SysCtlClockGet()), true);

       //clear I2C FIFOs
       HWREG(I2C1_BASE + I2C_O_FIFOCTL) = 80008000;

}

uint32_t I2C_Read(uint8_t slave_addr, uint8_t reg)
{
    uint32_t error = 0;
    //specify that we are writing (a register address) to the slave device
    I2CMasterSlaveAddrSet(I2C1_BASE, slave_addr, false);

    //specify register to be read
    I2CMasterDataPut(I2C1_BASE, reg);

    //send control byte and register address byte to slave device
    I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_SEND_START);

    //wait for MCU to finish transaction
    while(I2CMasterBusy(I2C1_BASE));

    error = I2CMasterErr(I2C1_BASE);

    //specify that we are going to read from slave device
    I2CMasterSlaveAddrSet(I2C1_BASE, slave_addr, true);

    //send control byte and read from the register we specified
    I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE);

    //wait for MCU to finish transaction
    while(I2CMasterBusy(I2C1_BASE));

    //return data pulled from the specified register
    return I2CMasterDataGet(I2C1_BASE);

}

Slave address is 0xCE, when i pass this as argument to the read function I was not getting ID read, so probed the SCL and SDA lines.

Found that slave address as captured by scope is 0x9C but what I am configuring is 0xCE. So, slave might not be acknowlidgening.

Pull ups are present and SCL/SDA appears clean.

Is there any issue with the code posted above? Where am I missconfiguring the bus?

Thanks,

Janardan

  • Hi,

      What is the slave IC device you are interfacing with? Can you share your slave I2C datasheet?

      Please note that the I2C slave address is a 7-bit address. This means you can only have address from 0-127. When you said your slave address is 0xCE it is already over 128. 

      When the slave address is driven out to the bus it is left shifted by 1. The bit 0 on the bus as you see on the scope is the direction (read or write) of the transaction. You should not take into account the bit 0 on the bus to determine the slave address. I'm guessing your slave I2C device address is 0x67. If you left shift 0x67 by 1 bit you will get 0xCE.

      Try with slave address of 0x67 and see if it works.