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.

TM4C1294KCPDT: Possibility of code hang due to I2C communication.

Part Number: TM4C1294KCPDT

Hi,

   I want to know the function definition of few of the library functions which are mentioned below. 

1. I2CMasterSlaveAddrSet()

2. I2CMasterDataPut()

3. I2CMasterControl()

4. I2CMasterBusy()

My doubt is can these functions go into infinite loop if there is any issue in the I2C Bus, Slave device etc? if so which API can make the CPU to get hang? To know better i wanted to see its definition.    

  • Hello Bharath,

    You can find each of these functions in the i2c.c file in the driverlib folder.

    Also have a look at our example here: [Install Path]\TivaWare_C_Series-2.2.0.295\examples\boards\ek-tm4c1294xl-boostxl-senshub\humidity_sht21_simple 

    For TM4C129x you need a delay after I2CMasterControl for sending data, see the following:

        //
        // Setup for first read.  Use I2C_MASTER_CMD_BURST_RECEIVE_START
        // to start a burst mode read.  The I2C master continues to own
        // the bus at the end of this transaction.
        //
        MAP_I2CMasterControl(I2C7_BASE, I2C_MASTER_CMD_BURST_RECEIVE_START);
    
        //
        // Wait until master module is done transferring.
        // The I2C module has a delay in setting the Busy flag in the register so
        // there needs to be a delay before checking the Busy bit.  The below loops
        // wait until the Busy flag is set, and then wait until it is cleared to
        // indicate that the transaction is complete.  This can take up to 633 CPU
        // cycles @ 100 kbit I2C Baud Rate and 120 MHz System Clock.  Therefore, a
        // while loop is used instead of SysCtlDelay.
        //
        while(!MAP_I2CMasterBusy(I2C7_BASE))
        {
        }
        while(MAP_I2CMasterBusy(I2C7_BASE))
        {
        }

  • Hi,

    1. Yes thank you i went through the definition of each function what i wanted. 

    2. Yes we are also using the MasterBusy inside the while loop, but again it will come out of the while loop only when the bus is not busy. so because of any issue in the bus the code will get stuck in that while loop. which is fine we get it and we can have a simple sysctlDelay in case we have some issue in the BUS until it is solved.

    3. But my doubt was is there any chance of the function call of I2CMasterSlaveAddrSet(), I2CMasterDataPut(), I2CMasterControl() and also ( I2CMasterBusy() if it is not inside while condition), making the code getting stuck in these functions? looking at the function definition it is simple peripheral register write operation happening inside these functions, so just need a confirmation whether code can get hanged in these function? 

    4. What are the possibility of code getting stuck due to I2C? particular scenario from I2C peripheral to hang the CPU? the code is simple say 

    I2CMasterSlaveAddrSet(I2C_BASE, SLAVE_ADDRESS_CAN_ID, false);
    I2CMasterDataPut(I2C_BASE, CONFIG_PORT_0);
    I2CMasterControl(I2C_BASE, I2C_MASTER_CMD_BURST_SEND_START);

    // while(I2CMasterBusy(I2C_BASE)); can be used but to keep it simple from getting into infinite loop because of BUS line held low by slave due to some issue will use simple sysctlDelay of 1msec

    now my doubt is even if there is some issue in BUS line or slave device or anything, can these 3 API or anything from I2C peripheral can lead to code getting hanged? 

     

  • Hello Bharath,

    The only hangs would occur with while loops for I2CMasterBusy. The individual functions would not hang on their own.

    The code will not hang from anything but getting stuck in an I2C based while loop.

  • Hi,

      Thank you for the clarification. 

    regards,

    Bharath