Search code examples
can-busdivider

Switching between two CAN messages


I have a robot that is moving when it received the CAN message. So, on the robot side I have only one Port for CAN message receiving but I am giving the CAN message from two difference controller, one is from Arduino that receives message from a remote controller and the 2nd is from my laptop thatbconnect with a CAN to UsB cable. What i want to switch between these two messages. For now i am always changing the CAN cable manually. I want to know that is there any CAN switch available or any other way to switch???

Now I am trying to changing the port everytime.


Solution

  • Physical connection

    All you need is to connect all devices in one CAN network. Note that only two terminators (resistors) shall be there. Your network should look like this:

    +---------+--------+---------+--------+ CAN_H
    [120Ω]    |        |         |     [120Ω]
    +----------+--------+---------+-------+ CAN_L
              ||       ||        ||       
             Robot   Arduino   Laptop
    

    Communication

    Option 1

    You might configure each device in a different way, for example:

    • Laptop sends frames with CAN ID = 0x100 (,0x101, 0x102, ... etc if you need more CAN IDs)
    • Arduino sends frames with CAN ID = 0x200 (,0x201, 0x202,...)
    • Robot listens to all CAN IDs transmitted by either node (Laptop and Arduino) and is programmed to act accordingly.

    Option 2

    • Laptop and Arduino send the same frames (CAN IDs are the same) and simulating the same controlling CAN node.
    • Robot listens to all CAN IDs transmitted by controlling node (either Laptop or Arduino).
    • No need to update Robot code in this case.

    Warning

    If both Arduino and laptop would try to control your robot at the same time, it would get duplicated or requests in contradiction. Also it might cause errors on CAN network. I strongly recommend to avoid situations with two devices simulating the same CAN node at the same time as it might cause undefined behavior, CAN devices go to ERROR state or even damage to your robot.

    Some Knowledge Sources

    Other Comments

    This question is not code related, so it does not belong to Stackoverflow (check other spaces for more suitable one).