Serial communication system and method
By using a complex programmable logic device (CPLD) in an embedded device to achieve shared serial bus communication between the master device and multiple slave devices, and by adopting time-division polling and complex logic, the efficiency and bandwidth of the serial communication system are improved, and the problem of low communication efficiency in traditional serial network is solved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SHANGHAI MOOREWATT ENERGY TECHNOLOGY CO LTD
- Filing Date
- 2025-09-30
- Publication Date
- 2026-05-29
Smart Images

Figure CN121233522B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of communications, and in particular to a serial communication system and method. Background Technology
[0002] Serial communication is a common communication method in embedded devices. Generally speaking, serial ports on a printed circuit board (PCB) are one-to-one communication. When multiple chips on a PCB need to exchange data, N-1 (N is the number of chips) independent serial ports are required. However, the pin resources of chips in embedded devices are limited, so serial port networking is used for communication.
[0003] However, traditional serial port networking suffers from low communication efficiency. Summary of the Invention
[0004] Therefore, it is necessary to provide a serial communication system and method to address the aforementioned technical problems.
[0005] In a first aspect, one embodiment of this application provides a serial communication system, including a master device, a first slave device, at least one second slave device, a serial bus, and a complex programmable logic device; the complex programmable logic device includes a master pin, a first slave pin, and at least one second slave pin; the master pin is connected to the master device through the serial bus, the first slave pin is connected to the first slave device through the serial bus, and the second slave pin is connected to the second slave device through the serial bus;
[0006] Complex programmable logic devices for use in wired-AND logic, enabling a master device to communicate with a first slave device and at least one slave device.
[0007] In one embodiment, the master device sends a first message to the target slave device via a complex programmable logic device; the first message includes a read request and / or a write request; the target slave device is a first slave device and / or a second slave device in a serial communication system.
[0008] The target receives a first message from the device, and if the first message includes a read request, returns a second message based on the read request through a complex programmable logic device.
[0009] In one embodiment, when the target slave device includes multiple slave devices, the master device uses a time-division polling method to receive the second messages returned by the multiple slave devices.
[0010] In one embodiment, the communication duration between the master device and the slave device is less than a preset timeout duration; the preset ultrasound duration is determined according to a time-division polling method.
[0011] In one embodiment, the communication period for the master device to send messages is greater than the total duration of communication between the master device and multiple slave devices.
[0012] In one embodiment, the serial bus includes a first bus and a second bus, and the main pin includes a first sub-pin and a second sub-pin. The transmitting end of the master device is connected to the first sub-pin through the first bus, and the receiving end of the master device is connected to the second sub-pin through the second bus.
[0013] The first slave pin includes a third sub-pin and a fourth sub-pin. The receiving end of the first slave device is connected to the third sub-pin through the first bus, and the transmitting end of the first slave device is connected to the fourth sub-pin through the second bus.
[0014] The second slave pin includes a fifth sub-pin and a sixth sub-pin. The receiving end of the second slave device is connected to the fifth sub-pin through the first bus, and the transmitting end of the second slave device is connected to the sixth sub-pin through the second bus.
[0015] In one embodiment, the complex programmable logic device is also used to communicate with the master device via a main pin.
[0016] Secondly, one embodiment of this application provides a serial communication method applied to a master device in a serial communication system as described in the first aspect above, the method comprising:
[0017] A first message is sent from a complex programmable logic device in a serial communication system to a target slave device in the serial communication system; the first message includes a read request and / or a write request; the target slave device is a first slave device and / or a second slave device in the serial communication system.
[0018] If the first message includes a read request, the target device receives a second message returned by the target device via a complex programmable logic device based on the read request.
[0019] In one embodiment, the target slave device includes multiple slave devices, receiving a second message returned by the target slave device based on a read request via a complex programmable logic device, including:
[0020] The system receives second messages from multiple slave devices based on read requests, processed through complex programmable logic devices, at different time intervals.
[0021] In one embodiment, the communication period for sending messages is greater than the total duration of communication with multiple slave devices.
[0022] In one embodiment, the method further includes:
[0023] Send a first message to the complex programmable logic device (CPLD) so that the CPLD receives and parses the first message.
[0024] Thirdly, one embodiment of this application provides a serial communication method applied to a first slave device and / or a second slave device in a serial communication system as described in the first aspect above. The method includes:
[0025] Receive the first message sent by the master device in the serial communication system through a complex programmable logic device; the first message includes a read request and / or a write request.
[0026] If the first message includes a read request, a second message is sent to the master device via a complex programmable logic device based on the read request.
[0027] In one embodiment, a second message is sent to the master device via a complex programmable logic device based on a read request, including:
[0028] Based on the read request, a second message is sent to the master device via a complex programmable logic device after a preset time period; the preset time period corresponds to the first slave device and / or the second slave device.
[0029] In one embodiment, the first message includes a first checksum, and the method further includes:
[0030] The second checksum is determined based on the first received message, and the first and second checksums are used to determine whether the first received message is normal.
[0031] In one embodiment, receiving a first message sent by the master device in the serial communication system via a complex programmable logic device includes:
[0032] Receive the first message sent by the master device through the complex programmable logic device, and determine whether the address information in the first message is consistent with the preset address information;
[0033] If the address information in the first message matches the preset address information, the first message is parsed to obtain the read request and / or write request.
[0034] This application provides a serial communication system and method. The system includes a master device, a first slave device, at least one second slave device, a serial bus, and a complex programmable logic device (CPL). The CPL includes a master pin, a first slave pin, and at least one second slave pin. The master pin is connected to the master device via the serial bus, the first slave pin is connected to the first slave device via the serial bus, and the second slave pin is connected to the second slave device via the serial bus. The CPL is used for wired-AND logic, enabling communication between the master device and the first slave device and at least one second slave device. In this embodiment, the master device shares the serial bus with the first slave device and at least one second slave device. The CPL internally implements wired-AND logic, which is simple and equivalent to the master device being directly connected to the first slave device via the first slave pin and to at least one second slave device via the second slave pin, without any intermediate conversion. This provides a physical basis for efficient communication, thereby improving the communication efficiency and bandwidth of the serial communication system. Attached Figure Description
[0035] To more clearly illustrate the technical solutions in the embodiments of this application or the conventional technology, the drawings used in the description of the embodiments or the conventional technology will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0036] Figure 1 This is a schematic diagram of the structure of a serial communication system provided in one embodiment of this application;
[0037] Figure 2 A timing diagram illustrating the transmission of messages between a master device and a slave device according to an embodiment of this application;
[0038] Figure 3 A timing diagram illustrating the transmission of messages between a master device and a slave device, provided for another embodiment of this application;
[0039] Figure 4 This is a schematic diagram of the structure of a serial communication system provided in another embodiment of this application;
[0040] Figure 5 This is a schematic diagram of push-pull output and open-drain output in one embodiment of this application;
[0041] Figure 6 This is a schematic diagram of the TX waveform in one embodiment of this application;
[0042] Figure 7 This is a schematic diagram of the TX waveform in another embodiment of this application;
[0043] Figure 8This is a flowchart illustrating the steps of a serial communication method provided in one embodiment of this application.
[0044] Figure 9 A flowchart illustrating the steps of a serial communication method provided in another embodiment of this application;
[0045] Figure 10 A flowchart illustrating the steps of a serial communication method provided in another embodiment of this application;
[0046] Figure 11 This is a flowchart illustrating the steps of a serial communication method provided in another embodiment of this application.
[0047] Explanation of reference numerals in the attached figures:
[0048] 100, Master device; 200, First slave device; 300, Second slave device; 400, Serial bus; 410, First bus; 420, Second bus; 500, Complex programmable logic device; 510, Master pin; 511, First sub-pin; 512, Second sub-pin; 520, First slave pin; 521, Third sub-pin; 522, Fourth sub-pin; 530, Second slave pin; 531, Fifth sub-pin; 532, Sixth sub-pin. Detailed Implementation
[0049] To facilitate understanding of this application, a more complete description will be provided below with reference to the accompanying drawings, which illustrate embodiments of the present application. However, the present application can be implemented in many different forms and is not limited to the embodiments described herein. Rather, these embodiments are provided so that the disclosure of this application will be thorough and complete.
[0050] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the application.
[0051] It is understood that the term "connection" in the following embodiments should be interpreted as "electrical connection," "communication connection," etc., if the connected circuits, modules, units, etc., transmit data through electrical signals. Unless otherwise specified, the term "connection" in the following embodiments can refer to direct or indirect connections.
[0052] It is understandable that "at least one" refers to one or more, and "multiple" refers to two or more. "At least a part of an element" refers to part or all of an element.
[0053] When used herein, the singular forms of “a,” “an,” and “the” may also include the plural forms unless the context clearly indicates otherwise. It should also be understood that the terms “comprising / including” or “having,” etc., specify the storage of the stated features, integrals, steps, operations, components, parts, or combinations thereof, but do not preclude the possibility of the presence or addition of one or more other features, integrals, steps, operations, components, parts, or combinations thereof. Meanwhile, the term “and / or” as used in this specification includes any and all combinations of the associated listed items.
[0054] The technical solution of this application and how it solves the technical problems will be described in detail below with specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments. The embodiments of this application will be described below with reference to the accompanying drawings.
[0055] First, before introducing the technical solutions of the embodiments disclosed in this application, the background technology or technological evolution on which the embodiments of this application are based will be introduced. In the field of communication technology, serial communication is a common communication method in embedded devices. Generally speaking, serial ports on printed circuit boards (PCBs) are one-to-one communication. When multiple chips on a PCB need to exchange data, N-1 (N is the number of chips) independent serial ports are required. However, the pin resources of chips in embedded devices are limited. If each chip only has one serial port for data exchange, it is necessary to consider using serial port networking for communication. In the prior art, serial port networking generally includes several categories such as shared bus, serial port expansion, and serial port data exchange. Shared bus technology implements a master-slave communication architecture through wired-AND. This technology has a simple physical layer, but the communication rate and bandwidth are limited, making it suitable for low-speed, small-scale applications. This application provides a serial communication system to address the problem of low communication efficiency in shared bus technology.
[0056] Please see Figure 1 One embodiment of this application provides a serial communication system, including a master device 100, a first slave device 200, at least one second slave device 300, a serial bus 400, and a complex programmable logic device 500.
[0057] The master device 100 can be a microcontroller unit (MCU), also known as a single-chip microcomputer. The first slave device 200 and at least one second slave device 300 can also both be MCUs. The serial bus 400 is a communication interface technology that transmits data bit-by-bit, its core feature being that it requires only a small number of physical lines to achieve data interaction between devices. A complex programmable logic device (CPLD) is a device that implements various complex logic functions through programming without the need to design application-specific integrated circuits (ASICs).
[0058] The complex programmable logic device 500 includes a master pin 510, a first slave pin 520, and at least one second slave pin 530. The master pin 510 is connected to the master device 100 via a serial bus 400, the first slave pin 520 is connected to the first slave device 200 via the serial bus 400, and the second slave pin 530 is connected to the second slave device 300 via the serial bus 400.
[0059] The number of second slave pins 530 can be the same as or greater than the number of second slave devices 300. When the number of second slave pins 530 is greater than the number of second slave devices 300, it facilitates the subsequent expansion of the second slave devices 300 and improves the practicality of the serial communication system.
[0060] The complex programmable logic device 500 is used for wired-AND logic to enable the master device 100 to communicate with a first slave device 200 and at least one second slave device 300.
[0061] The wired-AND logic is a pre-programmed sequence in the CPLD. It can be understood that the CPLD includes a logic module pre-programmed with the corresponding wired-AND logic, enabling the implementation of wired-AND logic. The CPLD connects the master device 100 and the first slave device 200 via the master pin 510 and the serial bus 400, enabling communication between the master device 100 and the first slave device 200. The CPLD also connects the master device 100 and at least one second slave device 300 via the first slave pin 520 and the serial bus 400, enabling communication between the master device 100 and at least one second slave device 300.
[0062] The serial communication system provided in this application includes a master device 100, a first slave device 200, at least one second slave device 300, a serial bus 400, and a complex programmable logic device 500. The complex programmable logic device 500 includes a master pin 510, a first slave pin 520, and at least one second slave pin 530. The master pin 510 is connected to the master device 100 via the serial bus 400, the first slave pin 520 is connected to the first slave device 200 via the serial bus 400, and the second slave pin 530 is connected to the second slave device 300 via the serial bus 400. The complex programmable logic device 500 is used for wired-AND logic, enabling communication between the master device 100, the first slave device 200, and at least one second slave device 300. In this embodiment, the master device 100 shares a serial bus 400 with the first slave device 200 and at least one second slave device 300. The complex programmable logic device 500 internally implements wired-AND logic, which is simple. This is equivalent to the master device 100 being directly connected to the first slave device 200 through the first slave pin 520, and the master device 100 being directly connected to at least one second slave device 300 through the second slave pin 530, without any intermediate conversion. This provides a physical basis for efficient communication, thereby improving the communication efficiency and bandwidth of the serial communication system.
[0063] In one embodiment, the master device 100 sends a first message to the target slave device via a complex programmable logic device 500; the first message includes a read request and / or a write request; the target slave device is a first slave device and / or a second slave device in a serial communication system. Upon receiving the first message, if the first message includes a read request, the target slave device returns a second message based on the read request via the complex programmable logic device 500.
[0064] The master device 100 transmits a first message based on the wired-AND logic within the complex programmable logic device 500. The first slave device 200 and / or the second slave device 300, which are connected to the complex programmable logic device 500, can receive the first message. The first message may include a read request sent by the master device 100, or a write request sent by the master device 100, or both a read request and a write request sent by the master device 100.
[0065] After receiving the first message, the first slave device 200 and / or the second slave device 300 compare the address information included in the first message with preset address information to determine whether the address information is the same as the preset address information. If the address information is the same as the preset address information, the first slave device 200 and / or the second slave device 300 corresponding to the preset address information is identified as the target slave device. The preset address information is the address information of the first slave device 200 and / or the second slave device 300 itself. Specifically, after receiving the first message, the first slave device 200 parses the first message to obtain the address information in the first message, compares the address information with the preset address information corresponding to the first slave device 200, and if the address information is the same as the preset address information, the first slave device 200 is identified as the target slave device. After receiving the first message, any second slave device 300 parses the first message to obtain the address information in the first message, compares the address information with the preset address information corresponding to the second slave device 300, and determines the second slave device 300 corresponding to the preset address information that is the same as the address information as the target slave device.
[0066] Upon receiving the first message, the target slave device parses it to determine the specific request type included within. If the target slave device determines that the first message includes a read request, it will send a second message based on the read request and transmit the second message to the master device 100 using CPLD wired-AND logic. If the target slave device determines that the first message includes a write request, it will write the data corresponding to the write request into itself. If the target slave device determines that the first message includes both a read request and a write request, it will write the data corresponding to the write request into itself, send a second message based on the read request, and transmit the second message to the master device 100 using CPLD wired-AND logic.
[0067] In this embodiment, the first message sent by the master device 100 may include a read request and a write request. By merging the read request and the write request into the same message, the target slave device can receive the read request and the write request in one communication session, which can save communication bandwidth and improve communication efficiency.
[0068] In one embodiment, when the target slave device includes multiple slave devices, the master device uses a time-division polling method to receive the second messages returned by the multiple slave devices.
[0069] The target slave device may include multiple slave devices, meaning that the preset address information of the multiple slave devices is the same as the address information in the first message. The multiple slave devices included in the target slave device may be a first slave device 200 and at least one second slave device 300, or multiple second slave devices 300.
[0070] When multiple slave devices send a second message to the master device 100 via CPLD-based wired-AND logic, the master device 100 receives the second messages returned by the multiple slave devices using a time-division round-robin approach. It can be understood that each slave device returns a second message to the master device 100 after a preset time period. The preset time period can be included in the first message sent by the master device 100.
[0071] In an optional embodiment, it is assumed that the target device includes a first slave device 200, a first second slave device, and a second second slave device. The master device 100 receives a second message returned by the first slave device 200 after a first time period, the master device 100 receives a second message returned by the first second slave device after a second time period, and the master device 100 receives a second message returned by the second second slave device after a third time period. The first time period, the second time period, and the third time period are different time periods.
[0072] In this embodiment, when the target slave device includes multiple slave devices, the master device 100 uses a time-division polling method to receive the second messages returned by the multiple slave devices. This can avoid multiple slave devices competing for the shared serial bus, solve the congestion problem of serial communication, and thus avoid data corruption in the returned second messages, thereby improving the practicality of the serial communication system.
[0073] In one embodiment, the communication duration between the master device and the slave device is less than a preset timeout duration; the preset timeout duration is determined according to a time-sharing polling method.
[0074] The master device can allocate a time slice, i.e., a preset timeout duration, to each slave device it communicates with using a time-division round-robin method. The preset timeout duration can be included in the first message sent by the master device. In actual communication, the communication duration between the master device and the slave device must be less than the preset timeout duration.
[0075] Understandably, the master device allocates time slices to multiple slave devices it communicates with using a time-sharing polling method. The time slices for the multiple slave devices can be the same or different. That is, the communication duration between the master device and the first slave device is less than the time slice allocated by the master device for the first slave device, and the communication duration between the master device and the second slave device is less than the time slice allocated by the master device for the second slave device.
[0076] In this embodiment, the communication duration between the master device and the slave device is less than the preset timeout duration. This avoids the problem of the master device and multiple slave devices competing for the shared serial bus, solves the congestion problem in serial communication, and avoids data corruption in the messages sent between the master device and the slave device, thereby improving the practicality of the serial communication system.
[0077] In one embodiment, data transmitted via the serial bus is sent byte by byte, while the first message sent by the master device 100 and the second message returned by the target slave device are transmitted frame by frame. Each frame contains several bytes of data of variable length, requiring a timeout mechanism for frame fragmentation. After receiving each byte, the target slave device restarts its timer. If no new data is received within a certain time period, it considers a frame complete and then parses the received first message. If the first message includes a read request, the target slave device returns a second message to the master device 100; sending the second message itself takes time. The master device 100 also needs time to fragment the frame after receiving the second message. Based on this, the time between the master device 100 sending the first message and the master device 100 receiving the second message returned by the slave device includes multiple time periods: T1: the time period for the master device to send the first message; T2: the timeout period for the target slave device to receive the first message; T3: the time period for the target slave device to receive the first message and start returning the second message; T4: the time period for the target slave device to return the second message; and T5: the timeout period for the master device to receive the second message. T2 and T5 are the same and fixed; T3 depends on the scheduling cycle of the serial communication system, which is controllable for a real-time system; T1 and T4 increase with the number of messages and can also be calculated. Thus, the delay time Ta after the master device finishes sending a message to a slave device can be expressed as: Ta = T1 + T2 + T3 + T4 + T5. By increasing the serial port baud rate, more messages can be sent per unit time, thereby reducing T1 and T4 and improving communication efficiency and bandwidth. By optimizing the message receiving mechanism of master device 100, first slave device 200, and at least one second slave device 300, T2 and T5 can be reduced. Specifically, the receiving mechanism parses the received message according to the message format while receiving, and stops receiving after receiving a complete message frame. This compresses T2 and T5, further improving the communication efficiency and bandwidth of the serial communication system. By increasing the scheduling cycle of the serial communication system, T3 can be reduced, improving communication efficiency and bandwidth. Specifically, as soon as the target slave device receives data, it immediately parses it and returns a second message, thus compressing T3 to the microsecond level.
[0078] In a specific embodiment, the serial port baud rate is 115200 baud, T2=T5=4ms, T3=1ms, then Ta=T1+T4+9. Assuming the master device 100 sends the first message and receives the second message of the same length to all slave devices, the time for reading and writing to all slave devices within one cycle is 3*Ta. If the communication cycle is 100ms, then Ta is 33ms, leaving the time for message transmission and reception as T1+T4=33–9=22ms.
[0079] In a specific embodiment, the timing of message transmission between the master device 100 and the slave device is as follows: Figure 2 As shown. Figure 2 The diagram shows a timing sequence of a master device sending a first message to slave devices 1 and 2, and slave device 1 returning a second message to the master device. Figure 2 In this diagram, TX represents the transmitting end, RX represents the receiving end, and Tout is the timeout period. This timeout period must be greater than the delay time (the total duration of communication between the master device and slave device 1 or slave device 2) Ta, i.e., Tout > Ta, to avoid serial bus contention.
[0080] In one embodiment, the communication period for the master device 100 to send messages is greater than the total duration of communication between the master device 100 and multiple slave devices.
[0081] The master device 100 sends messages periodically, and the communication period when the master device 100 sends messages needs to be greater than the total actual time used by the master device 100 in communicating with multiple slave devices.
[0082] The timing sequence for communication between master device 100 and multiple slave devices (slave device 1, slave device 2, and slave device 3) is as follows: Figure 3 As shown. Figure 3 In this context, Tperiod represents the communication period, and Tunit is the total time required within a single period for the master device to send the first message to multiple slave devices, and for the multiple slave devices to return the second message. Assuming the communication time for multiple slave devices is the same, Tout, then Tunit = 3 * Tout. Tunit must satisfy the condition Tunit... <Tperiod。
[0083] In this embodiment, the communication period for the master device 100 to send messages is greater than the total communication time between the master device and multiple slave devices. This satisfies the condition for periodic communication in the serial communication system, thereby improving the practicality of the serial communication system.
[0084] In one embodiment, such as Figure 4As shown, the serial bus 400 includes a first bus 410 and a second bus 420. The main pin 510 includes a first sub-pin 511 and a second sub-pin 512. The transmitting end TX of the master device 100 is connected to the first sub-pin 511 through the first bus 410, and the receiving end RX of the master device 100 is connected to the second sub-pin 512 through the second bus 420.
[0085] The first slave pin 520 includes a third sub-pin 521 and a fourth sub-pin 522. The receiving end RX of the first slave device 200 is connected to the third sub-pin 521 through the first bus 410, and the transmitting end TX of the first slave device 200 is connected to the fourth sub-pin 522 through the second bus 420.
[0086] The second slave pin 530 includes a fifth sub-pin 531 and a sixth sub-pin 532. The receiving end RX of the second slave device 300 is connected to the fifth sub-pin 531 through the first bus 410, and the transmitting end TX of the second slave device 300 is connected to the sixth sub-pin 532 through the second bus 420.
[0087] The serial bus 400 includes a bus connecting the master device 100 and the CPLD, a bus connecting the first slave device 200 and the CPLD, and a bus connecting the second slave device 300 and the CPLD. For the bus connecting the master device 100 and the CPLD, the first end of the first bus 410 is connected to the transmitting end TX of the master device 100, and the second end of the first bus 410 is connected to the first sub-pin 511. The first end of the second bus 420 is connected to the receiving end RX of the master device 100, and the second end of the second bus 420 is connected to the second sub-pin 512, thus establishing the connection between the master device 100 and the CPLD. For the bus connecting the first slave device 200 and the CPLD, the first end of the first bus 410 is connected to the receiving end RX of the first slave device 200, the second end of the first bus 410 is connected to the third sub-pin 521, the first end of the second bus 420 is connected to the transmitting end TX of the first slave device 200, and the second end of the second bus 420 is connected to the fourth sub-pin 522, thus establishing the connection between the first slave device 200 and the CPLD. For the bus connecting the second slave device 300 and the CPLD, the first end of the first bus 410 is connected to the receiving end RX of the second slave device 300, the second end of the first bus 410 is connected to the fifth sub-pin 531, the first end of the second bus 420 is connected to the transmitting end TX of the second slave device 300, and the second end of the second bus 420 is connected to the sixth sub-pin 532, so as to realize the connection between the second slave device 300 and the CPLD.
[0088] In this embodiment, based on the wired-AND logic of the CPLD, by setting the first sub-pin 511, the second sub-pin 512, the third sub-pin 521, the fourth sub-pin 522, the fifth sub-pin 531 and the sixth sub-pin 532, the transmitting end of the master device 100, the receiving end of the first slave device 200 and the receiving end RX of at least one second slave device 300 can share the first bus 410, and the receiving end RX of the master device 100, the transmitting end TX of the first slave device 200 and the transmitting end TX of at least one second slave device 300 can share the second bus 420. This can provide a physical basis for efficient communication, thereby improving the communication efficiency of the serial communication system.
[0089] In one embodiment, the transmitter TX of the master device 100 supports push-pull output and open-drain output. A schematic diagram of push-pull output and open-drain output is shown below. Figure 5 As shown. Figure 5 The diagram on the left shows a push-pull output, where the message sent by the master device 100 is output to the first bus 410 in a push-pull manner via two field-effect transistors. The diagram on the right shows an open-drain output, where the message sent by the master device 100 is output to the first bus 410 in an open-drain manner via a resistor R and a field-effect transistor. Here, TX represents the transmitting end of the master device 100. That is, at a baud rate of 500Kbps, the TX waveform of the transmitting end of the master device 100 in the open-drain output mode is as follows: Figure 6 As shown, the TX waveform at the transmitter of the master device 100 corresponding to the push-pull output mode is as follows: Figure 7 As shown. From Figure 7 As can be seen, the TX waveform is stable, and the transition edges between high and low levels are relatively steep, enabling it to support higher baud rates. The master device 100 uses a push-pull output method to output messages, which improves the communication efficiency of the serial communication system.
[0090] Traditional wired-AND logic on a shared bus, where multiple devices connect to the same bus for data transmission, suffers from limitations. Since the transmitters (TX) of these devices are connected to the same bus, if the TX output is push-pull, one device's TX cannot pull the bus level low, hindering network communication and preventing high-baud-rate communication. Therefore, conventional wired-AND logic only supports open-drain outputs and not push-pull outputs. This application, however, utilizes a complex programmable logic device (500) to implement wired-AND logic, supporting both push-pull and open-drain outputs.
[0091] In an optional embodiment, the serial communication system in this application mainly includes a communication approach for the master device 100 and a communication approach for the slave device.
[0092] For the communication approach of the master device 100, the transmitting end TX of the master device 100 is connected to the first sub-pin 511 of the CPLD. Internally, the CPLD uses wired-AND logic to transmit the messages sent by the master device 100 to the corresponding target slave device's receiving end RX via the slave pin. This enables a direct connection between the transmitting end TX of the master device 100 and the receiving end RX of the target slave device. Specifically, the transmitting end TX of the master device 100 is connected to the first sub-pin 511 of the CPLD. Internally, the CPLD samples the messages input from the first sub-pin 511 to obtain digitized 0 and 1 signals. The CPLD performs clock synchronization processing on the digitized 0 and 1 signals to ensure that the received messages and the internal processing circuit of the CPLD have the same clock cycle. Under this clock cycle, the digitized 0 and 1 signals are assigned to the target slave device, and the target slave device's signals are output from the slave pin of the CPLD to the corresponding target slave device. When the target slave device includes multiple slave devices, at this clock cycle, the digitized 0 and 1 signals are simultaneously assigned to the signals of the multiple slave devices and output to the corresponding slave devices through the slave pins of the CPLD. The internal clock frequency of the CPLD is very high, reaching over 100MHz. Messages sent by the master device 100 can reach the receiver RX of the target slave device very quickly and almost simultaneously. This forms a single-bus network between the transmitter TX of the master device 100 and the receiver RX of the multiple slave devices. The level on this bus is determined by the transmitter TX of the master device 100; that is, when the transmitter TX of the master device 100 is high, the receiver RX of all slave devices is also high, and vice versa. The transmitter TX of the master device 100 can use a push-pull output mode to achieve high-speed communication.
[0093] For the communication approach at the slave device end, the slave device's transmitter (TX) is connected to the CPLD via the CPLD's slave pin. The CPLD is responsible for receiving all replies from the slave devices, implementing wired-AND logic internally, and finally sending them to the master device 100's receiver (RX). Specifically, the slave device's transmitter (TX) is connected to the CPLD's slave pin. The CPLD internally samples the messages input from the slave pin to obtain digitized 0 and 1 signals. The CPLD performs clock synchronization processing on the received digitized 0 and 1 signals to ensure that the received digital signals have the same clock beat. All slave devices' transmitters (TX) are connected to the CPLD's slave pin via the second bus 420. All slave devices' transmitters (TX) can use a push-pull output method to achieve high-speed communication. The CPLD's internal wired-AND logic performs a logical AND operation on the clock-synchronized signals to obtain a new digital signal. This digital signal is then sent to the master device 100's receiver (RX) via the CPLD's master pin 510. The CPLD has a very high internal clock frequency, exceeding 100MHz. Messages sent by slave devices can reach the receiver RX of the master device 100 very quickly. This allows multiple slave devices' transmitters TX and the master device 100's receiver RX to form a single-bus network. The input of this bus is the transmitters TX of multiple slave devices, and the output is the master device's receiver RX. When any slave device's transmitter TX is low, the master device 100's receiver RX is low; only when all slave devices' transmitters TX are high will the master device 100's receiver RX be high.
[0094] In one embodiment, the complex programmable logic device 500 is also used to communicate with the master device 100 via the main pin 510.
[0095] It is understandable that, such as Figure 4 As shown, the CPLD can act as a slave device corresponding to the master device 100. The CPLD is pre-programmed with the corresponding slave device, that is, the CPLD also includes a slave device module. This slave device module can receive the first message sent by the master device 100 through the master pin 510, and if the first message includes a read request, it can return a second message to the master device 100 through the master pin 510.
[0096] In this embodiment, the CPLD is also used to communicate with the master device 100 through the main pin 510. That is, the CPLD can not only be used to enable the master device 100 to communicate with the first slave device 200 and at least one second slave device 300, but can also be used as a slave device. Such a CPLD has multiple uses and can reuse the hardware resources of the CPLD, thereby improving the practicality of the serial communication system.
[0097] Please see Figure 8One embodiment of this application provides a serial communication method applied to a master device in a serial communication system as described in the above embodiments. The method includes the following steps:
[0098] Step 801: Based on the wired-AND logic of the complex programmable logic device in the serial communication system, a first message is sent to the target slave device in the serial communication system; the first message includes a read request and / or a write request; the target slave device is the first slave device and / or the second slave device in the serial communication system.
[0099] The target slave device can be one slave device or multiple slave devices. Specifically, the target slave device can be a first slave device, a second slave device, a first slave device and at least one slave device, or multiple second slave devices.
[0100] The master device sends the first message to the CPLD in the serial communication system via the serial bus. Based on the wired-AND logic of the CPLD, the first message is then sent to the target slave device. This is equivalent to the master device directly sending the first message to the target slave device via the serial bus. A description of the first message can be found in the detailed description of the above embodiments, and will not be repeated here.
[0101] Step 802: If the first message includes a read request, receive the second message returned by the target slave device based on the read request via the wired-AND logic of the complex programmable logic device.
[0102] After receiving the first message, the target slave device parses it to determine the specific request type included within. If the target slave device determines that the first message includes a read request, it will send a second message based on the read request and transmit the second message to the master device using the CPLD's wired-AND logic. In other words, if the master device sends a first message to the target slave device that includes a read request, it will receive a second message returned by the target slave device based on that read request.
[0103] In an optional embodiment, if the target slave device determines that the first message includes a write request, the target slave device writes the data corresponding to the write request into the target slave device. If the target slave device determines that the first message includes both a read request and a write request, the target slave device writes the data corresponding to the write request into the target slave device, and sends back a second message based on the read request. The second message is then transmitted to the master device based on the wired-AND logic of the CPLD. The master device receives the second message returned by the target slave device based on the read request.
[0104] The serial communication method provided in this application embodiment enables communication between a master device and a target slave device using a serial bus and a CPLD. The CPLD internally supports wired-AND logic, effectively allowing the master device to directly connect to the first slave device via the serial bus, and to at least one second slave device via the serial bus, without any intermediate conversion. This provides a physical foundation for efficient communication. Transmitting the first and second messages based on the CPLD's wired-AND logic improves the efficiency and bandwidth of serial communication, thereby enhancing the practicality of the serial communication method. Furthermore, when the first message includes both read and write requests, the target slave device can receive both requests within a single communication session, saving communication bandwidth and improving communication efficiency.
[0105] In one embodiment, the target slave device includes multiple slave devices. In this case, an implementation involves receiving a second message returned by the target slave device based on a read request via wired-AND logic of a complex programmable logic device. This implementation includes:
[0106] The system receives second messages from multiple slave devices at different time periods, based on read requests, through the wired-AND logic of a complex programmable logic device.
[0107] Different time periods can be included in the first message. When the target slave device includes multiple slave devices, each slave device parses different time periods from the first message and returns a second message to the master device according to the read request based on the CPLD's wired-AND logic, with each slave device returning a second message for a different time period. Correspondingly, the master device can receive the second messages returned by the slave devices at different time periods. Since the different time periods have a chronological order, the second messages received by the master device from different slave devices also follow a chronological order.
[0108] In this embodiment, the master device receives second messages returned by multiple slave devices based on read requests through the wired-AND logic of a complex programmable logic device at different time periods. This avoids multiple slave devices competing for the shared serial bus, solves the congestion problem in serial communication, and avoids data corruption in the returned second messages, thereby improving the practicality of the serial communication method.
[0109] In one embodiment, the communication period for sending messages is greater than the total duration of communication with multiple slave devices.
[0110] The master device sends messages periodically, and the total actual time used for communication between the master device and multiple slave devices must be less than the communication period of the master device sending messages. For a description of the communication period and the total communication time between the master device and multiple slave devices, please refer to the specific description in the above embodiments, which will not be repeated here.
[0111] In this embodiment, the communication period for the master device to send messages is greater than the total communication time between the master device and multiple slave devices. This satisfies the condition of periodic communication in the serial communication system during the execution of the serial communication method, thereby improving the practicality of the serial communication method.
[0112] In one embodiment, as described in the above embodiments, the CPLD can act as a slave device. Based on this, the serial communication method further includes the following steps:
[0113] Send a first message to the complex programmable logic device (CPLD) so that the CPLD receives and parses the first message.
[0114] The CPLD can act as a slave device. The master device sends a first message to the CPLD, which then parses it upon receipt. Specifically, if the CPLD determines the first message to be from a target slave device, it can perform specific operations based on the request type within the message. If the CPLD determines the message is not from a target slave device, it can discard the first message. A description of the CPLD's processing of the first message can be found in the above embodiment's detailed description of the slave device's processing of the received first message, and will not be repeated here.
[0115] In this embodiment, when using the serial communication system provided in the above embodiment for serial communication, the CPLD in the serial communication system can be used as a slave device, thus reusing the hardware resources of the CPLD.
[0116] Please see Figure 9 One embodiment of this application provides a serial communication method applied to a first slave device and / or a second slave device in a serial communication system as described in the above embodiments. The method includes the following steps:
[0117] Step 901: Receive the first message sent by the master device in the serial communication system based on the wired-AND logic of the complex programmable logic device; the first message includes a read request and / or a write request.
[0118] The master device sends a first message to the CPLD in the serial communication system. The CPLD, based on wired-AND logic, transmits the first message to the first slave device and / or at least one second slave device connected to it. This is equivalent to the master device directly transmitting the first message to the first slave device and / or at least one second slave device via the serial bus. Both the first slave device and / or at least one slave device can receive the first message. A description of the first message can be found in the detailed description of the above embodiments, and will not be repeated here.
[0119] Step 902: If the first message includes a read request, send a second message to the master device based on the read request via the wired-AND logic of the complex programmable logic device.
[0120] After receiving the first message, the first slave device and / or at least one second slave device will first determine the target slave device based on the first message. The method for determining the target slave device can be referred to the specific description of the above embodiments, and will not be repeated here.
[0121] After determining the target slave device from the first slave device and / or at least one second slave device, the target slave device parses the first message to determine the specific request type included in the first message. If the target slave device determines that the first message includes a read request, it will send back a second message based on the read request and transmit the second message to the master device through the wired-AND logic of the CPLD. The operations performed by the target slave device when it determines that the request type in the first message is a write request or a read request and a write request can be referred to the specific description in the above embodiments, and will not be repeated here.
[0122] The serial communication method provided in this application embodiment enables communication between a master device and a first slave device and / or at least one slave device through a serial bus and a CPLD. The CPLD internally supports wired-AND logic, effectively allowing the master device to directly connect to the first slave device and at least one second slave device via the serial bus, without any intermediate conversion. This provides a physical foundation for efficient communication. By forwarding the first and second messages through the CPLD, the efficiency and bandwidth of serial communication can be improved, thereby enhancing the practicality of the serial communication method. Furthermore, when the first message includes both read and write requests, the target slave device can receive both requests within a single communication session, saving communication bandwidth and improving communication efficiency.
[0123] In one embodiment, such as Figure 10 As shown, this invention relates to an implementation method for receiving the first message transmitted by the master device in a serial communication system based on the wired-AND logic of a complex programmable logic device. The steps of this implementation method include:
[0124] Step 1001: Receive the first message sent by the master device based on the wired-AND logic of the complex programmable logic device, and determine whether the address information in the first message is consistent with the preset address information.
[0125] The preset address information is the address information of the first slave device and / or the second slave device itself. After receiving the first message sent by the master device based on the CPLD wired-AND logic, the first slave device and / or at least one second slave device will parse the first message, obtain the address information in the first message, and compare the address information with the preset address information to determine whether the address information is consistent with the preset address information.
[0126] Step 1002: If the address information in the first message matches the preset address information, parse the first message to obtain the read request and / or write request.
[0127] If the first slave device and / or at least one second slave device determine that the address information matches the preset address information by comparing the address information with the preset address information, then the slave device corresponding to the preset address information is determined as the target slave device. The target slave device will parse the first message and obtain the read request and / or write request in the first message.
[0128] In this embodiment, after receiving the second message, the first slave device and / or at least one second slave device first determine whether the first message was sent to itself. Only if it is determined that the message was sent to itself will the first message be parsed to obtain the specific read request and / or write request. This avoids the first slave device and / or at least one second slave device receiving a first message that is not for itself and then parsing it to obtain specific data, thus enabling efficient communication.
[0129] In one embodiment, an implementation involves sending a second message to a master device via wired-AND logic of a complex programmable logic device based on a read request. The implementation includes the following steps:
[0130] Based on the read request, a second message is sent to the master device after a preset time period using the wired-AND logic of a complex programmable logic device; the preset time period corresponds to the first slave device and / or the second slave device.
[0131] The preset time period can be obtained by parsing the first message. When the target slave device in the first slave device and / or at least one of the second slave devices returns a second message to the master device based on a read request, it will wait for the preset time period and then send the second message to the master device based on the wired-AND logic of the CPLD. Different slave devices correspond to different preset time periods.
[0132] In this embodiment, the target slave device sends a second message to the master device based on the read request and the wired-AND logic of the complex programmable logic device after a preset time period. The preset time period is different for different slave devices. This can avoid multiple slave devices competing for the shared serial bus, solve the congestion problem of serial communication, and thus avoid data corruption in the returned second message, thereby improving the practicality of the serial communication method.
[0133] In one embodiment, the first message sent by the master device includes a first checksum. The first checksum is a Cyclic Redundancy Check (CRC). Specifically, when the first message includes a read request, a write request, and the first checksum, the data in the first message is shown in the table below:
[0134]
[0135] In the table above, fields 1 and 2 refer to the fields corresponding to write requests, and field 3 refers to the fields corresponding to read requests. The master device can calculate the first checksum based on all the data preceding the first checksum in the first message.
[0136] When the first message includes a first checksum, the steps of the serial communication method include:
[0137] The second checksum is determined based on the first received message, and the first and second checksums are used to determine whether the first received message is normal.
[0138] The second checksum is of the same type as the first checksum. Upon receiving the first message, the target device (first slave device and / or at least one second slave device) retrieves the data from the first message and calculates the second checksum based on that data. The method by which the target slave device calculates the second checksum is the same as the method by which the master device calculates the first checksum.
[0139] After receiving the second checksum, the target device compares it with the first checksum in the first message to determine whether the first message is abnormal. If the first and second checksums are the same, the first message is normal; if they are different, the first message is abnormal and is discarded.
[0140] In this embodiment, the second check code is determined by the received first message. The first check code and the second check code can be used to determine whether the received first message is abnormal, which can prevent the serial communication system from malfunctioning due to the abnormal first message, thereby improving the practicality of the serial communication method.
[0141] Please see Figure 11 One embodiment of this application provides a serial communication method, the steps of which include:
[0142] Step 1101: The master device sends a first message to the first slave device and / or at least one second slave device based on the wired-AND logic of the CPLD;
[0143] Step 1102: The first slave device and / or at least one second slave device receive the first message, obtain address information according to the first message, compare the address information with preset address information, and determine the preset address information that matches the address information as the target slave device; the preset address information is the address information of the first slave device and / or at least one second slave device itself, and the target slave device is at least one of the first slave device and / or at least one second slave device.
[0144] Step 1103: The target parses the first message from the device, determines the second check code, and obtains the first check code in the first message. If the first check code and the second check code are the same, the request type in the first message is obtained.
[0145] Step 1104: If the target slave device determines that the request type is a write request, it writes the data corresponding to the write request to the target slave device.
[0146] Step 1105: If the target slave device determines that the request type is a read request, it returns a second message to the master device through the wired-AND logic of the CPLD after a preset time period based on the read request.
[0147] Step 1106: If the target slave device determines that the request type is a read request or a write request, it writes the data corresponding to the write request to the target slave device, and returns a second message to the master device through the wired-AND logic of the CPLD after a preset time period based on the read request.
[0148] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0149] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this patent application should be determined by the appended claims.
Claims
1. A serial communication system, characterized in that, The device includes a master device, a first slave device, at least one second slave device, a serial bus, and a complex programmable logic device (CPL). The CPL includes a master pin, a first slave pin, and at least one second slave pin. The master pin is directly connected to the master device via the serial bus, the first slave pin is directly connected to the first slave device via the serial bus, and each second slave pin is directly connected to the corresponding second slave device via the serial bus. The master device is configured to send a first message to a target slave device via the complex programmable logic device. The first message includes a read request and a write request, and the data in the first message supports fields of variable length. The target slave device is a first slave device and / or at least one second slave device in a serial communication system. The first message sent by the master device is output to the serial bus in a push-pull manner. The target slave device is configured to receive the first message and, in response to the read request in the first message, return a second message to the master device via the complex programmable logic device. The complex programmable logic device is configured to sample the first message sent by the master device through the master pin based on pre-programmed wired-AND logic, obtain a digital signal of the first message, perform clock synchronization processing on the digital signal of the first message, and output it to the target slave device through the slave pin connected to the target slave device; and to sample the second message input by the target slave device through the slave pin, obtain a digital signal of the second message, perform clock synchronization processing on the digital signal of the second message, perform a logical AND operation on the digital signal of the second message, and transmit it to the master device through the master pin, so as to realize a direct connection between the master device and the target slave device, enabling the master device to communicate with the first slave device and the at least one second slave device.
2. The serial communication system according to claim 1, characterized in that, When the target slave device includes multiple slave devices, the master device receives the second message returned by the multiple slave devices in a time-division polling manner.
3. The serial communication system according to claim 2, characterized in that, The communication duration between the master device and the slave device is less than a preset timeout duration; the preset timeout duration is determined according to the time-sharing polling method.
4. The serial communication system according to claim 2, characterized in that, The communication period for the master device to send messages is greater than the total communication time between the master device and the multiple slave devices.
5. The serial communication system according to any one of claims 1-4, characterized in that, The serial bus includes a first bus and a second bus, and the main pin includes a first sub-pin and a second sub-pin. The transmitting end of the master device is connected to the first sub-pin through the first bus, and the receiving end of the master device is connected to the second sub-pin through the second bus. The first slave pin includes a third sub-pin and a fourth sub-pin. The receiving end of the first slave device is connected to the third sub-pin through the first bus, and the transmitting end of the first slave device is connected to the fourth sub-pin through the second bus. The second slave pin includes a fifth sub-pin and a sixth sub-pin. The receiving end of the second slave device is connected to the fifth sub-pin through the first bus, and the transmitting end of the second slave device is connected to the sixth sub-pin through the second bus.
6. The serial communication system according to claim 5, characterized in that, The complex programmable logic device is also used to transmit the first message sent by the master device to the receiving end of the target slave device through a sub-pin connected to the target slave device based on the wired-AND logic, so as to realize the direct connection between the sending end of the master device and the receiving end of the target slave device.
7. The serial communication system according to claim 5, characterized in that, The transmitting end of the master device outputs the first message sent by the master device to the first bus in a push-pull output manner through two field-effect transistors; And / or, The target device outputs the second message to the second bus using a push-pull output method from its transmitting end.
8. The serial communication system according to any one of claims 1-4, characterized in that, The complex programmable logic device is also used to communicate with the master device through the main pin.
9. A serial communication method, characterized in that, The method, applied to a master device in a serial communication system as described in any one of claims 1-8, comprises: Based on the wired-AND logic of the complex programmable logic device in the serial communication system, a first message is sent to the target slave device in the serial communication system; the first message includes a read request and / or a write request; the target slave device is a first slave device and / or a second slave device in the serial communication system. If the first message includes the read request, a second message is received from the target slave device based on the read request, via the wired-AND logic of the complex programmable logic device.
10. The method according to claim 9, characterized in that, The target slave device includes multiple slave devices, and receiving the second message returned by the target slave device based on the read request through the wired-AND logic of the complex programmable logic device includes: The system receives the second message returned by the multiple slave devices based on the read request through the wired-AND logic of the complex programmable logic device at different time periods.
11. The method according to claim 10, characterized in that, The communication period for sending messages is greater than the total duration of communication with the plurality of slave devices.
12. The method according to claim 9, characterized in that, The method further includes: The first message is sent to the complex programmable logic device so that the complex programmable logic device receives the first message and parses the first message.
13. A serial communication method, characterized in that, The method, applied to a first slave device and / or a second slave device in a serial communication system as described in any one of claims 1-8, comprises: Receive a first message sent by the master device in the serial communication system based on the wired-AND logic of a complex programmable logic device; the first message includes a read request and / or a write request. If the first message includes the read request, a second message is sent to the master device based on the read request via the wired-AND logic of the complex programmable logic device.
14. The method according to claim 13, characterized in that, The step of sending a second message to the master device based on the read request via the wired-AND logic of the complex programmable logic device includes: Based on the read request, the second message is sent to the master device after a preset time period based on the wired-AND logic of the complex programmable logic device; the preset time period corresponds to the first slave device and / or the second slave device.
15. The method according to claim 13, characterized in that, The first message includes a first checksum, and the method further includes: The second checksum is determined based on the received first message, and the first checksum and the second checksum are used to determine whether the received first message is normal.
16. The method according to claim 13, characterized in that, The receiving of the first message sent by the master device in the serial communication system based on a complex programmable logic device includes: Receive the first message sent by the master device based on the wired-AND logic of the complex programmable logic device, and determine whether the address information in the first message is consistent with the preset address information; If the address information in the first message matches the preset address information, the first message is parsed to obtain the read request and / or the write request.
Citation Information
Patent Citations
Serial port conversion method and device of CPU (Central Processing Unit)
CN114647597A
Communication system, communication method and SPI (Serial Peripheral Interface) equipment
CN119311626A