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.

TM4C123FH6PM: TIRTOS, I2C Driver leaving gaps between bytes on bulk transfer.

Part Number: TM4C123FH6PM
Other Parts Discussed in Thread: EK-TM4C123GXL

Hello Everyone,

I am having issues with i2c transfers having gaps between bytes on both callback and blocking modes. 

There are 8 ms gaps between parts of the transfer when using blocking calls. 

I thought the internal driver would use interrupts so even if the task switches the bytes are sent properly. 

I didn't have the issue with SPI or UART drivers when I was using them.

If I try it with a devkit example that only has a single task I have no issues. The transfer is not broken into parts. 

CCS version: 10.1.1.00004 

Tirtos version : tirtos_tivac_2_16_00_08 (Installed within ccs, for some reason not the latest)

Tirtos came with TivaWare_C_Series-2.1.1.71b but I am using TivaWare_C_Series-2.2.0.295. 

Here is some captures of the i2c lines: 

Custom board blocking i2c:

There is a large gap of 7.4 ms on the same transfer.

If I use callback mode it is even worse, there is a 50 ms delay in the middle:

If there is multiple transfers there is multiple cuts in the middle. These cuts are not between transfers they actually go in the middle of transfers.

Some transactions don't get cut but most do.

Here is how I initialize i2c driver.

//Init code
I2C_Params      i2cParams;
I2C_Params_init(&i2cParams);
i2cParams.bitRate = I2C_100kHz;
I2C_Handle i2c = I2C_open(I2C0, &i2cParams);
if (i2c == NULL) 
{ 
    System_abort("Error Initializing I2C\n");
}

Here is my transfer call:

//Transaction call
uint8_t buffer[] = {0x06,0x00,0x04,0xFF,0x07,0x00,0x05,0xFF};
I2C_Transaction transaction = { buffer, sizeof(buffer), NULL, NULL, 0x20 };
if(!I2C_transfer(i2c, &cfg_transaction))
{
    System_printf("Problems sending i2c value.\n");
}

Can anybody help me with the issue please?

  • Hello Tuna,

    Have you tried using the ROV / RTOS Analyzer to view which tasks your application is running at a given time? I feel like the most likely issue is that your I2C is being preempted by a higher priority task. This would become apparently with those tools to see how your tasks are flowing and if anything is delaying the I2C execution.

  • Hello Ralph,

    Thanks for the reply. I'll check the ROV to see if it gets preempted. I haven't setup the priorities of the tasks I have created. All of them have 1 as piority. I'll raise the priority of that particular task and see if that helps with my issue. 

    I was just surprised that transaction required this much handholding after starting it. 

    I also put a task yield just before this transaction and I didn't see any gaps so that also gives me confidence that another task gets scheduled. 

    All the tasks are event driven so playing around with the priorities would probably a fine solution. I'll post if I have more issues after trying this solution. 

  • Hello Ralph,

    I tried changing the priority of the task that uses i2c to be higher than others (5 vs 1) and tried to run the code again.

    It didn't change the behavior. I am wondering when the i2c is setup in blocking mode it changes the context when the transfer is initiated. 

    The same behavior is seen on both setup part of the code and when the thread runs after getting a message from a mailbox. 

    It is also always cutting after the first 2 bytes (Address and first data byte). So that part is also deterministic. 

    I tried to use the live session to track the changes but it always misses the part the code switches to that task. (Saying gaps due to data loss.)

    I am not sure how to solve the issue. Can you help me with this.

    I can provide any data/images that you would need just let me know. 

    Thank you,

    Tuna

  • Hello Tuna,

    Would you be able to provide a project for me that runs on the EK-TM4C123GXL LaunchPad? If so I can then run it on my own hardware here and see what I can observe and if I can solve the issue with the data loss preventing you seeing more debug data.

    One other thing I noticed is that you upgraded the TivaWare version used with TI RTOS. We haven't validated other TivaWare versions. Do you have a way to quickly test with 2.1.1 if the problem also occurs?

  • Hello Ralph,

    I was going to go from one of the examples for i2c but I don't have any of the sensor boards just have a 123GXL so I wouldn't be able to run it.

    I can jump cables to the sensor I have but then you won't have the sensor.

    Also, If you try to address a device that doesn't exist clock line gets stuck low (it seems this is a old bug not resolved.).

    I will try to do what it with the sensor I have using regular Tivaware coming with RTOS and new Tivaware. Will share a zip with both. 

    I was running with regular Tivaware before switching and I experienced the same issue by the way.

  • Hello Tuna,

    You can just send me what you use for your sensor. I will update it with SensorHub BP code I have. Should be very quick to change a few lines to do a quick test. If I have issues then I can let you know and we'll figure out how I can best replicate it.

  • While trying to create the project I realized something really interesting.

    It seems like the issue doesn't happen when debugger is not connected.

    I have been running with the debugger and system flush calls have been used to help with testing the code. 

    Removing some system flush calls solved the issue. 

    Thank you Ralph for helping. 

  • Hi Tuna,

    Great to hear that the problem was so simple. Sorry I didn't come up with that idea myself, I've only recently begun with RTOS support for our devices. I'll have to keep that in mind in the future as well, thanks for sharing!

  • I have been running with the debugger and system flush calls have been used to help with testing the code. 

    If the System flush is used to write message to the CCS debugger console, then it uses the CIO protocol which involves the device stopping at a break point and the host reading the output before the target is then resumed. This could pause execution for milliseconds.

  • Hello Chester,

    Yes I believe this was the issue. Weird thing was the system flush call was on another thread and the priority of the tread running the i2c transfer was higher than that one. Maybe when a system flush call is made debugger is scheduled to read information but doesn't do it right away? Not really sure exactly how it works. I didn't notice the same behavior when sending Uart buffers so that also leads me to believe when using i2c on blocking mode it is not the hardware handling the buffering but it is the cpu. 

    I believe that is why I haven't noticed it before on uart or spi streams. 

    Thanks for your answer.