Master-slave device communication method based on electronic switch and related components thereof
By using electronic switches to connect the master device and multiple slave devices in series, high efficiency, low cost and reliability of master-slave communication are achieved, solving the problems of complex wiring and communication interruption caused by faults in the existing technology.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-13
- Publication Date
- 2026-03-24
AI Technical Summary
In existing technologies, communication between master and slave devices requires multiple chip select signal lines, resulting in high wiring costs and complexity. Daisy chain topology increases the number of signal lines and can cause communication interruption when a slave device fails.
The master device and multiple slave devices are connected in series using electronic switches. A chip select signal is provided through a signal line, and the target slave device is determined by a verification command. The electronic switches are then controlled to achieve one-to-one communication.
The number of chip select signal lines has been reduced, which lowers wiring costs and interface complexity, and avoids communication interruptions and data errors caused by equipment failure.
Smart Images

Figure CN115454908B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of multi-device communication, and in particular to a master-slave device communication method based on electronic switches and related components. Background Technology
[0002] Master and slave devices typically communicate using an SPI (Serial Peripheral Interface) bus. The master device needs to provide an additional chip select signal line for each slave device to enable normal communication. However, as the number of slave devices increases, the number of chip select signal lines also increases, raising wiring costs. Furthermore, the master device activating multiple chip select signals simultaneously can lead to data errors. Existing technology uses a daisy-chain topology to connect the devices; please refer to [reference needed]. Figure 1 , Figure 1 This is a schematic diagram of the structure of a communication system in the prior art. It is equivalent to providing the chip select signal required by all the slave devices through a chip select signal line. The master device only needs to activate a single chip select signal, which reduces wiring costs and avoids data errors. However, the daisy chain topology requires two signal lines with the same name to be set between every two devices, which leads to complex signal interfaces and an increase in the overall number of signal lines. Moreover, when a slave device fails, the master device will be unable to communicate with any normal slave device located after the failed slave device. Summary of the Invention
[0003] The purpose of this invention is to provide a master-slave device communication method based on electronic switches and related components, which reduces the number of signal lines, wiring costs, and interface complexity. It can avoid the problem of being unable to connect to other normal slave devices due to the failure of a slave device, and can also avoid the master device activating multiple chip select signals at the same time, thereby avoiding data errors.
[0004] To address the aforementioned technical problems, this invention provides a master-slave device communication method based on electronic switches, applied to a processor in a master device. The master device is connected to N slave devices, and the master device is connected in series with N electronic switches. The first moving terminal of the i-th electronic switch is connected to the chip select signal input terminal of the corresponding slave device. The second moving terminal of the i-th electronic switch is connected to the stationary terminal of the (i+1)-th electronic switch. The stationary terminal of the first electronic switch is connected to the chip select signal output terminal of the master device. N and i are both positive integers not less than 2, and i is less than N. The master-slave device communication method based on electronic switches includes:
[0005] When a communication command is received, a verification command corresponding to the communication command is generated;
[0006] The verification command is sequentially sent to N slave devices using N electronic switches, so that the N slave devices generate N verification messages according to the verification command;
[0007] The target device is determined based on N pieces of verification information;
[0008] A communication request is sent to the target slave device so that the master device can establish communication with the target slave device;
[0009] Before generating the verification information, the stationary terminal of the electronic switch corresponding to the slave device is connected to the first moving terminal; after generating the verification information, the stationary terminal of the electronic switch corresponding to the slave device (excluding the target slave device) is connected to the second moving terminal.
[0010] Preferably, before generating the verification instruction corresponding to the communication instruction, the method further includes:
[0011] When all N slave devices are powered on, N unused internal addresses are obtained from the preset address library. The N internal addresses are not completely identical to each other.
[0012] Each of the N internal station addresses is assigned to one of the N slave devices;
[0013] Generate the verification instruction corresponding to the communication instruction, including:
[0014] Generate the address query instruction corresponding to the slave device required by the communication instruction.
[0015] Preferably, the verification command is sequentially sent to the N slave devices using the N electronic switches, including:
[0016] The address query command is sent sequentially to the N slave devices using the N electronic switches in order to determine the address information of the N slave devices themselves;
[0017] The target slave device is determined based on N pieces of verification information, including:
[0018] Among the N address information, the slave device whose address information matches the address within the target station is selected as the target slave device.
[0019] Preferably, after the master device establishes communication with the target slave device, the method further includes:
[0020] After the master device finishes communicating with the target slave device, it connects the stationary terminals of all the electronic switches to the first moving terminal of the electronic switch itself.
[0021] Preferably, sending a communication request to the target slave device includes:
[0022] Upon receiving the start communication signal, communication data is sent to the target slave device.
[0023] When the preset clock signal passes through a preset number of valid edges, the transmission of communication data to the target slave device stops.
[0024] Preferably, the electronic switch is a single-pole double-throw electronic switch.
[0025] Preferred options also include:
[0026] S21: Sort the N electronic switches according to a preset order, and take the first electronic switch that the main device passes through when outputting the chip select signal as the current electronic switch;
[0027] S22: Generate a preset instruction and send the preset instruction to the slave device corresponding to the current electronic switch;
[0028] S23: Determine whether feedback information generated by the slave device corresponding to the current electronic switch according to the preset instruction has been obtained within a preset time period; if yes, proceed to S24; if no, proceed to S25.
[0029] S24: Increment the pre-design value by 1, then proceed to S25;
[0030] S25: Determine whether the current electronic switch is the last electronic switch; if yes, proceed to S27; if no, proceed to S26.
[0031] S26: Connect the stationary terminal of the current electronic switch to its corresponding second moving terminal, and use the next electronic switch as the new current electronic switch, then return to S23;
[0032] S27: Determine whether the pre-designed value is equal to N; if yes, proceed to S28; if no, proceed to S29.
[0033] S28: Determine that all the slave devices are normal;
[0034] S29: Determine that there is a fault in the slave device.
[0035] This application also provides a master-slave device communication device based on electronic switches. The device is disposed in the processor of a master device. The master device is connected to N slave devices. The master device is connected in series with N electronic switches. The first moving terminal of the i-th electronic switch is connected to the chip select signal input terminal of the corresponding slave device. The second moving terminal of the i-th electronic switch is connected to the stationary terminal of the (i+1)-th electronic switch. The stationary terminal of the first electronic switch is connected to the chip select signal output terminal of the master device. N and i are both positive integers not less than 2, and i is less than N. The master-slave device communication device based on electronic switches includes:
[0036] Memory, used to store computer programs;
[0037] A controller is used to implement the steps of the master-slave device communication method based on electronic switches as described above when executing the computer program.
[0038] This application also provides a master-slave device communication system, including N slave devices and N electronic switches, and also includes the master device as described above;
[0039] The master device is connected to N slave devices respectively, and the master device is connected in series with N electronic switches. The first moving terminal of the i-th electronic switch is connected to the chip select signal input terminal of the slave device corresponding to the electronic switch itself. The second moving terminal of the i-th electronic switch is connected to the stationary terminal of the (i+1)-th electronic switch. The stationary terminal of the first electronic switch is connected to the chip select signal output terminal of the master device. N and i are both positive integers not less than 2 and i is less than N.
[0040] This application also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps of the master-slave device communication method based on an electronic switch as described above.
[0041] In summary, this application provides a master-slave device communication method and related components based on electronic switches, relating to the field of multi-device communication. A master device is connected to multiple slave devices, each slave device corresponding to an electronic switch. The master device is connected in series with these electronic switches. The first moving terminal of each electronic switch is connected to the chip select signal input terminal of the corresponding slave device, and the second moving terminal of each electronic switch is connected to the stationary terminal of the previous electronic switch. The stationary terminal of the first electronic switch is connected to the chip select signal output terminal of the master device. When the master device receives a communication command, it generates a verification command corresponding to the communication command. The verification command is sequentially sent to N slave devices, so that the N slave devices generate N verification messages based on the verification command. The target slave device is determined based on the N verification messages. Once the target slave device is determined, the stationary terminal of the electronic switch corresponding to the target slave device is connected to its own first moving terminal, so that the master device can send a communication request to the target slave device, thereby establishing communication between the master device and the target slave device. By connecting various electronic switches in series via a single signal line to provide chip select signals to slave devices, the number of chip select signal lines is reduced, as well as wiring costs and interface complexity are lowered. Furthermore, the parallel connection method can avoid the problem of being unable to connect to other normal slave devices due to the failure of one slave device. By controlling the on and off of the electronic switches, the master device can be prevented from activating multiple chip select signals simultaneously, thereby avoiding data errors. Attached Figure Description
[0042] To more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings used in the prior art and embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0043] Figure 1 This is a schematic diagram of the structure of a communication system in the prior art;
[0044] Figure 2 A flowchart of a master-slave device communication method based on an electronic switch is provided in this application;
[0045] Figure 3 A schematic diagram of the structure of a device communication system provided in this application;
[0046] Figure 4 This application provides a schematic diagram of the structure of a master-slave device communication device based on an electronic switch. Detailed Implementation
[0047] The core of this invention is to provide a master-slave device communication method based on electronic switches and related components, which reduces the number of signal lines, wiring costs, and interface complexity. It can avoid the problem of being unable to connect with other normal slave devices due to the failure of a slave device, and can also avoid the master device activating multiple chip select signals at the same time, thereby avoiding data errors.
[0048] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0049] Please refer to Figure 2 and Figure 3 , Figure 2 A flowchart of a master-slave device communication method based on an electronic switch is provided in this application. Figure 3 This application provides a schematic diagram of a device communication system, which is applied to a processor in a master device. The master device is connected to N slave devices and connected in series with N electronic switches. The first moving terminal of the i-th electronic switch is connected to the chip select signal input terminal of the corresponding slave device, the second moving terminal of the i-th electronic switch is connected to the stationary terminal of the (i+1)-th electronic switch, and the stationary terminal of the first electronic switch is connected to the chip select signal output terminal of the master device. N and i are both positive integers not less than 2, and i is less than N. The master-slave device communication method based on electronic switches includes:
[0050] S1: When a communication command is received, a verification command corresponding to the communication command is generated;
[0051] S2: The verification command is sent sequentially to N slave devices using N electronic switches, so that the N slave devices generate N verification information according to the verification command;
[0052] S3: Determine the target device based on N verification information;
[0053] S4: When the stationary terminal of the electronic switch corresponding to the target slave device is connected to the first moving terminal of the electronic switch itself, a communication request is sent to the target slave device so that the master device and the target slave device can establish communication.
[0054] Before generating verification information, the stationary terminal of the electronic switch corresponding to the slave device is connected to the first moving terminal; after generating verification information, the stationary terminal of the electronic switch corresponding to the slave device (excluding the target slave device) is connected to the second moving terminal.
[0055] SPI (Serial Peripheral Interface) is a high-speed, full-duplex, synchronous serial communication protocol that uses four signal lines for communication: SCLK (serial clock), MOSI (master output and slave input), MISO (master input and slave output), and CS (chip select). When a master device is connected to multiple slave devices, the master device needs to provide a dedicated chip select signal for each slave device. This means that each additional slave device requires an additional CS signal line. Therefore, the number of chip select signal lines increases with the number of slave devices, leading to increased wiring costs. Furthermore, the number of signal lines is limited by the number of master device interfaces, thus limiting the maximum number of slave devices. Additionally, when the master device activates multiple chip select signals simultaneously, data corruption may occur. Currently used daisy-chain topologies for connecting master and slave devices, due to their serial nature, prevent the master device from communicating with other healthy slave devices after the failed slave device when one fails.
[0056] To address the aforementioned technical issues, in this application, all slave devices are connected to the master device via the same SPI bus. The SCLK, MOSI, and MISO signal interfaces of each slave device are respectively connected to the SCLK, MOSI, and MISO signal lines on the SPI bus. Similarly, the chip select signal interfaces of all slave devices are connected to the same CS signal line. To prevent the master device from simultaneously triggering multiple chip select signals, it is necessary to avoid the master device simultaneously verifying with multiple slave devices. Therefore, an electronic switch can be added to each slave device. This electronic switch is located at the CS signal terminal of the slave device. The electronic switch includes a stationary terminal and at least two moving terminals. The stationary terminal serves as the chip select signal input for the slave device, while one of the moving terminals is connected to the CS signal terminal of the slave device, and the second moving terminal is connected to the stationary terminal of the next electronic switch. The chip select signal output by the master device is output through the stationary terminal of the electronic switch and then through one of the moving terminals. This effectively allows for the directional control of the endpoint corresponding to the chip select signal output by the master device by controlling the output of the moving terminal of the electronic switch. Through the electronic switch, the master device can select chips from each slave device one by one.
[0057] During verification, the master device can verify the slave devices corresponding to each electronic switch in a preset order, such as the order in which the chip select signal passes through each electronic switch after output. After receiving the verification command, the slave device will determine whether it is the target slave device required by the master device. If so, the slave device will generate verification information to inform the master device that it is the target slave device; if not, the slave device will also generate verification information to inform the master device that it is not the target slave device. For example, the master device can use the address information of the target slave device as the verification command and send it to each slave device in sequence. The slave device compares the address information of the target slave device with its own address information to make a judgment. If the slave device determines that it is not the target slave device, it will control the stationary end of its corresponding electronic switch to switch to the second moving end, that is, control the stationary end of the electronic switch to connect with the second moving end, so that the signal sent by the master device from the chip select signal line can be transmitted to the next electronic switch through the electronic switch, while preventing the slave device from receiving the verification command again. After the target slave device is identified, the electronic switches of all other slave devices before the target slave device are in a state where the stationary terminal is connected to the second moving terminal, while the electronic switch of the target slave device is in a state where the stationary terminal is connected to the first moving terminal. This means that the master device only needs to output a chip select signal, and then the connection method of each electronic switch can be used to achieve the purpose of the master device selecting a certain slave device for communication and verification. In other words, at this time, only one slave device can receive the chip select signal output by the master device.
[0058] In summary, the master device is connected to multiple slave devices, each slave device corresponding to an electronic switch. The master device is connected in series with these electronic switches. The first moving terminal of each electronic switch is connected to the chip select signal input terminal of the corresponding slave device, and the second moving terminal of each electronic switch is connected to the stationary terminal of the previous electronic switch. The stationary terminal of the first electronic switch is connected to the chip select signal output terminal of the master device. The master device uses the electronic switches to verify each slave device one by one. Once a target slave device is identified, the master device sends a communication request to the target slave device to establish communication. By connecting all the electronic switches in series via a single signal line to provide chip select signals to the slave devices, the number of chip select signal lines is reduced, as well as wiring costs and interface complexity are lowered. Furthermore, the parallel connection method avoids the problem of being unable to connect to other normal slave devices due to the failure of one slave device. By controlling the on / off state of the electronic switches, the master device can be prevented from activating multiple chip select signals simultaneously, thereby avoiding data errors.
[0059] Based on the above embodiments:
[0060] In a preferred embodiment, before generating the verification instruction corresponding to the communication instruction, the method further includes:
[0061] When all N slave devices are powered on, N unused internal addresses are obtained from the preset address database. The N internal addresses are not completely identical to each other.
[0062] Each of the N internal station addresses is assigned to one of the N slave devices;
[0063] Generate verification instructions corresponding to the communication instructions, including:
[0064] Generate a query command for the address corresponding to the slave device that is required for communication instructions.
[0065] To accurately identify the target slave device, this application pre-assigns a unique identifier to each slave device. This unique identifier is used to authenticate the slave device's identity and location, ensuring the master device communicates with the correct slave device. Specifically, after both the master and slave devices are powered on, the entire system initializes. Therefore, each slave device needs to be configured after each power-on. This configuration also allows for determining the number and parameters of the slave devices to identify any faulty ones. During configuration, the master device assigns a unique internal address to each slave device sequentially by sending a station configuration frame. This provides each slave device with a unique identifier, enabling the master device to accurately identify the target slave device by comparing its internal address with the internal address corresponding to the communication command. This ensures accurate communication with the correct slave device during subsequent communication.
[0066] In addition, during configuration, each slave device can send its own basic parameter information to the master device through the site configuration frame, providing the master device with sufficient parameter information to establish a data system page, so that users can observe and operate it.
[0067] In a preferred embodiment, N electronic switches are used to sequentially send verification commands to N slave devices, including:
[0068] N electronic switches are used to sequentially send address query commands to N slave devices in order to determine the address information of each of the N slave devices.
[0069] The target device is determined based on N verification information, including:
[0070] Among N address information, the slave device whose address information matches the address within the target station is selected as the target slave device.
[0071] To accurately identify the target slave device, in this application, since each slave device has a unique internal address (i.e., a one-to-one correspondence between the internal address and the slave device), the verification command generated by the master device can be an address query command. Specifically, the master device sends the address query command to the slave device corresponding to the electronic switch closest to the chip select signal output terminal of the master device. After receiving the address query command, the slave device sends its own internal address to the master device and simultaneously controls the electronic switch to disconnect from the slave device to prevent subsequent slave devices from receiving the address query command again. After the electronic switch is disconnected from the slave device, it connects to the next electronic switch, and the next electronic switch connects to the next slave device, allowing the master device to send the address query command to the next slave device. Similarly, in practical applications, when determining whether a slave device is the target slave device, if the slave device finds that it is not the target slave device, it will switch its electronic switch to the stationary end and connect to the second moving end so that the chip select signal terminal of the master device can connect to the next slave device. Based on this, the master device generates an address query command and sends it sequentially to N slave devices. Upon receiving the command, each slave device compares the address information in the query command with its own address information and returns the comparison result to the master device. The master device then determines the address that matches the target address from the comparison results returned by the slave devices; the slave device corresponding to this address is the target slave device. This allows for accurate identification of the target slave device using address information. Furthermore, since each slave device returns its own address and connects its corresponding electronic switch to the next electronic switch, subsequent slave devices are prevented from receiving address query commands again, thus improving work efficiency.
[0072] As a preferred embodiment, after the master device and the target slave device establish communication, the method further includes:
[0073] After the master device finishes communicating with the target slave device, connect the stationary terminals of all electronic switches to the first moving terminal of the electronic switch itself.
[0074] To ensure system availability, in this application, during communication between the master device and the slave device, the states of all electronic switches corresponding to other slave devices positioned between the master and slave devices are changed. These electronic switches are all switched to their stationary ends connected to their second moving ends, allowing the chip select signal from the master device to be ultimately input to the communicating slave device via these electronic switches. It is evident that if these electronic switches remain in the stationary end connected to their second moving ends after communication between the master and slave devices ends, when the master device needs to initiate the next communication, it cannot start verification from the slave device closest to it. Furthermore, these slave devices cannot receive verification commands or chip select signals from their corresponding electronic switches, thus preventing the slave devices from controlling the direction of the electronic switches and reducing system availability. In addition, controlling the direction of each electronic switch by the master device would increase the load on the master device. Based on this, the state when the stationary terminal of the electronic switch is connected to the first moving terminal of the electronic switch itself can be regarded as the reset state, that is, the connection between the electronic switch and the slave device can be regarded as the default state. After the master device and the target slave device have finished communicating, the chip select signal will flow with the electronic switch to the last electronic switch. The second moving terminal of the last electronic switch is connected to the reset terminal of the master device. During the process of the reset signal returning to the master device, the reset signal will be transmitted to each electronic switch, so that all electronic switches are reset and the direction of the electronic switches is pointed to the slave device, thereby ensuring the availability of the system.
[0075] As a preferred embodiment, sending a communication request to the target slave device includes:
[0076] Upon receiving the start communication signal, communication data is sent to the target slave device.
[0077] When the preset clock signal passes through a preset number of valid edges, the transmission of communication data to the target slave device will stop.
[0078] To ensure that the slave device receives complete communication data, this application considers that in practical application scenarios, the master device continuously processes and transmits data, and the data generated at different times varies. Threads within the master device typically execute user instructions sequentially; that is, the master device generates the corresponding instructions and data according to the order in which it receives user instructions. If the communication data received by the slave device includes other data or is missing some, it may affect the outcome of the communication. Therefore, the application first determines the amount of communication data the master device needs to send to the slave device. Based on the data size, the master device's data transmission rate per unit time, and the slave device's data reception rate per unit time, the time required for the master device to send the communication data to the slave device is determined. Then, based on this time and the period of a preset clock signal, a preset quantity is determined. When the preset clock signal reaches a valid edge, the master device begins to send communication data to the target slave device and starts recording the number of times the preset clock signal reaches a valid edge. When the number of times the preset clock signal reaches a valid edge reaches a preset number, it means that the master device has completed the transmission of communication data. The data generated subsequently is not the communication data required by the slave device. At this time, the master device can stop sending communication data to the target slave device, thereby ensuring that the slave device receives complete communication data.
[0079] As a preferred embodiment, the electronic switch is a single-pole double-throw electronic switch.
[0080] To achieve the function of the electronic switch, this application uses a single-pole double-throw (SPDT) electronic switch. The stationary terminal of the SPDT is equivalent to its input terminal, and the moving terminal is equivalent to its output terminal. The SPDT allows control over the output direction, enabling the control of changing the output direction. Since the master device and each electronic switch are connected in series, this series connection is achieved through the stationary terminal and one moving terminal of each SPDT. The other moving terminal of the SPDT can be connected to the slave device, allowing verification commands or other chip select signals sent by the master device to be transmitted from the stationary terminal to a specific moving terminal, thus enabling the corresponding switch to receive the chip select signal from the master device. Furthermore, SPDTs offer advantages such as high lifespan, high reliability, high sensitivity, and strong anti-interference capabilities, making them well-suited for use as the electronic switch in this application.
[0081] As a preferred embodiment, it also includes:
[0082] S21: Sort the N electronic switches according to the preset order, and take the first electronic switch that the main device passes through when outputting the chip select signal as the current electronic switch;
[0083] S22: Generate a preset command and send the preset command to the slave device corresponding to the current electronic switch;
[0084] S23: Determine whether feedback information generated by the slave device corresponding to the current electronic switch according to the preset instruction has been obtained within the preset time period; if yes, proceed to S24; if no, proceed to S25.
[0085] S24: Increment the pre-design value by 1, then proceed to S25;
[0086] S25: Determine if the current electronic switch is the last electronic switch; if yes, proceed to S27; if no, proceed to S26.
[0087] S26: Connect the stationary terminal of the current electronic switch to its corresponding second moving terminal, and set the next electronic switch as the new current electronic switch, then return to S23;
[0088] S27: Determine if the pre-designed value is equal to N; if yes, proceed to S28; if no, proceed to S29.
[0089] S28: All slave devices are determined to be normal;
[0090] S29: A fault has been detected in the device.
[0091] To verify the fault status of slave devices and electronic switches, this application considers that slave devices and electronic switches may malfunction due to aging or short circuits, rendering them unusable. Therefore, it is necessary to verify their fault status. Specifically, a counter can be set inside the master device with a pre-designed value, which defaults to 0. The master device sequentially sends preset commands to the corresponding slave devices through each electronic switch. When both the slave device and the electronic switch are functioning normally, the slave device will generate feedback information and return it to the master device within a preset time period. Each time the master device successfully receives feedback information within the preset time period, the pre-designed value is incremented by 1. When the master device sends the preset command to the last slave device, since the second moving terminal of the electronic switch corresponding to the last slave device is connected to the reset terminal, a reset signal is generated and returned to the master device. When the master device receives the reset signal, it reads the pre-designed value from the counter to determine the number of slave devices. If the pre-designed value is not equal to the actual number of slave devices, it indicates that one of the slave devices is faulty. Furthermore, based on the feedback information and the specific values of the pre-designed parameters, the location of the fault can be determined. For example, when N equals 10, if the preset count value is 5, it means that the master device has received 5 feedback messages, and these feedback messages correspond to the feedback messages of the first 5 slave devices. Therefore, it can be determined that the 6th slave device has failed. Based on this, the fault status of the slave devices can be accurately verified through the pre-designed parameters.
[0092] Please refer to Figure 4 , Figure 4 This application provides a schematic diagram of a master-slave device communication device based on electronic switches. The device is housed in the processor of a master device, which is connected to N slave devices. The master device is connected in series with N electronic switches. The first moving terminal of the i-th electronic switch is connected to the chip select signal input terminal of the corresponding slave device. The second moving terminal of the i-th electronic switch is connected to the stationary terminal of the (i+1)-th electronic switch. The stationary terminal of the first electronic switch is connected to the chip select signal output terminal of the master device. N and i are both positive integers not less than 2, and i is less than N. The master-slave device communication device based on electronic switches includes:
[0093] Memory 21 is used to store computer programs;
[0094] The controller 22 is used to implement the steps of the master-slave device communication method based on electronic switches as described above when executing a computer program.
[0095] For a detailed description of the master-slave device communication apparatus provided in this application, please refer to the embodiments of the master-slave device communication method described above; further details will not be repeated here.
[0096] This application also provides a master-slave device communication system, including N slave devices and N electronic switches, and also includes the master device as described above;
[0097] The master device is connected to N slave devices. The master device is connected in series with N electronic switches. The first moving terminal of the i-th electronic switch is connected to the chip select signal input terminal of the corresponding slave device. The second moving terminal of the i-th electronic switch is connected to the stationary terminal of the (i+1)-th electronic switch. The stationary terminal of the first electronic switch is connected to the chip select signal output terminal of the master device. N and i are both positive integers not less than 2 and i is less than N.
[0098] For a detailed description of the master-slave device communication system provided in this application, please refer to the embodiments of the master-slave device communication method described above; further details will not be repeated here.
[0099] This application also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of the master-slave device communication method based on an electronic switch as described above.
[0100] For a detailed description of the computer-readable storage medium provided in this application, please refer to the embodiments of the master-slave device communication method described above; further details will not be repeated here.
[0101] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to the method section.
[0102] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.
[0103] The above description of the disclosed embodiments enables those skilled in the art to make or use the invention. Various modifications to these embodiments will be readily 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 invention. Therefore, the invention is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A master-slave device communication method based on electronic switches, characterized in that, A processor applied in a master device, wherein the master device is connected to N slave devices, and the master device is connected in series with N electronic switches. The first moving terminal of the i-th electronic switch is connected to the chip select signal input terminal of the corresponding slave device, the second moving terminal of the i-th electronic switch is connected to the stationary terminal of the (i+1)-th electronic switch, and the stationary terminal of the first electronic switch is connected to the chip select signal output terminal of the master device. N and i are both positive integers not less than 2 and i is less than N. The master-slave device communication method based on electronic switches includes: When a communication command is received, a verification command corresponding to the communication command is generated; The verification command is sequentially sent to N slave devices using N electronic switches, so that the N slave devices generate N verification messages according to the verification command; The target device is determined based on N pieces of verification information; A communication request is sent to the target slave device so that the master device can establish communication with the target slave device; Before generating the verification information, the stationary terminal of the electronic switch corresponding to the slave device is connected to the first moving terminal; after generating the verification information, the stationary terminal of the electronic switch corresponding to the slave device (excluding the target slave device) is connected to the second moving terminal. Before generating the verification instruction corresponding to the communication instruction, the method further includes: When all N slave devices are powered on, N unused internal addresses are obtained from the preset address library. The N internal addresses are not completely identical to each other. Each of the N internal station addresses is assigned to one of the N slave devices; Generate the verification instruction corresponding to the communication instruction, including: Generate the address query instruction corresponding to the slave device that requires the communication instruction; After the master device establishes communication with the target slave device, the method further includes: After the master device finishes communicating with the target slave device, it connects the stationary terminals of all the electronic switches to the first moving terminal of the electronic switch itself.
2. The master-slave device communication method based on electronic switches as described in claim 1, characterized in that, The verification command is sequentially sent to N slave devices using N electronic switches, including: The address query command is sent sequentially to the N slave devices using the N electronic switches in order to determine the address information corresponding to the N slave devices; The target slave device is determined based on N pieces of verification information, including: Among the N address information, the slave device whose address information matches the address within the target station is designated as the target slave device.
3. The master-slave device communication method based on electronic switches as described in claim 1, characterized in that, Sending a communication request to the target slave device includes: Upon receiving the start communication signal, communication data is sent to the target slave device. When the preset clock signal passes through a preset number of valid edges, the transmission of communication data to the target slave device stops.
4. The master-slave device communication method based on electronic switches as described in claim 1, characterized in that, The electronic switch is a single-pole double-throw electronic switch.
5. The master-slave device communication method based on electronic switches as described in any one of claims 1 to 4, characterized in that, Also includes: S21: Sort the N electronic switches according to a preset order, and take the first electronic switch that the main device passes through when outputting the chip select signal as the current electronic switch; S22: Generate a preset instruction and send the preset instruction to the slave device corresponding to the current electronic switch; S23: Determine whether feedback information generated by the slave device corresponding to the current electronic switch according to the preset instruction has been obtained within a preset time period; if yes, proceed to S24; if no, proceed to S25. S24: Increment the pre-design value by 1, then proceed to S25; S25: Determine whether the current electronic switch is the last electronic switch; if yes, proceed to S27; if no, proceed to S26. S26: Connect the stationary terminal of the current electronic switch to its corresponding second moving terminal, and use the next electronic switch as the new current electronic switch, then return to S23; S27: Determine whether the pre-designed value is equal to N; if yes, proceed to S28; if no, proceed to S29. S28: Determine that all the slave devices are normal; S29: Determine that there is a fault in the slave device.
6. A master-slave device communication device based on an electronic switch, characterized in that, The master-slave communication device based on electronic switches is disposed in the processor of the master device. The master device is connected to N slave devices respectively. The master device is connected in series with N electronic switches. The first moving terminal of the i-th electronic switch is connected to the chip select signal input terminal of the corresponding slave device. The second moving terminal of the i-th electronic switch is connected to the stationary terminal of the (i+1)-th electronic switch. The stationary terminal of the first electronic switch is connected to the chip select signal output terminal of the master device. N and i are both positive integers not less than 2 and i is less than N. The master-slave communication device based on electronic switches includes: Memory, used to store computer programs; A controller, used to implement the steps of the master-slave device communication method based on an electronic switch as described in any one of claims 1 to 5 when executing the computer program.
7. A master-slave device communication system, characterized in that, It includes N slave devices and N electronic switches, and also includes the master device as described in claim 6; The master device is connected to N slave devices respectively, and the master device is connected in series with N electronic switches. The first moving terminal of the i-th electronic switch is connected to the chip select signal input terminal of the slave device corresponding to the electronic switch itself. The second moving terminal of the i-th electronic switch is connected to the stationary terminal of the (i+1)-th electronic switch. The stationary terminal of the first electronic switch is connected to the chip select signal output terminal of the master device. N and i are both positive integers not less than 2 and i is less than N.
8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the steps of the master-slave device communication method based on an electronic switch as described in any one of claims 1 to 5.
Citation Information
Patent Citations
RS485 based communication method, device and communication system
CN106294236A
Serial communication branching device and serial communication system
CN107219822A