The invention relates to a method for automatically allocating an address to the same node on a communication
bus. The method includes the following steps: step S1, setting a
global variable address allocation tag, initializing the address allocation tag as an address unallocated state, judging whether the address allocation tag of a current node is unallocated, if not, executing the step S2, andif yes, executing the step S3; step S2, judging whether an address of the current node conflicts with a stored address, if yes, executing the step S3, and if not, executing the step S5; step S3, allocating an initial address that is a minimum address number '1' on the
bus to the current node; step S4, judging whether the address of the current node conflicts with the stored address, if not, executing the step S5, and if yes, adding 1 to the address of the current node, and re-executing the step S4; and step S5, switching the address allocation tag to an address allocated state and remaining unchanged. According to the method disclosed by the invention, when equipment replaces a
CAN bus due to the movement of the node, the reallocation of the address can be avoided, repeated addresses can be automatically rearranged in time, and
bus data errors caused by the repeated addresses can be avoided.