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.

I2C Initialization on LM4F232 eval board

Other Parts Discussed in Thread: TMP75

Hi,

Sorry for re-posting the same query again, I need urgent support on I2C initialization. Please let me know if further information is required.

I am working on evaluation board LM4F232H5QD where I2C0 is connected to TMP75 temperature sensor. I am using the following code:

1) To initialize I2C0

void InitI2C0(void)
{
    SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

    GPIOPinConfigure(GPIO_PB2_I2C0SCL);
    GPIOPinConfigure(GPIO_PB3_I2C0SDA);

    GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_2 | GPIO_PIN_3);

    I2CMasterInitExpClk(I2C0_MASTER_BASE, SysCtlClockGet(), false);     // SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |  

                                                                                                                                     //      SYSCTL_XTAL_16MHZ);
}

2) Code to send data:

void I2C_burstsend(unsigned char ucSlaveAddr, unsigned char sendData[], unsigned char size)
{
    unsigned int i;

    // Set the slave address, and set the Master to Transmit mode
    I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, ucSlaveAddr, false);
    // Place the character to be sent in the data register
    I2CMasterDataPut(I2C0_MASTER_BASE, sendData[0]);
    
    // Initiate send of character from Master to Slave
    if (size > 0)
        I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_START);
    else
        I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_SINGLE_SEND);
    // Delay until transmission completes
    while(I2CMasterBusy(I2C0_MASTER_BASE)){}

    if (size == 0)
        return;


    // send data array
    for(i=1; i < (size-1); i++)
    {
        I2CMasterDataPut(I2C0_MASTER_BASE, sendData[i]);
        I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
        while(I2CMasterBusy(I2C0_MASTER_BASE)){}
    }

    // send the last byte
    I2CMasterDataPut(I2C0_MASTER_BASE, sendData[i]);
    I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
    while(I2CMasterBusy(I2C0_MASTER_BASE)){}
}

It seems the code is not working, when I put a breakpoint at "if (size > 0)" and check the value of Register in CCS5 I2C0->I2C_MDR->I2C_MDR_DATA, the value is 0x00000000; the value of sendData[0] = 0x90.

When I proceed to next step i.e. I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_START); and checked the value of I2C_MCS_ERROR, its value is 1.

FYI, TMP75 is connected with 4.7kohm pull-up resistor.

Looking forward to your support.

Thanks and regards,

Praveen

// -------------------------------------------

I also tried the following code to initialize the I2C0, but behaviour is same:

void InitI2C0(void)
{
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);

    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

    I2CMasterIntEnable(I2C0_MASTER_BASE);

    GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2);

    ROM_GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3);

    ROM_GPIOPinConfigure(GPIO_PB2_I2C0SCL);

    ROM_GPIOPinConfigure(GPIO_PB3_I2C0SDA);

    GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_3, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_OD_WPU);

    ROM_I2CMasterInitExpClk(I2C0_MASTER_BASE, ROM_SysCtlClockGet(), false);

}

  • Along w/repeat posts - your code postings are inconsistent!  Post 1 or 2 (your recent series) lists:

    void InitI2C0(void)
    {
        ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);

        ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

        I2CMasterIntEnable(I2C0_MASTER_BASE);

        GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2);

        ROM_GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3);

        ROM_GPIOPinConfigure(GPIO_PB2_I2C0SCL);

        ROM_GPIOPinConfigure(GPIO_PB3_I2C0SDA);

        GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_3, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_OD_WPU);

        ROM_I2CMasterInitExpClk(I2C0_MASTER_BASE, ROM_SysCtlClockGet(), false);

    }

    Green line is good - yet has "disappeared" your most recent listing.  Red line - undoes aspects of earlier PinType & PinConfigure - not good.  It appears that you are "blending" I2C code examples from vendor's past - now NRND M3 - with your newer M4 - which will not work...  Instead - you must focus entirely upon any/all I2C code examples and listings targeting newer M4 devices. 

    Is there not complete demo code - that kit - as I earlier suggested?  If so - change nothing!  Get something working first - then if you must - make one slight change and immediately test/verify. 

    Suspect that your use of, "sendData[i]" w/in "I2CMasterDataPut()" - while inventive - adds complication - which is not ideal when one's need is "urgent." 

    Suggest that you place "standard data values" in place of the array - and test/verify...

    And always - w/in I2C - you must get the Slave Address scheme right.  Check/double-check - mistake here forever "dooms" your efforts - no matter how "urgent."