Hi,
I am using TM4C1294KCPDT for my project and am having problems receiving all the CAN messages.
I tried receive data using the FIFO. Here I am seeing a strange behavior. I configured FIFO with 16 objects, and using interrupt in No16 .
The messages are received from 1 to 16. But after that the next message(s) always land in 16. It does not use objects 1-15 afterwords. How to solve this issue? Basically I want a FIFO with 16 objects which can receive all the CAN messages.
I used the CANStatusGet API with the CAN_STS_NEWDAT parameter after read out of the FIFO but before accept more data to verify that the NEWDAT bits are clear in objects 1-15.
If I slow down the transmit speed delay 7ms every 16 frames from the transmittor, it works OK.
I found there are words in datasheet:
Until all of the preceding message objects have been released by clearing the NEWDAT bit, all further messages for this FIFO buffer are written into
the last message object of the FIFO buffer and therefore overwrite previous messages.
But when I received the interrupt, the Data in No16 message box was overwrite by the last data.
It seems that the cpu is slow than the CAN core. I closed all the interrupt except can, but the phenomenon is the same.
I used the same code in the CPU(TMS570LS3713), it worked fine but in TM4C1294 the data was overwritten.
Now, My Init code:
void CanRecvMsgBoxInit()
{
tCANMsgObject sCANMessage = {0};
uint32_t i = 0;
/* mailbox 1-16 FIFO recv, 1-15 disable interrupt, 16 enable interrupt */
sCANMessage.ui32MsgID = 0x00360000;
sCANMessage.ui32MsgIDMask =0x00FF0000;
sCANMessage.ui32Flags = (MSG_OBJ_USE_ID_FILTER | MSG_OBJ_FIFO|\
MSG_OBJ_EXTENDED_ID);
sCANMessage.ui32MsgLen = 8;
for(i=canMESSAGE_BOX1;i<canMESSAGE_BOX16;i++)
{
CANMessageSet(CAN0_BASE, i, &sCANMessage, MSG_OBJ_TYPE_RX);
}
/* mailbox 16 FIFO last msg box, enable interrupt */
sCANMessage.ui32Flags = (MSG_OBJ_RX_INT_ENABLE | \
MSG_OBJ_USE_ID_FILTER | \
MSG_OBJ_EXTENDED_ID);
sCANMessage.ui32MsgLen = 8;
CANMessageSet(CAN0_BASE, canMESSAGE_BOX16, &sCANMessage, MSG_OBJ_TYPE_RX);
/* mailbox 17 recv last frame,enable interrupt*/
sCANMessage.ui32MsgID = 0x00370000;
sCANMessage.ui32MsgIDMask = 0x00ff0000;
sCANMessage.ui32Flags = (MSG_OBJ_RX_INT_ENABLE | \
MSG_OBJ_USE_ID_FILTER | \
MSG_OBJ_EXTENDED_ID);
CANMessageSet(CAN0_BASE, canMESSAGE_BOX17, &sCANMessage, MSG_OBJ_TYPE_RX);
return ;
}
Recv read message code:
uint32_t CanRecvPkt(uint8_t *pucDataBuf, uint32_t ui32Status)
{
uint32_t ulRet = 0;
uint32_t i = 0;
tCANMsgObject sCANMessage;
uint32_t ui32Flags = 0;
uint8_t pucMsgData[8] = {0};
for(i=canMESSAGE_BOX1;i<canMESSAGE_BOX18;i++)
{
memset(&sCANMessage, 0, sizeof(tCANMsgObject));
sCANMessage.pui8MsgData = pucMsgData;
CANMessageGet(CAN0_BASE, i, &sCANMessage, 1);
ui32Flags = sCANMessage.ui32Flags;
if(ui32Flags & MSG_OBJ_NEW_DATA)
{
memcpy(pucDataBuf+(i-1)*8,pucMsgData,8);
}
}
return 0;
}
Can anybody tell me why this happened, how to fix it.