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.

eeprom interfacing though i2c in tiva TM4C123GH6PM read write problem

Other Parts Discussed in Thread: TM4C123GH6PM

Hai friend

   I am tring  eeprom interface with tiva TM4C123GH6PM  in ccs ide . I have problem in reading and writing please any one help me .

this is my code,

void i2cinit(void)
{
    SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    GPIOPinConfigure(GPIO_PB2_I2C0SCL);
    GPIOPinConfigure(GPIO_PB3_I2C0SDA);
    // Give control to the I2C0 Module
    //GPIODirModeSet(GPIO_PORTB_BASE, GPIO_PIN_3, GPIO_DIR_MODE_HW);
    //GPIODirModeSet(GPIO_PORTB_BASE, GPIO_PIN_2, GPIO_DIR_MODE_HW);
    GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_2 | GPIO_PIN_3);
    HWREG(I2C0_BASE + I2C_O_MCR) |= 0x01;
    I2CMasterInitExpClk(I2C0_BASE, SysCtlClockGet(), false);
    //I2CSlaveEnable(I2C0_BASE);
    //I2CSlaveInit(I2C0_BASE, SLAVE_ADDRESS);
    I2CMasterEnable(I2C0_BASE);
}

void eepromWrite(uint16_t address_u16, uint8_t data_u8)
{

    I2CMasterSlaveAddrSet(I2C0_BASE, SLAVE_ADDRESS, false);
    I2CMasterDataPut(I2C0_BASE, ((address_u16 >> 8) & 0xFF));
    SysCtlDelay(dalay);
    I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_START);
    while(I2CMasterBusy(I2C0_BASE))  {}

    I2CMasterDataPut(I2C0_BASE, (address_u16 & 0xFF));
    SysCtlDelay(dalay);
    I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_START);
    while(I2CMasterBusy(I2C0_BASE))  {}

    I2CMasterDataPut(I2C0_BASE, data_u8);
    SysCtlDelay(dalay);
    I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_START);
    while(I2CMasterBusy(I2C0_BASE))  {}
}
void eepromRead(uint16_t address_u16, uint8_t *rxdata_pu8,uint32_t rxdataLen_u32)
{
    uint16_t i = 0;
    I2CMasterSlaveAddrSet(I2C0_BASE, SLAVE_ADDRESS, false);

    I2CMasterDataPut(I2C0_BASE, ((address_u16 >> 8) & 0xFF));
    SysCtlDelay(dalay);
    I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_START);
    while(I2CMasterBusy(I2C0_BASE))  {}

    I2CMasterDataPut(I2C0_BASE, (address_u16 & 0xFF));
    SysCtlDelay(dalay);
    I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_START);
    while(I2CMasterBusy(I2C0_BASE))  {}

    I2CMasterSlaveAddrSet(I2C0_BASE, SLAVE_ADDRESS, true);
    while(I2CMasterBusy(I2C0_BASE))  {}
    // Tell the master to read data.
    I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE);
    // Wait until the slave is done sending data.

    for(i = 0; i < rxdataLen_u32; i++)
    {
        while(I2CMasterBusy(I2C0_BASE))  {}
        *rxdata_pu8 = I2CMasterDataGet(I2C0_BASE);
        rxdata_pu8++;
        SysCtlDelay(dalay);
    }
}