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.

TM4C1290NCPDT: Burst mode I2C not operating consistently

Part Number: TM4C1290NCPDT

I have a master burst mode function that sometimes works right but more often does not send the first data byte.  Code as follows:

void InitI2C(void) {

    //--- Backlight at Addr 0x38, Beeper at Addr 0xF8 ---//

    I2CMasterInitExpClk(I2C2_BASE, GetClkSpeed(), I2C_100K);   // Master, 100Kbps.

    //--- Real Time Clock at Addr 0xD0 ---//

    I2CMasterInitExpClk(I2C0_BASE, GetClkSpeed(), I2C_100K);   // Master, 100Kbps.
}

void RtcWrite(u8 Register, u8 Data) {

    while(I2CMasterBusy(I2C0_BASE)) {}                             // Wait till done.
    I2CMasterSlaveAddrSet(I2C0_BASE, RtcAddr, I2CWrite);           // This shifts the addr left 1.
    I2CMasterDataPut(I2C0_BASE, Register);                         //
    I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_START);  // Register.
    while(I2CMasterBusy(I2C0_BASE)) {}                             // Wait till done.
    I2CMasterDataPut(I2C0_BASE, Data);                             //
    I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH); // Data.
}

The "Register" is 0x02 and the "Data" is 0x01.  Sometimes it works correctly:

But more often the Register value is not sent:

  • Hi Doug,

      Can you replace everywhere in your code:

    FROM:

        while(I2CMasterBusy(I2C0_BASE)) {}                             

    TO:

        while(!I2CMasterBusy(I2C0_BASE)) {}                             // Add this line

        while(I2CMasterBusy(I2C0_BASE)) {}                             // Keep this original line

  • Hi Charles,

    That didn't fix it but it did make it work differently.  One thing I did differently from yesterday is that I found that to reset the IC I needed to set the reset bit but then set it back to zero so I make a second call to RtcWrite() with Register = 2 an Data = 0.  Now the first transfer is different, instead of sending the Register number and not the Data, it now is not sending Register but is sending Data.  The second transfer, to set Data back to 0, always seems to work correctly.

    Thanks, Doug

  • But wait, there's more !

    I added:

    while( ! I2CMasterBusy(I2C0_BASE)) {}                             // Add this line

    while(I2CMasterBusy(I2C0_BASE)) {}                             // Keep this original line

    to the End of my code, so it doesn't return before everything is finished and now it works correctly, although the very first time RtcWrite() is called it probably doesn't - will have to change my test a little to check that.

    Doug

  • OK, first call does work correctly.  I'm going to play around some more, enabling FIFO, interrupt driven, etc., but for now let's call this solved.

    Thanks Charles.