Hi
We met the similar question about FlexCAN delay between transmitted messages.
I did a test with TWR-K70F120M board with repeated transfer standard CAN frame (FlexCAN configured 1Mbps baud rate) with CodeWarrior MCU V10.6 with processor expert [CAN_LDD] driver.
Below is the test code abstracted:
MyCANPtr = CAN1_Init(NULL); /* Initialization of CAN2 component */
Frame.MessageID = 0x123U; /* Set Tx ID value - standard */
Frame.FrameType = LDD_CAN_DATA_FRAME; /* Specyfying type of Tx frame - Data frame */
Frame.Length = sizeof(CAN_OutData); /* Set number of bytes in data frame - 4B */
Frame.Data = CAN_OutData; /* Set pointer to OutData buffer */
DataFrameTxFlg = FALSE; /* Initialization of DataFrameTxFlg */
while(1)
{
//PITCounter_pre = PIT_CVAL0; /*get CAN1_SendFrame() function execute time*/
Error = CAN1_SendFrame(MyCANPtr, 5U, &Frame); /* Sends the data frame over buffer 0 */
//PITCounter_aft = PIT_CVAL0;
while (!DataFrameTxFlg) { /* Wait until data frame is transmitted */
}
}
Below is the test result:


There with 25us interval from the first CAN frame [after ACK field] to the next CAN frame [before Start of Frame].
I using the PIT timer to counter the CAN1_SendFrame() function execute time is about 9us.
From the CAN spec (CAN baud rate 1Mbps), there with below time interval between the two CAN frames interval:
[ACK Delimiter] 1us
[End of Frame] 7us
[CAN1_SendFrame() function execute time] 9us
[INTERFRAME SPACE]'s [Intermission] 3us
[INTERFRAME SPACE]'s [Bus IDLE] 1us
Total interval value added is 21us.



The actual interval between two CAN frame is 25ms, not 21us as expected.
I checked this issue with Kinetis product team with below feedback.
The TASD field will affect start of arbitration delay among TX message buffers (internal arbitration). The next message to be transmitted must be configured before CRC field to participate of arbitration process. Otherwise, the arbitration will start again in BusIdle.
So to optimize the transmit delay, new Tx MB must be configured before CRC field in the current transmission/reception. If the Tx Message is configured after IFLAG set from current transmission/reception, the next internal arbitration to select a Tx winner will happen in BusIdle.
The PE generated code is not optimized this way.
You can see in the main loop, it will wait for DataFrameTxFlg set then to configure TX buffer for next transmission. The DataFrameFlag is set in event code which in turn is executed in CAN ISR.
while(1)
{
Error = CAN1_SendFrame(MyCANPtr, 5U, &Frame); /* Sends the data frame over buffer 0 */
while (!DataFrameTxFlg) { /* Wait until data frame is transmitted */
}
}
Looking at the CAN ISR code, you can find it will scan through configured MBs for both TX and RX, with lowest number MB first, this will cause more delays if you configured more MBs or you configured the TX MB to higher number before it actually set the DataFrameTxFlg flag, so this means the internal arbitration could happen in BusIdle state, so this will increase time delay.
TxBufferMask = (LDD_CAN_TBufferMask)(DeviceDataPrv->TxBufferMask & StatusReg);
if (TxBufferMask != 0x00U) { /* Is Tx Buffer? */
BufferMask = 0x01U;
for (MBIndex=0x00U; MBIndex<MBIndexMax; MBIndex++) {
if ((TxBufferMask & BufferMask) != 0x00U) {
CAN1_OnFreeTxBuffer(DeviceDataPrv->UserData, MBIndex); /* Invoke user event */
}
BufferMask = (LDD_CAN_TBufferMask)(BufferMask << 0x01U);
}
}
RxBufferMask = (LDD_CAN_TBufferMask)(DeviceDataPrv->RxBufferMask & StatusReg);
if (RxBufferMask != 0x00U) { /* Is Rx Buffer? */
BufferMask = 0x01U;
for (MBIndex=0x00U; MBIndex<MBIndexMax; MBIndex++) {
if ((RxBufferMask & BufferMask) != 0x00U) {
CAN1_OnFullRxBuffer(DeviceDataPrv->UserData, MBIndex); /* Invoke user event */
}
BufferMask = (LDD_CAN_TBufferMask)(BufferMask << 0x01U);
}
}
Wish it helps.
Have a great day,
Ma Hui
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------