Quantcast
Channel: Forums - Recent Threads
Viewing all articles
Browse latest Browse all 262198

TM4C1294NCPDT: I2C Issue

$
0
0

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


Viewing all articles
Browse latest Browse all 262198

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>