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.

Multiple CAN TX devices and Single CAN RX devices

Other Parts Discussed in Thread: HALCOGEN

Hello

I am using TMDSRM48USB. 
I am able to execute Single CAN TX and CAN RX program as shown in training. 
Now I want to transmit data from 2 separate CAN devices and other side will be CAN RX device.
I want to use priority between two TX devices which are transmitting information at every 1 sec and 2 sec respectively.
I am not able to figure out, what modifications I should do ?

  • Ankush,

    You could use DCAN3 on the second header on the USB stick for your 2nd CAN.
    You could use the FREERTOS port in HalCoGen and use it's timing to trigger the two different events (transmits from different CAN modules based on timing of the OS).

    -Anthony
  • Hi Anthony,

    I need to do exactly opposite.
    I want to transmit two CAN messages from two separate boards, and a single board which is only receiving CAN messages from the other two boards. Now at RX side I want to give priority to one of the TX board's message. For example- 1st TX board is transmitting at every 1 sec and 2nd TX board transmitting information every 3 sec. Thus at some regular intervals the 1st and 2nd TX boards will transmit CAN message at same moment which should be prioritised at RX board. I want to assign priority on RX board instead of TX boards.
  • Ankush,

    I'm not sure of this question.

    First - I assume your concern is that 1s and 3s intervals overlap, and so at ever 3s interval there will be 2 messages.
    But if the two transmitters share a CAN bus this isn't what will happen.

    The CAN bus arbitrates based on the message ID when there is a collision so one message with the highest priority ID will come first. This is really a CAN bus question though not an MCU question.

    Ok now you could try to make use of this to make the one message higher priority than the other but that won't work either because you cannot (without a lot of extra work) ensure that the messages will collide. Even with the exact same crystal frequency, the inaccuracy of the crystal will cause the timebase on one board to be off ever so slightly from the other.

    Try just setting a pin to toggle on one board at every 1s and 3s on the other. Then look at these two pins on an oscilloscope; trigger on the 3s interval pin. You won't see that there is a 'fixed' delay between the 3s and the 1s. Instead you'll see a slowly drifting 1s trigger over a period of say a couple minutes. This is because the crystals are not the *exact* same frequency. They can be very precisely close, but if not exact the error winds up accumulating and pretty soon it's enough so that you cannot guarantee a collision on the CAN bus.

    What I would do is:
    a) pick the message ID so that it follows your desired priority if possible.
    b) use an RTOS or RTOS like code.
    c) structure your code so that in the ISR you simply log the event (message received) and transfer the message data to RAM but don't process in the ISR. Instead post a semaphore indicating that the message has been received.
    d) use the RTOS to prioritize the processing of the events as you need.

    Of course this assumes that the processing takes a long time. If the processing is short - like << 1 message time on the CAN bus - this may all be a waste of effort because just processing the messages in the order they are received would be enough.