CANID initialization system and method based on GPIO control
Through the CAN_ID initialization system and method based on GPIO control, a unique CAN_ID is automatically set for multiple identical CAN devices, which solves the problem of errors prone to device installation and improves installation efficiency and accuracy.
Patent Information
- Application Number
- CN202411755109.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-03
- Publication Date
- 2025-03-14
AI Technical Summary
The prior art lacks the initialization method of multiple identical CAN devices, which leads to errors that occur during installation of devices and requires manual settings of different CAN_IDs.
The CAN_ID initialization system and method based on GPIO control are adopted to connect the IO line between the CAN initialization control device and the CAN slave device through the IO line connection between the CAN initialization control device and the CAN slave device, and use the GPIO signal and the CAN bus broadcast frame, and a unique CAN_ID is automatically set for each CAN slave device.
Automatic CAN_ID initialization of CAN slave devices is realized, avoiding the mismatch between the device location and CAN_ID, and improving installation efficiency and accuracy.
Smart Images

Figure CN119629051A_ABST
Abstract
Description
Technical Field
[0001] The present invention mainly relates to the technical field of CAN device control, and in particular to a CAN_ID initialization system and method based on GPIO control. Background Art
[0002] CAN bus (Controller Area Network) is a field bus protocol widely used in automotive electronics, industrial control and automation. It is a serial, asynchronous half-duplex communication protocol that uses two differential signal lines (CAN_H and CAN_L) to form a bus. All nodes are connected to the bus through these two lines to achieve real-time information interaction.
[0003] The CAN bus has excellent stability and anti-interference capabilities, but the characteristics of the CAN bus make the physical position of the CAN device on the bus bound to the CAN_ID in the system. For multiple similar or identical CAN devices in a system, their CAN_IDs need to be pre-set, and when assembling such devices, the devices must be installed in the corresponding physical positions according to the CAN_ID of the devices. When there are multiple devices with the same appearance in the system, it is extremely easy to install them in the wrong position during installation. In short, there is currently a lack of initialization methods for multiple identical CAN devices in a system on the market. Summary of the invention
[0004] The technical problem to be solved by the present invention is to provide a CAN_ID initialization system and method based on GPIO control, so as to solve the problem that each CAN slave device needs to manually set a different CAN_ID.
[0005] In order to solve the above technical problems, in a first aspect, the present invention provides a CAN_ID initialization system based on GPIO control, comprising: a CAN bus, a plurality of CAN slave devices are mounted at different positions on the CAN bus, and an initialization control device is also mounted on the CAN bus, wherein each of the CAN slave devices is connected to the initialization control device through two control IO lines; the initialization system performs the following steps, including: the CAN initialization control device reads the first control IO pin of the CAN slave device to determine whether the CAN slave device is in place; the CAN slave device sends a first level signal through the first control IO pin, so that the CAN initialization control device obtains the CA N slave device access information; the CAN initialization control device sends the first level signal through the second control IO pin, so that the CAN slave device waits for initialization; the CAN initialization control device sends a broadcast frame through the CAN bus, and the sending content is used to provide a CAN_ID for the current CAN slave device, and the CAN_ID is the physical location information of the CAN slave device on the CAN bus; the CAN slave device sets the obtained CAN_ID as its own CAN_ID, and sends an initialization success frame to the CAN initialization control device; the CAN initialization control device sends a second level signal through the second control IO pin after receiving the initialization success frame.
[0006] Furthermore, it also includes: the CAN initialization control device determines whether the current CAN slave device is the last device to be initialized; if the current CAN device is not the last device to be initialized, continuing the CAN_ID initialization process of the remaining CAN slave devices.
[0007] Furthermore, the first level signal is a low level signal, and the second level signal is a high level signal.
[0008] Furthermore, the CAN initialization control device also generates a CAN_ID for each of the CAN slave devices through a custom rule.
[0009] Furthermore, the CAN slave device is a rotary encoder or a programmable button.
[0010] In the second aspect, the present invention also provides a CAN_ID initialization method based on GPIO control, which is applied to a CAN initialization control device, including: reading a first control IO pin of a CAN slave device to determine whether the CAN slave device is in place; sending the first level signal through a second control IO pin to make the CAN slave device wait for initialization; sending a broadcast frame through a CAN bus, wherein the sent content is used to provide a CAN_ID for the current CAN slave device, and the CAN_ID is the physical location information of the CAN slave device on the CAN bus; and sending a second level signal through the second control IO pin after receiving the initialization success frame sent by the CAN slave device.
[0011] Furthermore, it also includes: judging whether the current CAN slave device is the last device to be initialized; if the current CAN device is not the last device to be initialized, continuing the CAN_ID initialization process of the remaining CAN slave devices.
[0012] Furthermore, the first level signal is a low level signal, and the second level signal is a high level signal.
[0013] Furthermore, it also includes: generating a CAN_ID of each of the CAN slave devices through a custom rule.
[0014] In the third aspect, the present invention also provides a CAN_ID initialization method based on GPIO control, which is applied to a CAN slave device, including: sending a first level signal through a first control IO pin, so that a CAN initialization control device obtains access information of the CAN slave device; receiving the CAN_ID sent by the CAN initialization control device, wherein the CAN_ID is the physical location information of the CAN slave device on the CAN bus; setting the obtained CAN_ID as its own CAN_ID, and sending an initialization success frame to the CAN initialization control device.
[0015] Compared with the prior art, the present invention has the following beneficial effects: it can automatically complete the CAN_ID initialization of the CAN slave device, and avoid the situation where the position of the CAN slave device on the CAN bus does not match the CAN_ID. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] The accompanying drawings illustrate embodiments of the present invention and together with the specification serve to explain the principles of the present invention. In the accompanying drawings: Figure 1 It is a structural schematic diagram of a CAN_ID initialization system based on GPIO control according to an embodiment of the present invention; Figure 2 This is a flow chart of a CAN_ID initialization method based on GPIO control according to an embodiment of the present invention. Figure 1 ; Figure 3 This is a flow chart of a CAN_ID initialization method based on GPIO control according to an embodiment of the present invention. Figure 2 ; Figure 4 It is a schematic diagram of the arrangement when the CAN slave device is a programmable button in one embodiment of the present invention; Figure 5 This is a circuit diagram of a CAN prompting and controlling device in one embodiment of the present invention; Figure 6 Schematic diagram of connector pins of a programmable key in one embodiment of the present invention. DETAILED DESCRIPTION
[0017] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following is a brief introduction to the drawings required for the description of the embodiments. Obviously, the drawings described below are only some examples or embodiments of the present invention. For ordinary technicians in this field, the present invention can also be applied to other similar scenarios based on these drawings without creative work. Unless it is obvious from the language environment or otherwise explained, the same reference numerals in the figures represent the same structure or operation.
[0018] It should be understood that when a component is referred to as being "on another component," "connected to another component," "coupled to another component," or "contacting another component," it may be directly on, connected to, coupled to, or contacting the other component, or there may be intervening components. In contrast, when a component is referred to as being "directly on another component," "directly connected to," "directly coupled to," or "directly contacting" another component, there are no intervening components. Similarly, when a first component is referred to as being "electrically in contact with" or "electrically coupled to" a second component, there is an electrical path between the first component and the second component that allows current to flow. The electrical path may include capacitors, coupled inductors, and / or other components that allow current to flow, even without direct contact between conductive components.
[0019] refer to Figure 1 As shown, the CAN_ID initialization system based on GPIO control in this embodiment includes a CAN bus, a number of CAN slave devices are mounted at different positions on the CAN bus, and a CAN initialization control device is also mounted on the CAN bus, wherein each CAN slave device is connected to the CAN initialization control device through two control IO lines (control IO-1 and control IO-2). To realize the CAN_ID initialization of the CAN slave device, the entire system has 1 CAN initialization control device, and the system has no limit on the number of CAN slave devices, which can be mounted to the maximum number supported by the CAN bus.
[0020] In this embodiment, the initialization system performs the following steps, including: the CAN initialization control device reads the first control IO pin of the CAN slave device to determine whether the CAN slave device is in place; the CAN slave device sends a first level signal through the first control IO pin, so that the CAN initialization control device obtains the access information of the CAN slave device; the CAN initialization control device sends a first level signal through the second control IO pin, so that the CAN slave device waits for initialization; the CAN initialization control device sends a broadcast frame through the CAN bus, and the sent content is used to provide a CAN_ID (Controller Area Network Identifier) for the current CAN slave device, and the CAN_ID is the physical location information of the CAN slave device on the CAN bus; the CAN slave device sets the obtained CAN_ID as its own CAN_ID, and sends an initialization success frame to the CAN initialization control device; after receiving the initialization success frame, the CAN initialization control device sends a second level signal through the second control IO pin.
[0021] This embodiment uses the GPIO (General Purpose Input / Output) interface to sequentially start and initialize the device IDs (CAN_ID) of multiple CAN slave devices on the CAN bus, thereby avoiding the problem of manually setting different CAN_IDs for each CAN device. In addition, the CAN initialization control device can also determine whether the current CAN slave device is the last device to be initialized. If the current CAN device is not the last device to be initialized, the CAN_ID initialization process of the remaining CAN slave devices continues.
[0022] In one implementation, the first level signal is a low level signal, and the second level signal is a high level signal.
[0023] In one implementation, the CAN initialization control device also generates the CAN_ID of each CAN slave device through a custom rule. For example, the CAN_ID of CAN slave device 1 is 0x0502, the CAN_ID of CAN slave device 2 is 0x0503, the CAN_ID of CAN slave device 3 is 0x0504, and so on.
[0024] In one implementation, the CAN slave device is a rotary encoder or a programmable button.
[0025] refer to Figure 2As shown, another embodiment of the present invention is a CAN_ID initialization method based on GPIO control, which is applied to a CAN initialization control device, including: reading the first control IO pin of the CAN slave device to determine whether the CAN slave device is in place; sending a first level signal through the second control IO pin to make the CAN slave device wait for initialization; sending a broadcast frame through the CAN bus, the content of which is used to provide a CAN_ID for the current CAN slave device, and the CAN_ID is the physical location information of the CAN slave device on the CAN bus; after receiving the initialization success frame sent by the CAN slave device, sending a second level signal through the second control IO pin. Other execution steps can refer to the aforementioned embodiment and will not be repeated here.
[0026] For the CAN initialization control device, its main task is to set the CAN_ID for the CAN slave device and monitor in real time whether the CAN slave device is in place. Specifically, it is often executed through the following process: 1) Generate CAN_ID through rules or custom rules; 2) Detect whether the control IO-1 is a low-level signal to determine whether the CAD slave device is in place; 3) Make the control IO-2 send a low-level signal, and control IO-2 changes from a high level to a low level, so that the corresponding CAN slave device waits for initialization; 4) Send a broadcast frame through the CAN bus, and the content sent is the CAN_ID generated by the current CAN slave device; 5) Wait for the CAN slave device to send an initialization completion frame; 6) Make the control IO-2 send a high-level signal to complete the initialization of the current CAN slave device; 7) Determine whether the currently initialized CAN slave device is the last CAN device.
[0027] refer to Figure 3 As shown, another embodiment of the present invention provides a CAN_ID initialization method based on GPIO control, which is applied to a CAN slave device, including: sending a first level signal through a first control IO pin, so that a CAN initialization control device obtains access information of the CAN slave device; receiving the CAN_ID sent by the CAN initialization control device, where the CAN_ID is the physical location information of the CAN slave device on the CAN bus; setting the obtained CAN_ID as its own CAN_ID, and sending an initialization success frame to the CAN initialization control device.
[0028] For example, for a CAN slave device, its main task is to receive the CAN_ID issued by the CAN initialization control device, and set the issued CAN_ID as the CAN_ID of its own CAN interface according to the rules. It often performs the following processes: 1) Make the control IO-1 send a low-level signal, and control IO-1 changes from a high level to a low level, so that the CAN initialization control device obtains the CAN slave device access information; 2) Wait for the control IO-2 to have a low-level signal input. When the control IO-2 signal is low, it means that the master is initializing the current slave device; 3) Wait for the master to send a broadcast frame through the CAN bus. After sending the broadcast frame, the CAN slave device with a low-level control IO-2 signal parses the broadcast frame and obtains the CAN_ID; 4) Set the obtained CAN_ID as its own CAN_ID, and send an initialization success frame to the CAN initialization control device; 5) Wait for the control IO-2 to have a high-level signal input. When a high-level signal is input, it means that the current slave device is initialized.
[0029] For example, a programmable button is used as an example for explanation. Figure 4 As shown in the figure, the programmable key product is a keyboard composed of 6×6 matrix keys. The programmable key is a device composed of a main control module (CAN initialization control device) and multiple key modules (CAN slave devices). Since the function of the key needs to be bound to the physical location of the key, the main control module and the key module themselves need to know the physical location of the key module. In the initialization process of the device, the main control module works as the initialization control device, and the key module works as the slave device. The circuit block diagram is as follows Figure 5 The connector pins of the key module are shown in Figure 6 shown.
[0030] After the programmable key is powered on, the key module and the main control module start to work. After the two types of modules have completed the necessary processes, the CAN protocol based on the initialization method of this embodiment starts to initialize.
[0031] ①After the start, the main control module will first read the pin GPIO0 of each button module to determine whether the current button module is in place. When the pin GPIO0 is detected to be pulled low, it means that the current button module is in place and CAN_ID initialization is ready. After the reading is completed, the main control module will store the read result in a variable of type uint_64. Each BIT of this variable corresponds to a device. When the acquisition result is high (not in place), the current BIT is set to 1. When the acquisition result is low (in place), the current BIT is set to 0, and a variable of type uint_32 (variable A) is used to record how many pins are currently being collected and pulled low.
[0032] ②After checking the presence of the key module, the main control module will first pull down the pin GPIO1 of the key module corresponding to BIT0, select this key module, wait for 1ms, and then send the ID initialization information of the currently selected key module. The ID generation method used here is the cumulative generation method. The CAN_ID of slave device 0 is 0x0501, the CAN_ID of slave device 1 is 0x0502, and so on, until 0x0536.
[0033] ③After completing the necessary initialization, the key module will wait for the pin GPIO1 to be pulled low. When the pin GPIO1 is pulled low, the key module CAN interface will wait for the initialization information sent by the main control module and use this information to reinitialize the CAN interface of the slave device. After the key module reinitializes the CAN interface, the key module sends a message to the main control module through the CAN bus, indicating that the initialization is successful.
[0034] ④ When the main control module receives the initialization completion message sent by the selected button module, the main control module pulls the pin GPIO1 high to complete the initialization of the currently selected slave device.
[0035] ⑤ Repeat ②~④ until the number of executions is equal to variable A. At this point, the initialization process ends and the CAN_ID allocation of the key module is completed.
[0036] For those skilled in the art, the above invention disclosure is only for example and does not constitute a limitation of the present invention. Although not explicitly stated herein, those skilled in the art may make various modifications, improvements and corrections to the present invention. Such modifications, improvements and corrections are suggested in the present invention, so such modifications, improvements and corrections still belong to the spirit and scope of the exemplary embodiments of the present invention.
[0037] Although the present invention has been described with reference to the current specific embodiments, those skilled in the art should recognize that the above embodiments are only used to illustrate the present invention, and various equivalent changes or substitutions may be made without departing from the spirit of the present invention. Therefore, any changes or modifications to the above embodiments within the spirit of the present invention will fall within the scope of the claims of the present invention.
Claims
1. A CAN_ID initialization system based on GPIO control, characterized in that: include: A CAN bus, wherein a plurality of CAN slave devices are mounted at different positions on the CAN bus, and an initialization control device is also mounted on the CAN bus, wherein each of the CAN slave devices is connected to the initialization control device via two control IO lines; The initialization system performs the following steps, including: The CAN initialization control device reads the first control IO pin of the CAN slave device to determine whether the CAN slave device is in place; The CAN slave device sends a first level signal through a first control IO pin, so that the CAN initialization control device obtains access information of the CAN slave device; The CAN initialization control device sends the first level signal through the second control IO pin, so that the CAN slave device waits for initialization; The CAN initialization control device sends a broadcast frame through the CAN bus, and the sent content is used to provide a CAN_ID for the current CAN slave device, and the CAN_ID is the physical location information of the CAN slave device on the CAN bus; The CAN slave device sets the obtained CAN_ID as its own CAN_ID, and sends an initialization success frame to the CAN initialization control device; The CAN initialization control device sends a second level signal through a second control IO pin after receiving the initialization success frame.
2. The CAN_ID initialization system based on GPIO control according to claim 1, characterized in that: Also includes: The CAN initialization control device determines whether the current CAN slave device is the last device to be initialized; if the current CAN device is not the last device to be initialized, the CAN_ID initialization process of the remaining CAN slave devices is continued.
3. The CAN_ID initialization system based on GPIO control according to claim 1, characterized in that: The first level signal is a low level signal, and the second level signal is a high level signal.
4. The CAN_ID initialization system based on GPIO control according to claim 1, characterized in that: The CAN initialization control device also generates a CAN_ID for each of the CAN slave devices through a custom rule.
5. The CAN_ID initialization system based on GPIO control according to claim 1, characterized in that: The CAN slave device is a rotary encoder or a programmable button.
6. A CAN_ID initialization method based on GPIO control, characterized in that: Applicable to CAN initialization control equipment, including: Reading a first control IO pin of a CAN slave device to determine whether the CAN slave device is in place; Sending the first level signal through the second control IO pin to make the CAN slave device wait for initialization; Send a broadcast frame via the CAN bus, the content of which is used to provide a CAN_ID for the current CAN slave device, wherein the CAN_ID is the physical location information of the CAN slave device on the CAN bus; After receiving the initialization success frame sent by the CAN slave device, a second level signal is sent through the second control IO pin.
7. The CAN_ID initialization method based on GPIO control according to claim 6, characterized in that: Also includes: Determine whether the current CAN slave device is the last device to be initialized; if the current CAN device is not the last device to be initialized, continue the CAN_ID initialization process of the remaining CAN slave devices.
8. The CAN_ID initialization method based on GPIO control according to claim 6, characterized in that: The first level signal is a low level signal, and the second level signal is a high level signal.
9. The CAN_ID initialization method based on GPIO control according to claim 6, characterized in that: Also includes: The CAN_ID of each CAN slave device is generated by a custom rule.
10. A CAN_ID initialization method based on GPIO control, characterized in that: Applicable to CAN slave devices, including: Sending a first level signal through the first control IO pin enables the CAN initialization control device to obtain access information of the CAN slave device; Receiving a CAN_ID sent by the CAN initialization control device, wherein the CAN_ID is the physical location information of the CAN slave device on the CAN bus; The obtained CAN_ID is set as its own CAN_ID, and an initialization success frame is sent to the CAN initialization control device.
Citation Information
Patent Citations
Equipment address configuration method, device and system for communication system
CN107071076A
Device ID configuration method and system in CAN bus network
CN110753138A
GPIO-based communication method
CN112817895A
CAN network
CN113556270A
Working method of equipment in power supply system of underground scheme
CN118487375A