CAN001 identifier and data length issue

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
Not applicable
Hello everyone,

I have a problem in setting up the CAN-communication properly.
The "CAN001" app is used with 2 message objects for transmit (LMO1) and receive (LMO2). In both cases the acceptance mask is set to "0" and interrupts are enabled as well as connected to the "NVIC002" - app.
Everytime I send a message to the XMC4500, I want to change my destination address as well as my data. I've tried it in many different ways and found 2 issues with updating the MO-data-registers.

Firstly my destination address is fixed as well as my data. The length of my databytes is 6 but if I change it to 7 or 8, the message won't be received by my destination-tablet.
The other problem is changing the destination address in dependence on my source address. For example I get a message from 0x111 and it should be send to 0x112 with the same data and on the same CAN-port.

I attached my receive-routine below as well as the project via an archive file and hope, that somebody can help me.


best regards,
Sebastian



/* Check receive pending status in LMO2 */
if(CAN001_GetMOFlagStatus(&CAN001_Handle0,2,RECEIVE_PENDING) == CAN_SET)
{
/* Clear the flag */
CAN001_ClearMOFlagStatus(&CAN001_Handle0,2,RECEIVE_PENDING);
/* Read the received Message object and stores in variable CanRecMsgObj */
CAN001_ReadMsgObj(&CAN001_Handle0,&CanRecMsgObj,2);


TempMsgHandle.Identifier = 0x123;
TempMsgHandle.data[0] = 0xEF;
TempMsgHandle.data[1] = 0xEF;
TempMsgHandle.data[2] = 0xEF;
TempMsgHandle.data[3] = 0xEF;
TempMsgHandle.data[4] = 0xEF;
TempMsgHandle.data[5] = 0xEF;
TempMsgHandle.data[6] = 0xEF;
TempMsgHandle.data[7] = 0xEF;

TempMsgHandle.DataLength = 6; //7 and 8 is not possible
TempMsgHandle.IDExten =0;
TempMsgHandle.MsgObjEN = CAN001_ENABLE; // must be enabled
TempMsgHandle.MsgObjType = 1; // Tx=1 or Rx=0


CAN001_ConfigMsgObj(&CAN001_Handle0, &TempMsgHandle, 1);

CAN001_SendDataFrame(&CAN001_Handle0,1);

}

/* Check for Node error */
if(CAN001_GetNodeFlagStatus(&CAN001_Handle0,CAN001_ALERT_STATUS) == CAN_SET)
{

/* Clear the flag */
CAN001_ClearNodeFlagStatus(&CAN001_Handle0,CAN001_ALERT_STATUS);

}

0 Likes
2 Replies
User8570
Level 3
Level 3
Sebastian

I had been using this code and it works quite well

TempMsgHandle.Identifier = 0x180;
TempMsgHandle.DataLength = 4;
TempMsgHandle.IDExten =0; // 0 or 1
TempMsgHandle.MsgObjEN = CAN001_ENABLE; // must be enabled
TempMsgHandle.MsgObjType = (CAN_MsgType)1; // Tx=1 or Rx=0
TempMsgHandle.data[0]=0x5a;
TempMsgHandle.data[7]=0x5b;

CAN001_ConfigMsgObj(&CAN001_Handle1, &TempMsgHandle, 2);
CAN001_UpdateMODataRegisters(&CAN001_Handle1, 2, TempMsgHandle.DataLength, TempMsgHandle.data);
CAN001_SendDataFrame(&CAN001_Handle1, 2);



I think you are missing the following line:
CAN001_UpdateMODataRegisters(&CAN001_Handle1, 2, TempMsgHandle.DataLength, TempMsgHandle.data);


Cheers
0 Likes
Not applicable
Hello,

Thank you for the suggestion on the missing code line. I havn't set the correct data length.
My only problem is, when I change the identifier and data at the same time, the communication stops on the microcontroller side (I can't receive messages anymore until a power reset).

Do I have to wait (or check with a flag) until the message object is configured to update the data ?

Thanks for further help, I appreciate that


edit:
I found my problem ! Had a short circuit which caused the CAN to a strange malfunction. Now everything works fine with the new card.
0 Likes