CAN001 App

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

cross mob
Not applicable
When I want to use CAN Node number X from the XMC4500 in my application, how do I know that I really use CAN Node X?
As an example I want to use CAN Node 2, that means that I have to add in the project 3 instances of CAN001 and then should I use CAN001/2 which is CAN Node 2?
0 Likes
24 Replies
oreste
Employee
Employee
Welcome! 50 replies posted 25 replies posted
Could you explain why you need exactly Can Node 2 ?
0 Likes
Not applicable
On the XMC-HiLight Board from Hitex, P1.9 and P1.8 are more easy to acces than the pins from "satellite connector". I have to connect a CAN Transceiver to the board and this pins belongs to CAN Node 2.
0 Likes
Not applicable
😄
dorinjj wrote:
On the XMC-HiLight Board from Hitex, P1.9 and P1.8 are more easy to acces than the pins from "satellite connector". I have to connect a CAN Transceiver to the board and this pins belongs to CAN Node 2.


I found my answer 😄 . I will use a single instance and I will choose which pin to be used for CAN Transmit and which pin to be used for CAN Receive, without to care which node is used.
0 Likes
Not applicable
I read from datasheet of the XMC4500 that it has 64 message objects (MO) and I have some questions regarding this:
1. It is posible to use the same MO for transmiting and receiving data?
2. How can I add a new MO into the list of "Logical message object selection" (LMOx) from "Message Configuration" tab? For example I wish to configure a number of x MO (0<65) for transmiting/receiving data. I know that each MO that will be used has to be asigned to a message list, and that objects from that list will be used for sending and receiving data by a CAN Node. LMO is derived from abbrevation of Logical or List Message Object?
Thank You.
0 Likes
Not applicable
I have succed in sending multiple LMO with different IDs, but they are limited on 10 per CAN001 Instance (CAN Node).
My question is how can I attach all message objects to the same message object list for being used by the respective CAN Node?
Thank You.
0 Likes
Not applicable
I have a new problem and I'm not sure if this could be solved.
I want to extract the ID of any Remote Frames that arrive on my XMC board.
For doing this I setup a Logical Message Object with "Enable Receive Enable" activated, (LMO1) as a "Transmit Message Object" because this type can receive & answer to Remote Frames; IDE: length: 11 bit, value: 7FF (doesn't matter); Standard Acceptance Mask: 0 because in this way I will get an interrupt every time when I receive a Remote Frame with any ID.
I tried to extract the ID of the received Remote Frame and it doesn't work:

//ISR
void EventHandler_CAN001_0()
{
CAN001_ReadMsgObj(&CAN001_Handle0, &TempMsgHandle, 1);
//toggle led
}

If I check with the debugger for TempMsgHandle.Identifier when the led is toggled, I get a value of 0x00.. and if I check for CAN001_MessageHandle0_1.Identifier, I get the value of LMO1 ID which in this case is 0x7FF.
I'm not sure if this could be done, but maybe I could get acces to one of the hardware registers for getting this ID that belongs to Remote Frame.
Is that possible or should I use something else for copying the ID's of any Remote Frame to a variable?
Thank You.
0 Likes
oreste
Employee
Employee
Welcome! 50 replies posted 25 replies posted
dorinjj wrote:
I read from datasheet of the XMC4500 that it has 64 message objects (MO) and I have some questions regarding this:
1. It is posible to use the same MO for transmiting and receiving data?
2. How can I add a new MO into the list of "Logical message object selection" (LMOx) from "Message Configuration" tab? For example I wish to configure a number of x MO (0<65) for transmiting/receiving data. I know that each MO that will be used has to be asigned to a message list, and that objects from that list will be used for sending and receiving data by a CAN Node. LMO is derived from abbrevation of Logical or List Message Object?
Thank You.

1) Yes
2) Due to a performance limitation in Dave, we limited the number of message object that you can configure in the GUI to 10. From hardware point of view you can assign all MO to the same node. Regarding how to do it I suggest you to give a look to the function: CAN001_lAllocateMOtoNodeList.
You can hack Dave to allocate all MO basically in two ways:


  • CAN001_Handle0_NODE to get the pointer to the node allocated to your CAN001 instance and configure at register level how it is done in CAN001_lAllocateMOtoNodeList.
  • Change directly CAN001_lAllocateMOtoNodeList by modifing the template of code generator in order to preserve your modification across the code generation.
    In order to change the template you have to enable remove the filter that hide the model folder inside the Dave folder. See attached picture
18.attach

Edit the template CAN001c.jet see below picture: (it is quite easy)
452.attach
Best Regards
Oreste
0 Likes
oreste
Employee
Employee
Welcome! 50 replies posted 25 replies posted
dorinjj wrote:
I have succed in sending multiple LMO with different IDs, but they are limited on 10 per CAN001 Instance (CAN Node).
My question is how can I attach all message objects to the same message object list for being used by the respective CAN Node?
Thank You.


See my previous answer.
0 Likes
oreste
Employee
Employee
Welcome! 50 replies posted 25 replies posted
dorinjj wrote:
I have a new problem and I'm not sure if this could be solved.
I want to extract the ID of any Remote Frames that arrive on my XMC board.
For doing this I setup a Logical Message Object with "Enable Receive Enable" activated, (LMO1) as a "Transmit Message Object" because this type can receive & answer to Remote Frames; IDE: length: 11 bit, value: 7FF (doesn't matter); Standard Acceptance Mask: 0 because in this way I will get an interrupt every time when I receive a Remote Frame with any ID.
I tried to extract the ID of the received Remote Frame and it doesn't work:

//ISR
void EventHandler_CAN001_0()
{
CAN001_ReadMsgObj(&CAN001_Handle0, &TempMsgHandle, 1);
//toggle led
}

If I check with the debugger for TempMsgHandle.Identifier when the led is toggled, I get a value of 0x00.. and if I check for CAN001_MessageHandle0_1.Identifier, I get the value of LMO1 ID which in this case is 0x7FF.
I'm not sure if this could be done, but maybe I could get acces to one of the hardware registers for getting this ID that belongs to Remote Frame.
Is that possible or should I use something else for copying the ID's of any Remote Frame to a variable?
Thank You.


Reading the HW reference manual it looks like that it is not possible but I am contacting one of my collegue to double check it.

Best Regards
Oreste
0 Likes
Not applicable
Hello, I wish to check if the CAN bus is free for transmiting messages before starting to transmit my message on it. After usage of CAN001_SendDataFrame function, if the returned value is different from DAVEApp_SUCCESS it means that the message was not sent, but I'm not sure and I have some questions.

1. If the message was not sent, it will be transmited automaticaly and immediately when the CAN bus will become free or do I have to try for retransmiting this message "manually" again?
2. Are here any other methods for checking if CAN bus is free? Maybe looking after a flag from register x of CAN Node x?

Thank You.
0 Likes
oreste
Employee
Employee
Welcome! 50 replies posted 25 replies posted
dorinjj wrote:
I have a new problem and I'm not sure if this could be solved.
I want to extract the ID of any Remote Frames that arrive on my XMC board.
For doing this I setup a Logical Message Object with "Enable Receive Enable" activated, (LMO1) as a "Transmit Message Object" because this type can receive & answer to Remote Frames; IDE: length: 11 bit, value: 7FF (doesn't matter); Standard Acceptance Mask: 0 because in this way I will get an interrupt every time when I receive a Remote Frame with any ID.
I tried to extract the ID of the received Remote Frame and it doesn't work:

//ISR
void EventHandler_CAN001_0()
{
CAN001_ReadMsgObj(&CAN001_Handle0, &TempMsgHandle, 1);
//toggle led
}

If I check with the debugger for TempMsgHandle.Identifier when the led is toggled, I get a value of 0x00.. and if I check for CAN001_MessageHandle0_1.Identifier, I get the value of LMO1 ID which in this case is 0x7FF.
I'm not sure if this could be done, but maybe I could get acces to one of the hardware registers for getting this ID that belongs to Remote Frame.
Is that possible or should I use something else for copying the ID's of any Remote Frame to a variable?
Thank You.


oreste wrote:
Reading the HW reference manual it looks like that it is not possible but I am contacting one of my collegue to double check it.

Best Regards
Oreste


I confirm it is not possible. You shall use one MO per each message identifier.
0 Likes
oreste
Employee
Employee
Welcome! 50 replies posted 25 replies posted
dorinjj wrote:
Hello, I wish to check if the CAN bus is free for transmiting messages before starting to transmit my message on it. After usage of CAN001_SendDataFrame function, if the returned value is different from DAVEApp_SUCCESS it means that the message was not sent, but I'm not sure and I have some questions.

1. If the message was not sent, it will be transmited automaticaly and immediately when the CAN bus will become free or do I have to try for retransmiting this message "manually" again?
2. Are here any other methods for checking if CAN bus is free? Maybe looking after a flag from register x of CAN Node x?

Thank You.

Bus Arbitration is done automatically in HW. Check 18.2.1 Addressing and Bus Arbitration
in reference manual. So I don't think this is the problem.

Could you write me which error is reported ?

Regards
Oreste
0 Likes
Not applicable
The answer to my question is that "The message will be retransmited automaticaly", BUT I observed something else when I try to send a message and while the XMC board is not connected to CAN.

I made 2 tests:

Test 1
//...
Status=CAN001_SendDataFrame(&CAN001_Handle0,1);
if(Status!=DAVEApp_SUCCESS){
//set LED; *** BREAKPOINT ***
}
//...

Result Test 1:
- Status=0x0;
- content of if statement is not executed
- the message is sent after connection of XMC board to CAN



Test 2
//...
// 1st if statement
Status=CAN001_SendDataFrame(&CAN001_Handle0,1);
if(Status!=DAVEApp_SUCCESS){
//set LED; *** BREAKPOINT ***
}

//2nd if statement
Status=CAN001_SendDataFrame(&CAN001_Handle0,1);
if(Status!=DAVEApp_SUCCESS){
//set LED; *** BREAKPOINT ***
}
//...

Result Test 2:
- Status=0x4; (CAN001_MO_BUSY = 4U from CAN001.h)
- content of 2nd if statement is executed
- the message is sent after connection of XMC board to CAN


CAN001_SendDataFrame function returns an answer from 5:
- DAVEApp_SUCCESS: if message is transmitted
- CAN001_MO_NOT_ACCEPTABLE: If MO is not a transmit message object
- CAN_MO_NOT_FOUND: if MO is not a part of node list
- CAN001_MO_BUSY: if MO is currently transmitting a mesage
- CAN001_MSGOBJ_DISABLED: If MO is Disabled

* An error like "BUS_FAULT" or "BUS_BUSY" it could be very usefull, but for "BUS_BUSY" I think that only one who knows is the CAN controller.


My questions are:
- Why CAN001_SendDataFrame returns DAVEApp_SUCCESS in Test 1? The XMC board is not connected to CAN, the message is not sent and Status is 0x0 wich means a succesful transmission.
- How could I check if the message was sent (without using "Transmit Interrupt")?

Thank You.
0 Likes
Not applicable
dorinjj wrote:

How could I check if the message was sent (without using "Transmit Interrupt")?


Using "Transmit Interrupt":
-if the message is not sent: CAN001_GetMOFlagStatus(&CAN001_Handle0,1,TRANSMIT_PENDING) returns 0x00
-when the message is sent: CAN001_GetMOFlagStatus(&CAN001_Handle0,1,TRANSMIT_PENDING) returns 0x01
0 Likes
Not applicable
Mrs,

We have here two XMC 4500 with two communication boards , and now our development is focused on half duplex communication between these two kits via CAN modules.
Well, in loopback mode it works pretty well, but now connecting the kits one each other, what we noticed is that even transmission isn't occurring. To attest that, in our code we are using the funtion GetMOFlagStatus which remains with transmit pending status never concluding transmission.

The code is below:

Status = CAN001_SendDataFrame(&CAN001_Handle0,1);
StatusTX = CAN001_GetMOFlagStatus(&CAN001_Handle0,1,TRANSMIT_PENDING);
}
while(StatusTX != 1) // when transmission occurs, StatusTX = 1
{
StatusTX = CAN001_GetMOFlagStatus(&CAN001_Handle0,1,TRANSMIT_PENDING); // never leaves this loop.
}
CAN001_ClearMOFlagStatus(&CAN001_Handle0,1,TRANSMIT_PENDING);


Could someone help us to find a path through these issues?
Regards,
Celio
0 Likes
oreste
Employee
Employee
Welcome! 50 replies posted 25 replies posted
CelioSordi wrote:
Mrs,

We have here two XMC 4500 with two communication boards , and now our development is focused on half duplex communication between these two kits via CAN modules.
Well, in loopback mode it works pretty well, but now connecting the kits one each other, what we noticed is that even transmission isn't occurring. To attest that, in our code we are using the funtion GetMOFlagStatus which remains with transmit pending status never concluding transmission.

The code is below:

Status = CAN001_SendDataFrame(&CAN001_Handle0,1);
StatusTX = CAN001_GetMOFlagStatus(&CAN001_Handle0,1,TRANSMIT_PENDING);
}
while(StatusTX != 1) // when transmission occurs, StatusTX = 1
{
StatusTX = CAN001_GetMOFlagStatus(&CAN001_Handle0,1,TRANSMIT_PENDING); // never leaves this loop.
}
CAN001_ClearMOFlagStatus(&CAN001_Handle0,1,TRANSMIT_PENDING);


Could someone help us to find a path through these issues?
Regards,
Celio


Hi Celio,

It looks like that there is something else clearing the bit.
If you have derived your code from CAN examples and you kept the interrupt routine please remove from the interrupt routine the code that clear this bit.
In fact this could explain the different behaviour when you use in the same board with loopback mode as well.


Best Regards
Oreste
0 Likes
oreste
Employee
Employee
Welcome! 50 replies posted 25 replies posted
CelioSordi wrote:
Mrs,

We have here two XMC 4500 with two communication boards , and now our development is focused on half duplex communication between these two kits via CAN modules.
Well, in loopback mode it works pretty well, but now connecting the kits one each other, what we noticed is that even transmission isn't occurring. To attest that, in our code we are using the funtion GetMOFlagStatus which remains with transmit pending status never concluding transmission.

The code is below:

Status = CAN001_SendDataFrame(&CAN001_Handle0,1);
StatusTX = CAN001_GetMOFlagStatus(&CAN001_Handle0,1,TRANSMIT_PENDING);
}
while(StatusTX != 1) // when transmission occurs, StatusTX = 1
{
StatusTX = CAN001_GetMOFlagStatus(&CAN001_Handle0,1,TRANSMIT_PENDING); // never leaves this loop.
}
CAN001_ClearMOFlagStatus(&CAN001_Handle0,1,TRANSMIT_PENDING);


Could someone help us to find a path through these issues?
Regards,
Celio


Hi Celio,

It looks like that there is something else clearing the bit.
If you have derived your code from CAN examples and you kept the interrupt routine please remove from the interrupt routine the code that clear this bit.
In fact this could explain the different behaviour when you use in the same board with loopback mode as well.


Best Regards
Oreste
0 Likes
Not applicable
oreste wrote:
Hi Celio,

It looks like that there is something else clearing the bit.
If you have derived your code from CAN examples and you kept the interrupt routine please remove from the interrupt routine the code that clear this bit.
In fact this could explain the different behaviour when you use in the same board with loopback mode as well.


Best Regards
Oreste



Hello Oreste,
Inside of CAN001_GetMOFlagStatus I can observe that the condition always goes into else routine:

if((CAN_MOxRegs->MOSTAT & (uint32_t)NewMsgStatus) != 0) // since NewMsgStatus is TRANSMIT_PENDING defined by 2U.
{
Status = CAN_SET; // value = 1
}
else
{
Status = CAN_RESET; // value = 0


In other words, it never sets the CAN node. So, the function CAN001_GetMOFlagStatus is always returning 0.
Looking in variables box (debug session) I couldn't find the value of MOSTAT register, but we know that NewMsgStatus is 2U (definition of TRANSMISSION_PENDING). So probably our problem is with MOSTAT register who doesn't have the properly value to set the transmission.

We are using the functions described in Help Contents >> Dave Apps >> CAN001
About a routine clearing the bit, I couldn't find this interruption in our code.
Regards,
0 Likes
oreste
Employee
Employee
Welcome! 50 replies posted 25 replies posted
CelioSordi wrote:
Hello Oreste,
Inside of CAN001_GetMOFlagStatus I can observe that the condition always goes into else routine:

if((CAN_MOxRegs->MOSTAT & (uint32_t)NewMsgStatus) != 0) // since NewMsgStatus is TRANSMIT_PENDING defined by 2U.
{
Status = CAN_SET; // value = 1
}
else
{
Status = CAN_RESET; // value = 0


In other words, it never sets the CAN node. So, the function CAN001_GetMOFlagStatus is always returning 0.
Looking in variables box (debug session) I couldn't find the value of MOSTAT register, but we know that NewMsgStatus is 2U (definition of TRANSMISSION_PENDING). So probably our problem is with MOSTAT register who doesn't have the properly value to set the transmission.

We are using the functions described in Help Contents >> Dave Apps >> CAN001
About a routine clearing the bit, I couldn't find this interruption in our code.
Regards,



Hi
I have implemented a small example:

  • 2 Boards connected by cable
  • one board transmit as fast as possible 4 bytes
  • one board receiving and checking that received_value= old_value +1
  • speed 1Mbit/sec
I didn't detected any issue.

Unfortunatly in this forum there is not enough space to attach a the full project. You can contact me by email at .@infineon.com. so I can send you the two projects.

In the meatime I can attach the two main.c.

Receive main.c

 #include   //SFR declarations of the selected device
#include //Declarations from DAVE3 Code Generation
/** @brief Data structure where the received CAN message is transferred to */
CAN001_MessageHandleType CanRecMsgObj;
int main(void)
{
volatile status_t status; // Declaration of return variable for DAVE3 APIs
unsigned int old_value=0;
DAVE_Init(); // Initialization of DAVE Apps
/* Switch on LED Pin 3.9 t indicate that the requested message is received*/
IO004_ResetPin(IO004_Handle0);
CAN001_ClearMOFlagStatus(&CAN001_Handle0,1,RECEIVE_PENDING);
while(1)
{
while (CAN_SET != CAN001_GetMOFlagStatus(&CAN001_Handle0,1,RECEIVE_PENDING));
/* Clear the flag */
CAN001_ClearMOFlagStatus(&CAN001_Handle0,1,RECEIVE_PENDING);
/* Read the received Message object and stores in variable CanRecMsgObj */
status=CAN001_ReadMsgObj(&CAN001_Handle0,&CanRecMsgObj,1);
//Detect if data is not sequential
if (*((unsigned int *)CanRecMsgObj.data) != old_value +1 ) {
IO004_SetPin(IO004_Handle0);
while(1);
}
else {
old_value=*((unsigned int *)CanRecMsgObj.data);
}
if (!(old_value % 10000)) {
IO004_TogglePin(IO004_Handle0);
}
}
return 0;
}






Transmit main.c

/** Inclusion of header file */
#include

int main(void)
{
unsigned int counter=1;

// ... Initializes DAVE Apps configurations ...
DAVE_Init();

while(1)
{
CAN001_ClearMOFlagStatus(&CAN001_Handle0,1,TRANSMIT_PENDING);
/* Update data value to be transmitted by Node "Request" in message object 1 (LM01) */
CAN001_UpdateMODataRegisters(&CAN001_Handle0,1,4,&counter);
CAN001_SendDataFrame(&CAN001_Handle0,1);
while (CAN_SET != CAN001_GetMOFlagStatus(&CAN001_Handle0,1,TRANSMIT_PENDING));
counter++;
}
}


Regards
Oreste Bernardi
0 Likes
Not applicable
Hello Oreste,
It's working now. Thank you.

*****

Well, thinking of our scenario, we have an issue in potential concerning of TX and RX of LMO's.

Let me explain:
As I could notice, a LMO configured as RX only will receive or update its fields if Identifier field matches with the received message identifier. In other words, if the frame belongs to this specific LMO.
Well, MultiCAN can support 64 LMO's. To us, 64 LMO's (being 32 TX and 32 RX) is not sufficient considering our database of messages.

We tried to use an acceptance mask allowing sort of messages (defined by mask) be stored in LMO's. But it is not working, at principle.
How can I recover a message in the CANBus even we don't have logical message objects enough to cover all identifiers?

Regards,
Celio
0 Likes
Not applicable
CelioSordi wrote:
Hello Oreste,
It's working now. Thank you.

*****

Well, thinking of our scenario, we have an issue in potential concerning of TX and RX of LMO's.

Let me explain:
As I could notice, a LMO configured as RX only will receive or update its fields if Identifier field matches with the received message identifier. In other words, if the frame belongs to this specific LMO.
Well, MultiCAN can support 64 LMO's. To us, 64 LMO's (being 32 TX and 32 RX) is not sufficient considering our database of messages.

We tried to use an acceptance mask allowing sort of messages (defined by mask) be stored in LMO's. But it is not working, at principle.
How can I recover a message in the CANBus even we don't have logical message objects enough to cover all identifiers?

Regards,
Celio


I used in my project a LMO with ID = 7FF (the lowest priority message for Standard Frames) and Acceptance Mask = 0. In this way is possible to store in that LMO any Data Frame.
0 Likes
oreste
Employee
Employee
Welcome! 50 replies posted 25 replies posted
Hi,
dorinjii is right.
You can find more details in this chapter of reference manual.

18.3.6.1 Receive Acceptance Filtering


Best Regards
Oreste


0 Likes
Not applicable
Hello Oreste and dorinjii.
I have been reading this reference manual lately. As I imagine, I should use acceptance mask to allow receive frames regardless its Identifier. But, the problem was I use for mask 3FFFFFFF.

Now it's working.
Thank you, dorinjii and Oreste.

Celio
0 Likes
Not applicable
Hello.
Stupid question, but does it work for you if you set up an acceptance mask that only the messages with this identifier are handled as described above?
I want to set up an LMO-RX which only receives one ID (the heartbeat of the CAN-device) and followed by this I want to put a NVIC-Handler.
In the moment that doesn't work for me so I use this workaround inside a NVIC-Handler which uses a LMO-RX receiving all CAN-IDs:
if(CanRecMsgObj.Identifier==0x72C) ...

Thanks for your opinion.
0 Likes