Electronic – Question about communication using a controller area network (CAN)

canmbed

I am trying to make a test CAN loop on a breadboard and I want to try reading and writing to it using an mbed.

I found an example circuit and some test code for reading and writing from a CAN loop using mbed. However, if you look at the test code you can see that it writes from Pins 9 and 10 and reads from pins 29 and 30. From what I read about so far this is called writing to one node on the CAN loop and reading from another node.

CAN Handbook

But I am wondering if it is possible to take turns both reading and writing just from pins 29 and 30? I think this would be called writing and reading from the same node on the CAN loop. Unfortunately I don't think I can do that from what I read about so far. One source I found says…

Every node can see all messages from all other nodes but it can’t see its own

found on page 3 of CAN Primer: Creating Your Own Network.

I did try to test reading and writing from the same node by creating the circuit on a breadboard and changing the code from can1.write to can2.write. But the message was never received. I wonder if that is because my changed code is incorrect for reading/writing from one node.

But intuitively it seems to me that the message should be able to loop back to the sender. Since I don't know that much about CAN, I wanted to come here and see if anyone knew the answer to my question…

Can I make a test loop reading and writing from the same one node (just pins 29 and 30) on the mbed?

Best Answer

As you correctly pointed out that

Every node can see all messages from all other nodes but it can’t see its own

you can not read what you transmit. In other words, CAN is Half Duplex protocol.

There is a reason for that. CAN uses CSMA i.e. Carrier Sense Multiple Access. A node validates whatever it transmits to make sure that it still retains bus control (You can read more about "CAN Bus arbitration"). Technically, A node, or to be specific - CAN Controller, reads whatever it transmits, but it is not available for controller.

But there are certain controllers which has a feature of "Loop Back". It returns the message on successful transmission.