XMC4500 CAN Communication

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

cross mob
User11187
Level 2
Level 2
Dear All,

I started to develop my code to manage a CAN communication. (I'm not an expert). I used "CAN_EXAMPLE_XMC45" example with loopback mode and everything works well.
Now I want to send packet from the physical pins: I disabled loopback, I assigned P1.12 and P1.13 as receive and trasmit pins and I inserted in a loop the function CAN_NODE_MO_Transmit(&Request_Node_LMO_01_Config);
First time I execute it I have success but using an oscilloscope I dont' measure anything. From the second time the function return busy status.

1) Which is my mistake? Why I don't see anything on tx pin?
2) Why do I have busy status?

PS I'm using xmc4500 relax kit

Regards
0 Likes
8 Replies
DRubeša
Employee
Employee
First solution authored First like received
Hi ermes,

Have you maybe took a look at the "CAN_TRANSMITTER" example which is located in XMCLibs examples? It´s fairly similar example, but it´s built using XMCLibs and on the XMC4500 Hexagon board. However, due to the fact it´s not exactly the same example, can you provide us with your project files? I could take a look what is not properly set. One thing to notice though, you should have a receiver board to have continuous CAN communication. Problem is that you transmit message on the CAN bus but there is no CAN node to receive message. I guess that once you transmit the CAN message you don´t see "CAN_NSR1_TXOK" status flag to be set to "1". For this reason I believe you see busy status. But first I would like to see your project files so I can see what maybe the issue.

Best regards;
Deni
0 Likes
lock attach
Attachments are accessible only for community members.
User11187
Level 2
Level 2
Hi Deni,

Thank you for your support.

I started with CAN_EXAMPLE_XMC45 because it is really easy to understand.
I attached a zip file with the project I am using. As you can see, I copied the example project and I disabled loopback mode.

I understand I receive a busy error while there isn't a CAN communication, but why I don't see anything with my oscilloscope? Also interrupt functions are not called after transmit.

I also tried to short Can1Tx with Can2Rx and Can1Rx with Can2Rx (ie P1.12 -> 1.5 and 1.13 -> 1.4) and the function inside interrupt (CAN_NODE_GetStatus(&Request_Node) & XMC_CAN_NODE_STATUS_LAST_ERROR_CODE) returns 1

Regards
0 Likes
DRubeša
Employee
Employee
First solution authored First like received
Hi ermes,

hmmm, I noticed one "small", but very important detail when looking at the solution to your problem. Your board does not have a CAN transceiver. You can see that in the Board User Guide. For example. block diagram for your board:
2697.attach

and block diagram of the XMC4700/XMC4800 Relax kit with CAN transceiver in the blue circle.
2698.attach

So you can try to do implement a workaround (google "Is a CAN enabled microcontroller sufficient to drive a CAN bus") but you will have issues due to the no immunity to noise so it may not work, or it may work only on low speed/short distances. I would suggest to acquire some other board that has CAN transceiver already integrated. Of course you can always add CAN transceiver by yourself or you can try this quick&dirty hack that I mentioned.

Best regards,
Deni
0 Likes
User11187
Level 2
Level 2
Hi Deni,

Of course I have an external can tranceiver! I want to decouple firmware problems from hardware problems.
My firmware works with loopback, but I don't measure anything with oscilloscope:

1) If can pin are disconnected from the tranceiver I see TxD = 3.3V and RxD = 0V
2) when I transmit nothing happens
3) the same if I connect the tranceiver

Could you suggest me some tests to do in order to exclude hardware or firmware problems?

Thank you
0 Likes
DRubeša
Employee
Employee
First solution authored First like received
Hi ermes,

Aaaa OK in that case...shall we continue with debugging then 😉

I also tried to short Can1Tx with Can2Rx and Can1Rx with Can2Rx (ie P1.12 -> 1.5 and 1.13 -> 1.4)
. And this makes sense while the Board user manual for your board specifies the mentioned four pins as being available. However, in the example that you sent me, I see that another pins are selected for the receive node.

2699.attach

Can you please select P1.4 and P1.5 on the React Node side and try again? If this still doesn´t help, then please set the breakpoint right after transmit (right after following instruction: can_mo->can_mo_ptr-> MOCTR = CAN_MO_MOCTR_SETTXRQ_Msk | CAN_MO_MOCTR_SETTXEN0_Msk | CAN_MO_MOCTR_SETTXEN1_Msk and make an screenshot of your CAN_NSR registers for both nodes (TX and RX one). We will see what does the LEC bitfield states.

Best regards,
Deni
0 Likes
User11187
Level 2
Level 2
Hi Deni,

Following your suggestion I double checked can tranceiver: there was a hardware bug. Now can communication works correctly.
Just a question: using the transmit function once the xmc starts to send tx packets. How Can I control sending period?

Thanks a lot Deni
0 Likes
DRubeša
Employee
Employee
First solution authored First like received
Hi Matteo,

I´m not exactly sure what do you assume with "controlling sending period", but I guess you think of some way to repeatedly send messages on CAN bus using transmit function. For this purpose, I would suggest using a timer with the wanted period and in the timer´s interrupt routine sending CAN message. You can also use the interrupt services of other peripherals for sure e.g upon receiving a message on SPI/UART you send the message over CAN bus (this was just an example, I don´t know your exact application).

Best regards,
Deni
0 Likes
User9076
Level 1
Level 1
Hi,
normally a CAN controller transmits the message automatically until a valid acknowledgment is sent out from another node in CAN network. So connect a receiving node at your CAN network and it should work.
Regards
M.Schneiders
0 Likes