Single bus device ID setting method and system
By sending broadcast packets in the IO device on the bus and detecting voltage and logic IDs, the problem of device ID conflict is solved, and normal communication of IO device is achieved.
Patent Information
- Application Number
- CN202411437282.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-15
- Publication Date
- 2025-02-11
AI Technical Summary
In the prior art, when the number of devices on the bus increases, a limited address line may lead to device ID conflicts, resulting in communication conflicts and errors.
The controller sends broadcast packets carrying device IDs to N IO devices. The IO device detects its own voltage and logic IDs, and sets the logic ID of each IO device in turn to ensure that each IO device sets a unique device through an address line ID.
No matter how many devices increase on the bus, there will be no device ID conflicts, ensuring normal communication between IO devices.
Smart Images

Figure CN119415461A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of communication technology, and in particular to a method and system for setting a single bus device ID. Background Art
[0002] For devices communicating on buses such as the CAN bus and RS485 bus, the master node needs to address the device or set the device ID in order to better manage and communicate with the device.
[0003] At present, addressing is generally performed through an address bus or by installing a dial code on the device to determine the device ID. However, as the number of devices on the bus increases, the address lines cannot be increased indefinitely. The limited address lines may cause device ID conflicts. Two or more devices may be assigned the same address, which will cause communication conflicts and errors.
[0004] Therefore, how to correctly allocate device IDs of IO devices to ensure normal communication of IO devices has become a problem that urgently needs to be solved in the field. Summary of the invention
[0005] The present application provides a method and system for setting a single bus device ID, the purpose of which is to correctly allocate the device ID of an IO device to ensure normal communication of the IO device.
[0006] In order to achieve the above objectives, this application provides the following technical solutions:
[0007] A single bus device ID setting system, the setting system comprising: a controller and N IO devices, N being a positive integer greater than 1;
[0008] The N IO devices are connected in series, the output end of the first IO device is connected to the input end of the second IO device, the output end of the N-1 IO device is connected to the input end of the N IO device, and the input end of the first IO device is connected to the controller through an address line;
[0009] The controller and the N IO devices are communicatively connected via a communication bus;
[0010] The controller sends a broadcast packet carrying a device ID to the N IO devices through a communication bus. When the N IO devices receive the broadcast packet carrying the device ID sent by the controller, the N IO devices detect their own voltage and logic ID to obtain a detection result; and according to the detection result, the logic ID of each IO device is set in sequence from the Nth IO device to the first IO device.
[0011] Optionally, the IO device includes: a switch, a first resistor, a second resistor and a third resistor;
[0012] One end of the switch is connected to one end of the first resistor, and the other end of the first resistor is grounded;
[0013] One end of the second resistor is connected to a power supply, the other end of the second resistor is connected to one end of the third resistor, and the other end of the third resistor is grounded;
[0014] When the IO device is the first IO device, the other end of the switch is connected to the controller, and the common end connected to the other end of the second resistor and one end of the third resistor is connected to the input end of the second IO device;
[0015] When the IO device is the Nth IO device, the other end of the switch is connected to the output end of the N-1th IO device.
[0016] Optionally, the N IO devices are 4 IO devices, including: a first IO device, a second IO device, a third IO device and a fourth IO device;
[0017] The input end of the first IO device is connected to the controller, and the output end of the first IO device is connected to the input end of the second IO device;
[0018] The output end of the second IO device is connected to the input end of the third IO device, and the output end of the third IO device is connected to the input end of the fourth IO device.
[0019] Optionally, each of the N IO devices is provided with a single-chip microcomputer, and the single-chip microcomputer is used to measure the voltage of the addressing circuit of the N IO devices themselves.
[0020] Optionally, the first IO device is fixedly connected to the controller via a fixed component.
[0021] Optionally, the fixing component includes: a slot and a guide rail;
[0022] The guide rail is arranged on the controller, the slot is arranged on the first IO device, and the first IO device and the controller are slidably connected via the slot and the guide rail.
[0023] A method for setting a single bus device ID, applied to any of the above-mentioned single bus device ID setting systems, comprising:
[0024] Send a broadcast packet carrying the device ID to N IO devices through the controller;
[0025] When receiving the broadcast packet, periodically detecting the voltage of the addressing circuit of the N IO devices;
[0026] When the voltage of any IO device is a preset voltage and the logic ID of the IO device is a preset ID, the logic ID of the IO device is set to the device ID, a response message of setting completion is sent to the controller, and the connection with other IO devices is disconnected; wherein the other IO devices refer to IO devices other than the set device ID;
[0027] After receiving the response information, the controller adds 1 to the device ID in the broadcast packet to obtain a new device ID;
[0028] The controller determines the new device ID as the device ID, and returns to execute the step of sending a broadcast packet carrying the device ID to N IO devices through the controller until the device IDs of all IO devices are set.
[0029] Optionally, before sending the broadcast packet carrying the device ID to the N IO devices through the controller, the method further includes:
[0030] When N IO devices are powered on, the logical IDs of the N IO devices are set to preset IDs.
[0031] Optionally, when the voltage of any IO device is a preset voltage and the logic ID of the IO device is a preset ID, setting the logic ID of the IO device to the device ID, sending a setting completion response message to the controller, and disconnecting from other IO devices, includes:
[0032] When the voltage of any IO device is 1.5V and the logic ID of the IO device is 0XFFFF, the logic ID of the IO device is set to the device ID, and a response message of setting completion is sent to the controller, and the addressing circuit of the IO device is disconnected from the addressing circuits of other IO devices.
[0033] Optionally, also include:
[0034] When the device IDs of all the IO devices are set, the controller feeds back a response message indicating that the device IDs of all the IO devices are set.
[0035] The technical solution provided by the present application is that N IO devices are connected in series from beginning to end, the output end of the first IO device is connected to the input end of the second IO device, the output end of the N-1th IO device is connected to the input end of the Nth IO device, and the input end of the first IO device is connected to the controller through an address line; the controller and the N IO devices are connected through a communication bus communication; wherein the controller sends a broadcast packet carrying a device ID to the N IO devices through the communication bus, and when the N IO devices receive the broadcast packet carrying the device ID sent by the controller, the voltage and logic ID of the N IO devices are detected to obtain the detection result; according to the detection result, the logic ID of each IO device is set in sequence from the Nth IO device to the first IO device. The device ID of each IO device can be set in sequence through an address line, and no matter how many devices are added to the communication bus, there will be no device ID conflict, thereby ensuring the normal communication of the IO devices. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0037] Figure 1 A schematic diagram of the architecture of a system for setting a single bus device ID provided in an embodiment of the present application;
[0038] Figure 2 A schematic diagram of the architecture of another single bus device ID setting system provided in an embodiment of the present application;
[0039] Figure 3 A schematic diagram of the architecture of an IO device provided in an embodiment of the present application;
[0040] Figure 4 A schematic diagram of the architecture of another single bus device ID setting system provided in an embodiment of the present application;
[0041] Figure 5 A flowchart of a method for setting a single bus device ID provided in an embodiment of the present application. DETAILED DESCRIPTION
[0042] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0043] In this application, the terms "comprises", "comprising" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprising a ..." does not exclude the presence of other identical elements in the process, method, article or device comprising the element.
[0044] like Figure 1 , which is a schematic diagram of the architecture of a single bus device ID setting system provided in an embodiment of the present application, the setting system includes: a controller 11 and N IO devices, where N is a positive integer greater than 1.
[0045] N IO devices 12 are connected in series in sequence, the output end of the first IO device is connected to the input end of the second IO device, the output end of the N-1th IO device is connected to the input end of the Nth IO device, and the input end of the first IO device is connected to the controller through an address line.
[0046] Optionally, each of the N IO devices is provided with a single-chip microcomputer, and the single-chip microcomputer is used to measure the voltage of the addressing circuit of the N IO devices themselves.
[0047] It is understandable that the microcontroller carries an Analog-to-Digital Converter (ADC) function, through which the voltage of the IO device itself can be measured.
[0048] Furthermore, the first IO device is fixedly connected to the controller 11 via a fixed component.
[0049] It is understandable that after the input end of the first IO device is connected to the controller via a wire, the first IO device can also be tightly connected to the controller 11 via a mechanical structure, that is, it can be fixedly connected to the controller 11 via a fixing component.
[0050] Furthermore, the fixing component includes: a slot and a guide rail.
[0051] The guide rail is arranged on the controller 11, the slot is arranged on the first IO device, and the first IO device and the controller 11 are slidably connected via the slot and the guide rail.
[0052] It can be understood that the first IO device and the controller 11 are slidably connected via the slot and the guide rail, so that the first IO device and the controller 11 can be fixedly connected, and can also be slid to disconnect at any time.
[0053] The controller 11 and the N IO devices are communicatively connected via a communication bus.
[0054] Among them, the controller 11 sends a broadcast packet carrying a device ID to N IO devices through the communication bus. When the N IO devices receive the broadcast packet carrying the device ID sent by the controller 11, the N IO devices detect their own voltage and logic ID to obtain the detection result; according to the detection result, the logical ID of each IO device is set in sequence from the Nth IO device to the first IO device.
[0055] It should be noted that the controller 11 and the N IO devices are connected via a CAN bus communication.
[0056] Optionally, the controller 11 and the N IO devices may also be connected via an RS485 bus communication.
[0057] For further information, see Figure 2 The IO device includes: a switch 21, a first resistor 22, a second resistor 23 and a third resistor 24.
[0058] One end of the switch 21 is connected to one end of the first resistor 22, and the other end of the first resistor 22 is grounded;
[0059] One end of the second resistor 23 is connected to the power source 25 , the other end of the second resistor 23 is connected to one end of the third resistor 24 , and the other end of the third resistor 24 is grounded.
[0060] When the IO device is the first IO device, the other end of the switch 21 is connected to the controller 11, and the common end where the other end of the second resistor 23 and one end of the third resistor 24 are connected is connected to the input end of the second IO device.
[0061] When the IO device is the first IO device, the other end of the switch 21 is connected to the controller 11 through a single bus lead-out point (e.g., a wire), and the common end of the other end of the second resistor 23 and one end of the third resistor 24 is connected to the input end of the second IO device through the single bus lead-out point. For details, the location of the single bus lead-out point can be found in Figure 3 .
[0062] When the IO device is the Nth IO device, the other end of the switch 21 is connected to the output end of the N-1th IO device.
[0063] When the IO device is the Nth IO device, the other end of the switch 21 is connected to the output end of the N-1th IO device through a single bus lead-out point.
[0064] Optionally, the resistance values of the first resistor 22 , the second resistor 23 and the third resistor 24 include but are not limited to: 10K.
[0065] It is understandable that each IO device has two 10K resistors connected in series between VCC and GND, where the voltage of VCC includes but is not limited to: 3V.
[0066] It should be noted that the position of the common terminal (i.e. Figure 2 The voltages of V1, V2, V3 and V4) in the IO device are obtained.
[0067] For further information, see Figure 4 , the N IO devices are 4 IO devices, including: a first IO device 41 , a second IO device 42 , a third IO device 43 and a fourth IO device 44 .
[0068] An input end of the first IO device 41 is connected to the controller 11 , and an output end of the first IO device 41 is connected to an input end of the second IO device 42 .
[0069] An output terminal of the second IO device 42 is connected to an input terminal of the third IO device 43 , and an output terminal of the third IO device 43 is connected to an input terminal of the fourth IO device 44 .
[0070] It should be noted that each IO device can also be fixedly connected by a mechanical mechanism. The mechanical structure connection can ensure that each IO device remains stable during use and prevent displacement due to vibration or external force.
[0071] In summary, the device ID of each IO device can be set in sequence through one address line. No matter how many devices are added to the communication bus, there will be no device ID conflict, thereby ensuring normal communication of the IO devices.
[0072] Corresponding to the system for setting a single bus device ID provided in the above embodiment of the present application, the embodiment of the present application further provides a method for setting a single bus device ID, which is applicable to the system for setting a single bus device ID mentioned in the above embodiment of the present application, such as Figure 5 As shown, the following steps are included:
[0073] S501: Send a broadcast packet carrying a device ID to N IO devices through the controller.
[0074] It can be understood that the controller sends a broadcast packet carrying a device ID to the N IO devices through the communication bus, so that the N IO devices set the logical ID according to the broadcast packet.
[0075] Optionally, before step S101, the logical ID of the IO device needs to be set to an initial value, and the initial value indicates that the logical ID of the IO device has not been set, thereby avoiding omissions when setting the logical ID later. Therefore, another embodiment of the present application provides a method for setting a logical ID, including:
[0076] When N IO devices are powered on, the logical IDs of the N IO devices are set to preset IDs.
[0077] The preset ID includes but is not limited to: 0xFFFF.
[0078] It is understandable that when N IO devices are powered on, a unique ID can be dynamically assigned to each IO device through a specific protocol or mechanism. 0xFF indicates that these devices have not yet obtained a valid ID and are waiting for a subsequent assignment process.
[0079] It should be noted that when the N IO devices are powered on, that is, when the switches in all the IO devices are closed, the logical IDs of the N IO devices are set to the preset IDs.
[0080] S502: When a broadcast packet is received, the voltage of the addressing circuit of the N IO devices is periodically detected.
[0081] It can be understood that when N IO devices receive the broadcast packet, the voltage of their own addressing circuit is measured through the ADC function of the microcontroller.
[0082] S503: When the voltage of any IO device is the preset voltage and the logic ID of the IO device is the preset ID, the logic ID of the IO device is set as the device ID, a response message of setting completion is sent to the controller, and the connection with other IO devices is disconnected.
[0083] Among them, other IO devices indicate IO devices other than the set device ID.
[0084] Optionally, the preset voltage includes but is not limited to: 3V.
[0085] It can be understood that since the Nth IO device has no subsequent devices and there is no voltage division, the voltage of the Nth IO device is the preset voltage, and the logical ID of the Nth IO device is the preset ID. The logical ID of the IO device is set to the device ID, and a response message of setting completion is sent to the controller, and the connection with other IO devices is disconnected; when the Nth IO device is disconnected from other IO devices, the N-1th IO device has no subsequent devices and there is no voltage division. Therefore, the voltage of the N-1th IO device is the preset voltage, and the logical ID of the N-1th IO device is the preset ID. Therefore, the logical ID of the N-1th IO device is set, and so on, until the first IO device is set.
[0086] It should be noted that the IO device disconnects from other IO devices by turning on its own switch.
[0087] Optionally, in another embodiment of the present application, a specific implementation of step S503 includes:
[0088] When the voltage of any IO device is 1.5V and the logic ID of the IO device is 0XFFFF, the logic ID of the IO device is set to the device ID, and a response message of setting completion is sent to the controller, and the addressing circuit of the IO device is disconnected from the addressing circuits of other IO devices.
[0089] S504: After receiving the response information, the controller adds 1 to the device ID in the broadcast packet to obtain a new device ID.
[0090] Specifically, assuming that the device ID is 1, after receiving the response information, the controller adds the device ID to 1 to obtain a new device ID of 2.
[0091] S505: The controller determines the new device ID as the device ID, and returns to execute step S501 until the device IDs of all IO devices are set.
[0092] In order to better Figure 5 The content shown is explained below, and an example is given in combination with a specific application scenario. Assume that there are four IO devices, namely a first IO device, a second IO device, a third IO device, and a fourth IO device, and the device ID is 1.
[0093] First, a broadcast packet carrying the device ID is sent to four IO devices through the controller. When N IO devices receive the broadcast packet, their own voltage is measured through the ADC function of the microcontroller. Since the fourth IO device has no subsequent device and there is no voltage division, the voltage of the fourth IO device is the preset voltage, and the logic ID of the fourth IO device is the preset ID. The logic ID of the IO device is set to 1, and a response message of setting completion is sent to the controller, and the connection with other IO devices is disconnected.
[0094] Secondly, after receiving the response information, the controller adds 1 to the device ID to obtain a new device ID of 2, and sends a broadcast packet carrying the device ID to the four IO devices through the controller. Since there is no subsequent device for the third IO device, the third IO device and the fourth IO device are at the preset voltage at this time. However, since the logical ID of the third IO device is the preset ID, at this time, the logical ID of the third IO device is set to 2, and a response information of the setting completion is sent to the controller, and the connection with other IO devices is disconnected.
[0095] Next, after receiving the response information, the controller adds 1 to the device ID to obtain a new device ID of 3, and sends a broadcast packet carrying the device ID to the four IO devices through the controller. Since there is no subsequent device for the second IO device, the second IO device, the third IO device and the fourth IO device are at the preset voltage at this time. However, since the logical ID of the second IO device is the preset ID, at this time, the logical ID of the second IO device is set to 3, and a response message of setting completion is sent to the controller, and the connection with other IO devices is disconnected.
[0096] Finally, after receiving the response information, the controller adds 1 to the device ID to obtain a new device ID of 4, and sends a broadcast packet carrying the device ID to the four IO devices through the controller. Since the first IO device does not have a subsequent device, the first IO device, the second IO device, the third IO device and the fourth IO device are at the preset voltage at this time. However, since the logical ID of the first IO device is the preset ID, at this time, the logical ID of the second IO device is set to 4, and a response message of setting completion is sent to the controller, and the connection with other IO devices is disconnected.
[0097] Optionally, after step S505, the method further includes:
[0098] When the device IDs of all IO devices are set, the controller feeds back a response message indicating that the device IDs of all IO devices are set.
[0099] In summary, the controller sends a broadcast packet to each IO device, so that each IO device sets the logical ID in turn according to the broadcast packet to ensure that there is no conflict when the device sets the logical ID, thereby avoiding the problem of device ID duplication and ensuring normal communication of the IO device.
[0100] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can refer to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system or system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can refer to the partial description of the method embodiment. The system and system embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative work.
[0101] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.
[0102] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A system for setting a single bus device ID, characterized in that: The setting system includes: a controller and N IO devices, where N is a positive integer greater than 1; The N IO devices are connected in series, the output end of the first IO device is connected to the input end of the second IO device, the output end of the N-1 IO device is connected to the input end of the N IO device, and the input end of the first IO device is connected to the controller through an address line; The controller and the N IO devices are communicatively connected via a communication bus; The controller sends a broadcast packet carrying a device ID to the N IO devices through a communication bus. When the N IO devices receive the broadcast packet carrying the device ID sent by the controller, the N IO devices detect their own voltage and logic ID to obtain a detection result; and according to the detection result, the logic ID of each IO device is set in sequence from the Nth IO device to the first IO device.
2. The system according to claim 1, characterized in that The IO device includes: a switch, a first resistor, a second resistor and a third resistor; One end of the switch is connected to one end of the first resistor, and the other end of the first resistor is grounded; One end of the second resistor is connected to a power supply, the other end of the second resistor is connected to one end of the third resistor, and the other end of the third resistor is grounded; When the IO device is the first IO device, the other end of the switch is connected to the controller, and the common end connected to the other end of the second resistor and one end of the third resistor is connected to the input end of the second IO device; When the IO device is the Nth IO device, the other end of the switch is connected to the output end of the N-1th IO device.
3. The system according to claim 1, characterized in that The N IO devices are 4 IO devices, including: a first IO device, a second IO device, a third IO device and a fourth IO device; The input end of the first IO device is connected to the controller, and the output end of the first IO device is connected to the input end of the second IO device; The output end of the second IO device is connected to the input end of the third IO device, and the output end of the third IO device is connected to the input end of the fourth IO device.
4. The system according to any one of claims 1 to 3, characterized in that: Each of the N IO devices is provided with a single-chip microcomputer, and the single-chip microcomputer is used to measure the voltage of the addressing circuit of the N IO devices themselves.
5. The system according to claim 1, characterized in that The first IO device is fixedly connected to the controller via a fixing component.
6. The system according to claim 5, characterized in that The fixing component comprises: a slot and a guide rail; The guide rail is arranged on the controller, the slot is arranged on the first IO device, and the first IO device and the controller are slidably connected via the slot and the guide rail.
7. A method for setting a single bus device ID, characterized in that: A system for setting a single bus device ID applied to any one of claims 1 to 6, comprising: Send a broadcast packet carrying the device ID to N IO devices through the controller; When receiving the broadcast packet, periodically detecting the voltage of the addressing circuit of the N IO devices; When the voltage of any IO device is a preset voltage and the logic ID of the IO device is a preset ID, the logic ID of the IO device is set to the device ID, a response message of setting completion is sent to the controller, and the connection with other IO devices is disconnected; wherein the other IO devices refer to IO devices other than the set device ID; After receiving the response information, the controller adds 1 to the device ID in the broadcast packet to obtain a new device ID; The controller determines the new device ID as the device ID, and returns to execute the step of sending a broadcast packet carrying the device ID to N IO devices through the controller until the device IDs of all IO devices are set.
8. The method according to claim 7, characterized in that Before the controller sends a broadcast packet carrying the device ID to the N IO devices, the method further includes: When N IO devices are powered on, the logical IDs of the N IO devices are set to preset IDs.
9. The method according to claim 7, characterized in that: When the voltage of any IO device is a preset voltage and the logic ID of the IO device is a preset ID, the logic ID of the IO device is set to the device ID, a response message of setting completion is sent to the controller, and the connection with other IO devices is disconnected, including: When the voltage of any IO device is 1.5V and the logic ID of the IO device is 0XFFFF, the logic ID of the IO device is set to the device ID, and a response message of setting completion is sent to the controller, and the addressing circuit of the IO device is disconnected from the addressing circuits of other IO devices.
10. The method according to claim 7, characterized in that Also includes: When the device IDs of all the IO devices are set, the controller feeds back a response message indicating that the device IDs of all the IO devices are set.