0

So I've been working on a project over the last few month using homemade boards on a CAN bus. It's working well when using a board as a sender and another one as receiver. I now have 3 boards and on which there are several sensor. My purpose here is to be able for every board to share data and use other from another mcu.

An quick overview of the project for a better understanding : I'm trying to automate a RC plane.

MCU-1 : Potentiometers + GPS

MCU-2 : 1 accelerometer + 1 barometer

MCU-3 : 1 differential pressure transmitter + 1 radio transmitter

I'd like to be able, for MCU-1 to receive and use data from MCU-2 and in the same time to transmit data to MCU-3. (They both have many more components and tasks to achieved, that why I don't have all the sensors on the same board)

I don't think it's important but MCU1 and 3 are ATmega328p (the one from the nano board) and MCU2 is an ATmega2560

My question : Is it possible ? I mean is it possible to have a MCU running as a Sender and a Receiver at the same time ? and how to do it ? :)

Also is it possible to have a MCU running as a receiver, let's say 90% of the time and sender 10% (or after an update) ? If the first situation isn't possible this one could be a solution for my project.

Thank you

Undeadguy

1

Yes, it is possible.

CAN is a multi-master serial bus standard for connecting Electronic Control Units [ECUs] also known as nodes. Two or more nodes are required on the CAN network to communicate. The complexity of the node can range from a simple I/O device up to an embedded computer with a CAN interface and sophisticated software.

-- Wikipedia

You should understand how collision detection works in a multi-master CAN bus and ensure that you implement it (or it is implemented in your chosen CAN library) to allow reliable operation:

The CAN specifications use the terms "dominant" bits and "recessive" bits where dominant is a logical 0 (actively driven to a voltage by the transmitter) and recessive is a logical 1 (passively returned to a voltage by a resistor). The idle state is represented by the recessive level (Logical 1). If one node transmits a dominant bit and another node transmits a recessive bit then there is a collision and the dominant bit "wins". This means there is no delay to the higher-priority message, and the node transmitting the lower priority message automatically attempts to re-transmit six bit clocks after the end of the dominant message. This makes CAN very suitable as a real time prioritized communications system.

The exact voltages for a logical 0 or 1 depend on the physical layer used, but the basic principle of CAN requires that each node listens to the data on the CAN network including the transmitting node(s) itself (themselves). If a logical 1 is transmitted by all transmitting nodes at the same time, then a logical 1 is seen by all of the nodes, including both the transmitting node(s) and receiving node(s). If a logical 0 is transmitted by all transmitting node(s) at the same time, then a logical 0 is seen by all nodes. If a logical 0 is being transmitted by one or more nodes, and a logical 1 is being transmitted by one or more nodes, then a logical 0 is seen by all nodes including the node(s) transmitting the logical 1. When a node transmits a logical 1 but sees a logical 0, it realizes that there is a contention and it quits transmitting. By using this process, any node that transmits a logical 1 when another node transmits a logical 0 "drops out" or loses the arbitration. A node that loses arbitration re-queues its message for later transmission and the CAN frame bit-stream continues without error until only one node is left transmitting. This means that the node that transmits the first 1 loses arbitration. Since the 11 (or 29 for CAN 2.0B) bit identifier is transmitted by all nodes at the start of the CAN frame, the node with the lowest identifier transmits more zeros at the start of the frame, and that is the node that wins the arbitration or has the highest priority.

For example, consider an 11-bit ID CAN network, with two nodes with IDs of 15 (binary representation, 00000001111) and 16 (binary representation, 00000010000). If these two nodes transmit at the same time, each will first transmit the start bit then transmit the first six zeros of their ID with no arbitration decision being made.

  • Thank you for this info. That's what I thought when I choose CAN. However I didn't find any library capable of having multiple master... Any idea where I could find one ? – Undeadguy Jul 6 '18 at 7:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.