I'm going through some addressing schemes with CAN bus. I came across this post: Most efficient way to handle addressing / termination in a daisy-chained CAN bus?
There's a solution explained called EmCAN. The author says:
EmCan solves the node address problem without requiring special hardware. For details, see the EmCan spec, but basically, each node has a globally unique 7 byte ID. Each node periodically requests a bus address and sends this ID. The collision detection mechanism will guarantee that the bus master sees only one of these requests even if multiple nodes send a address request at the same time. The bus master sends a address assignment message that includes the 7 byte ID and the assigned address, so at most one single node is assigned a new address at a time.
So I'm thinking of this approach:
Until an address is assigned, nodes can only act upon broadcast messages from the bus master, and can only send requests for a address.
- There's an unique serial number of 8 bytes, derived from the unique chip identifier of the STM32.
- A node ID which is a number between 1 and 127
At first boots up, the node gets a default address 0. It sends its unique 8-byte serial number to master (in the data frame), which then assigns the node a shorter node ID between 1 and 127. As of that point, the node uses only the node ID assigned for communication.
So the big question: what if two nodes with no address assigned send the same address request with the same node Id of zero at boot up? This would cause a conflict no addressed by the CAN protocol.