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.

Verifying I2C library function



Hi,

I've read over most of the forum threads about I2C and have the code set up correctly as far as I am aware.

	I2CMasterSlaveAddrSet(I2C0_BASE, SLAVE_ADDRESS, false);
	//SEND CONTROL CMD
	I2CMasterDataPut(I2C0_BASE, 0x01);
	I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_START);
	while(I2CMasterBusy(I2C0_BASE))
	{
	}
    	//SEND DATA BYTES
    	I2CMasterDataPut(I2C0_BASE, 0x02);
    	I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
    	while(I2CMasterBusy(I2C0_BASE))
    	{
    	}
    	//SEND DATA BYTES
    	I2CMasterDataPut(I2C0_BASE, 0x03);
    	I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
    	while(I2CMasterBusy(I2C0_BASE))
    	{
    	}
    	//FINISH
    	I2CMasterDataPut(I2C0_BASE, 0x04);
    	I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
    	while(I2CMasterBusy(I2C0_BASE))
    	{
    	}

The slave (MAX5825 DAC chip) is responding to address with ACK.

Now the difference:

When I set up a loopback slave the dataput is fine.

But when I use a real slave only second and fourth bytes is seen.

Picture from logic analyzer below.

It doesn't seem possible that the MAX5825 can inhibit I2C from sending data. So maybe the software is skipping over the Send commands?

Stephen

  • Hello Stephen,

    Looks like that Master is a TM4C129 device. Did you try doing the following
    while(!(I2CMasterBusy(I2C0_BASE)))
    {
    }
    while(I2CMasterBusy(I2C0_BASE))
    {
    }

    instead of

    while(I2CMasterBusy(I2C0_BASE))
    {
    }

    Regards
    Amit
  • Hi Amit,

    That solved my problem.

    Thanks!

    Stephen

  • Hi Stephen,

    Could you confirm me something? Is that a Logic, digital analyzer?

    Also, instead of what Amit suggested could you try adding SysCtlDelay(20); before the

    while(I2CMasterBusy(I2C0_BASE))

    {

    }

    The delay could be less, just don't know how less so i just suggested a number that would surely do the job, you can test later shorter delays.

    I want to confirm this:

    The problem your facing is most likely due to the TM4C1294 increased clock of 120Mhz - compared to the TM4C123 at 80Mhz from which the I2C example originated first. Supposedly the TM4C1294 is fast enough that the flag  I2CMasterBusy doesn't update in time, hence when you check it right away it wasn't updated yet. The extra while Amit suggested would just be a delay of sorts.
    I sincerely don't like it, if for some reason the flag was updated first to "Busy" then back to "Not Busy" then when you use the while that Amit suggested you would have a endless loop.

    Amit, you could confirm this also right? Imagine badly made interrupt (very slow) that happened just before that while you suggested, a endless loop could happen. Better safe than sorry i think, since the idea is just create a delay, better use one that doesn't have the possibility to block everything. (well a timeout could be used too but let's leave that for now)

    A handbook for these notes like the MCU to fast for the I2C could be made...

  • Hi Luis

    I am using a Saleae Digital Logic Analyzer.
    Your method also works in my example.
    I replaced with SysCtl Delay(500) to get it working. Anything less had error.
    Setting the wrong delay can also cause problems...
    I am not sure what is the best method of implementation.

    Thanks for bringing it up
    Stephen
  • Hi Stephen,

    Other method instead of that is actually using a interrupt for when the I2C is done. You could read the data inside the handler of you prefer to use the same type of code use a volatile variable like, volatile uint32_t I2CReady =0;

    And instead of both whiles use:

    while(I2CReady==0){

    }
    I2CReady=0;



    Check the verified answer in this thread (and other answers for better understanding)
    http://e2e.ti.com/support/microcontrollers/tiva_arm/f/908/t/384543


    (and i still don't get the dam notifications)