This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS570LS1227: CAN Network with 2 TMS570LS1227s and a TM4C123GH6PM

Part Number: TMS570LS1227
Other Parts Discussed in Thread: TM4C123GH6PM, TMS570LS1224

Hi all, 

I'm fairly new to CAN protocol and I'm having a hard time implementing a CAN network and would appreciate all the help I can get with my project My objective is to setup/configure 3 nodes of a CAN network. My nodes are as follows: 

1) Node 1 = A TMS570LS1227 with a standard ID of 0x1,    MSG_OBJ1 used for Transmitting, MSG_OBJ2 & MSG_OBJ3 used for Receiving

2) Node 2 =  A TMS570LS1227 with a standard ID of 0x2,  MSG_OBJ1 used for Transmitting, MSG_OBJ2 & MSG_OBJ3 used for Receiving

3) Node 3 = A TM4C123GH6PM with a standard ID of 0x3,  MSG_OBJ1 used for Transmitting, MSG_OBJ2 & MSG_OBJ3 used for Receiving

I've done my research on how CAN protocol works and I'm aware of how the Message Box priority and Message Identifier priority works. Each Node is using its Message Box Object 1 to transmit and using Message Box Objects 2 and 3 to receive messages from the other two. 

I'm using interrupts to indicate TX & RX messages on each Node from the other nodes. I've also set up the filtering mask with 0x07FF to use the 11-bits to filter messages from the CAN bus, for each node's receiving message box object. 

Based on my understanding and setup above, when I initialize & configure each node on the network, I'm expecting Node 1 to win the arbitration process first and transmit its message, while Node 2 and 3 receive the message. Next, I expect Node 2 to win the arbitration against Node 3, while Node 1 and Node 3 receive. Finally, Node 3 transmits and the other nodes listen and receive. 

The following are the issues I've faced with the settings I've described above:

1) The communication is not consistent, i.e. I don't always have all the expected messages in each Node's receive Message Object. What I mean by that: Sometimes Node 3 will have the transmitted message of Node 2 but will not have the message transmitted by Node 1, Node 2 will have the message transmitted by Node 3, but not the message transmitted by Node 1, and Node 2 will have Node 1's message, but not Node 3's transmitted message - IDK why this is happening. Any ideas? 

2) When I look at the CAN bus on the Logic Analyzer, I get errors stating there is bit-stuffing and ACK errors. How do you fix the Acknowledgment Error? i.e. How do I configure my receiving Node's to acknowledge that they have received the transmitted message? And I thought Bit-stuffing is taken care of by the CAN controller? Or am I misinformed? Please advise. 

3) My current code works with any two of the Nodes in the network, but as soon as I have all 3 nodes in the network, the behavior of the bus is unpredictable.

I've read through the forum and tried to find a similar problem to mine and couldn't find anything useful, anywhere. As I mentioned above, this my first time working on CAN and would appreciate any help that I can get and I'm happy to share my code for each node with you. Looking forward to all your replies. Thank you for your time. 

Cheers. 

  • Hello,

    Three CAN nodes can access the CAN bus at any time, if it is idle. If 3 nodes want to communicate at the same moment, the message with the highest priority wins the bus arbitration and gets the right to transmit. The CAN identifier (CAN ID) as part of the message indicates the priority. The lower the number of the CAN ID, the higher the priority. In your design, Node 1 has the highest priority, and Node 3 has the lowest priority.

    CAN bus access conflicts are resolved by a bit-wise arbitration of the CAN ID. All connected nodes observe the bus level bit-for-bit. There are two bus levels: dominant and recessive. The dominant level overwrites the recessive level. In CAN's bit stream, the MSB of each byte is transmitted first.

    1. Can you use different mask for message box 2 and 3 to receive messages from different node? For example, Node1-mailbox2 is to receive message from Node 2, and mailbox3 to receive the message from Node 3. I am wondering if the message in mailbox  is overwritten.

    2. The bit stuff error and ACK are expected. In your design, your use 11-bit CAN ID. More than 5 bits of the ID is zero for Node1/2/3. The arbitrated nodes don't get ACK.

  • Hi QJ, 

    Thank you for your reply. I am indeed using different mailboxes on each node to receive messages from the other nodes, i.e. on Node 1, Message Object 1 is used to transmit Node 1's messages, Message object 2 is used to receive Node 2's messages and Message object 3 is used to receive Node 3's messages. 

    Despite using different mailboxes for each node and setting the Mask bits to 0x7FF for each receiving mailbox,  I'm still not getting all the messages in my mailboxes. 

  • Hello, 

    If UMask is set, the mask bits are used for acceptance filtering. If MASK bit is 0x7FF, only the incoming message with matched ID is copied to message RAM.

    If Node1 TX message ID is 0x1, Node 2 will not receive this message if the ID of Node 2 RX message objects are not 0x1. 

    This is the diagram for TX and RX:

    Node 1: MailBox1 ID=1, TX

                 MailBox2 ID=2, RX -- from Node 2

                 MailBox3 ID=3, RX -- from Node 3

    Node 2: MailBox1 ID=2, TX

                 MailBox2 ID=1, RX -- from Node 1

               MailBox3 ID=3, RX -- from Node 3

    Node 3: MailBox1 ID=3, TX

                 MailBox2 ID=2, RX -- from Node 2

               MailBox3 ID=1, RX -- from Node 1

  • Hi QJ, 

    Thank you for your reply. I've set up mailboxes exactly how you suggested in your reply and I'm surprised at how it is functioning.

    Anyhow, here is an image of my hardware setup for the CAN network. Maybe something wrong here, please advise. I can share my code if you would like to have a look. 

    Looking forward to your reply. Thank you for your time. 

    Cheers, 

    Junaid Khan

  • Your setup looks good. I assume that CAN_H/L on left side and right side of Node 2 are from the same CAN transceiver, and three nodes use the same baudrate. 

  • Yes, and they all are configured to the baudrate of 500K.

  • Did you try the lower baudrate (for example 50k, 100k etc) since the wires can pick up noise which affects the transmission? 

  • I lowered the baudrate and the problem still isn't fixed. The three nodes are not consistent with their transmissions and receiving messages when in the same network.

  • I think that the node can receive the messages from other two nodes most of the time, and the problem only happens sometimes.

  • How do I tackle this issue?

    I tried my setup with 2 TMS570LS1227s and a TMS570LS1224 - had the same problem.

  • Can you share the code?