Data transmission method, device and equipment based on serial port device and medium
By expanding the data bits of the serial port device and configuring the transmission sequence identification, the problem of complex and low efficiency of the serial port device in multi-master and multi-slave communication is solved, and efficient and orderly data transmission is achieved.
Patent Information
- Application Number
- CN202510522489.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-24
- Publication Date
- 2025-08-08
AI Technical Summary
The existing serial port devices require more pin configurations, logic devices and arbitration modules when the master communicates with multiple slaves, and the operation process is complex and the data transmission efficiency is low.
By expanding the data bits of the serial port device, two-bit data bits are added for transmission mode selection and data verification, and the transmission sequence identification is configured to realize orderly communication between the host and multiple slaves to avoid communication interference and data loss.
It realizes efficient communication without the need for special configuration of slave pins, reduces error probability, improves data transmission efficiency, supports multi-mode transmission, and is suitable for the communication needs of system-on-chip.
Smart Images

Figure CN120455556A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of communication technology, and in particular to a data transmission method, device, equipment and medium based on a serial port device. Background Art
[0002] Among existing serial devices, a Universal Asynchronous Receiver / Transmitter (UART), for example, typically configures the baud rate to ensure consistent parameters between the master and slave devices for correct data transmission. The data format typically consists of a start bit, eight data bits, a parity bit, and a stop bit.
[0003] In the related art, when applying the above-mentioned UART protocol behavior, if one host wants to send data to multiple slaves, the usual practice is to specially configure the communication pins of the slaves, such as setting them to open-drain output mode or using diodes for isolation, so as to avoid communication interference between the slaves. If multiple hosts want to correspond to multiple slaves, corresponding arbitration mechanisms and polling mechanisms need to be added to achieve orderly communication between multiple hosts and slaves, avoiding communication conflicts and data loss. It can be seen that in the related art, the scheme of using serial ports to realize one-master-multiple-slave and multi-master-multi-slave communication obviously requires more pin configurations, logic devices and the support of arbitration modules, and the operation process is complicated and the data transmission efficiency is low. Summary of the Invention
[0004] The present application provides a data transmission method, device, equipment and medium based on a serial port device, so as to at least solve the problem in the related art that when a host communicates with multiple slaves, more pin configurations, logic devices and arbitration module support are required, the operation process is complicated and the data transmission efficiency is low.
[0005] The present application provides a data transmission method based on a serial port device, which is applied to a host. The data bits of a transmission data packet of the serial port device include: a first data bit for selecting a transmission mode, a second data bit, and a plurality of third data bits for transmitting data. The method includes:
[0006] Obtain the data to be transmitted and the address of the target slave corresponding to the data to be transmitted;
[0007] When there are multiple addresses of the target slave machine, a transmission sequence identifier of the data to be transmitted is configured, the first data bit is configured as the first identifier, the second data bit is configured as the second identifier, and each third data bit is configured as the address of the current target slave machine, thereby obtaining multiple first data packets to be transmitted with the transmission sequence identifier, the first identifier being used to indicate that the current transmission mode is the multi-slave mode, and the second identifier being used to indicate that the first data packets to be transmitted transmit addresses;
[0008] transmitting a plurality of first data packets to be transmitted based on the transmission sequence identifier, so that each target slave starts responding to the data packet to be transmitted corresponding to the transmission sequence identifier when verifying that the address transmitted in the first data packet to be transmitted is consistent with its own address;
[0009] Configuring the first data bit as a first identifier, configuring the second data bit as a third identifier, and configuring each third data bit as data to be transmitted, to obtain a second data packet to be transmitted with a transmission sequence identifier, wherein the third identifier is used to indicate that the second data packet to be transmitted transmits data;
[0010] The second data packet to be transmitted is transmitted based on the transmission sequence identifier, so that each target slave receives the second data packet to be transmitted based on the transmission sequence identifier of the second data packet to be transmitted.
[0011] The present application also provides a data transmission device based on a serial port device, which is applied to a host. The data bits of a transmission data packet of the serial port device include: a first data bit for selecting a transmission mode, a second data bit, and a plurality of third data bits for transmitting data. The device includes:
[0012] An acquisition module is used to obtain the data to be transmitted and the address of the target slave machine corresponding to the data to be transmitted;
[0013] a first processing module, configured to, when there are multiple addresses of a target slave machine, configure a transmission sequence identifier of the data to be transmitted, configure the first data bit as the first identifier, configure the second data bit as the second identifier, and configure each third data bit as the address of the current target slave machine, to obtain multiple first data packets to be transmitted with the transmission sequence identifier, wherein the first identifier is used to indicate that the current transmission mode is a multi-slave mode, and the second identifier is used to indicate that the first data packets to be transmitted transmit addresses;
[0014] a second processing module, configured to transmit the plurality of first data packets to be transmitted based on the transmission sequence identifier, so that each target slave starts responding to the data packet to be transmitted corresponding to the transmission sequence identifier when verifying that the address transmitted in the first data packet to be transmitted is consistent with its own address;
[0015] a third processing module, configured to configure the first data bit as a first identifier, configure the second data bit as a third identifier, and configure each third data bit as data to be transmitted, to obtain a second data packet to be transmitted with a transmission sequence identifier, wherein the third identifier is used to indicate that the second data packet to be transmitted transmits data;
[0016] The fourth processing module is configured to transmit the second data packet to be transmitted based on the transmission sequence identifier, so that each target slave receives the second data packet to be transmitted based on the transmission sequence identifier of the second data packet to be transmitted.
[0017] The present application also provides an electronic device, comprising: a memory for storing a computer program; and a processor for implementing the steps of any of the above-mentioned data transmission methods based on a serial port device when executing the computer program.
[0018] The present application also provides a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, the steps of any of the above-mentioned data transmission methods based on a serial port device are implemented.
[0019] Through the present application, due to the expansion of the data bits in the transmission data packet of the serial port device, the mode configuration of the host communicating with multiple slaves is realized, and there is no need to specially configure the slave pins. In this mode, only the participating host and slaves need to respond, and other hosts and slaves will not respond to these data, avoiding communication interference between slaves. Sequential transmission is performed by configuring the transmission sequence identifier, which can well replace the arbitration mechanism and polling mechanism, realize orderly communication between multiple hosts and slaves, avoid communication conflicts and data loss problems, reduce the error probability, make the communication between the host and the slave more efficient, convenient and fast, facilitate smoother communication, and improve data transmission efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] In order to more clearly illustrate the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0021] Figure 1 A schematic diagram of the structure of communication between the host and slave of the system on chip provided in an embodiment of the present application;
[0022] Figure 2 This is a schematic diagram of the data transmission method of the existing serial port;
[0023] Figure 3 Schematic diagram of the data transmission method of the serial port provided in the embodiment of the present application;
[0024] Figure 4 A flowchart of a data transmission method based on a serial port device provided in an embodiment of the present application;
[0025] Figure 5 A flowchart of another data transmission method based on a serial port device provided in an embodiment of the present application;
[0026] Figure 6 A schematic diagram of the conversion of three communication modes of the serial port provided in an embodiment of the present application;
[0027] Figure 7 A schematic diagram of the state transition of the basic transmission mode provided in an embodiment of the present application;
[0028] Figure 8 A schematic diagram of the state transition of the data verification mode provided in an embodiment of the present application;
[0029] Figure 9 A schematic diagram of the state transition of the one-master-multiple-slave / multi-master-multiple-slave mode provided in an embodiment of the present application;
[0030] Figure 10 A schematic diagram of the UART serial port workflow provided in an embodiment of the present application;
[0031] Figure 11 A schematic diagram of the structure of a data transmission device based on a serial port device provided in an embodiment of the present application;
[0032] Figure 12 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0033] The following will be combined with the accompanying drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0034] It should be noted that, in the description of this application, the terms "comprises," "includes," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. The terms "first," "second," etc., in this application are used to distinguish similar objects, and are not used to describe a particular order or sequence.
[0035] In order to enable those skilled in the art to better understand the present application, the present application is further described in detail below with reference to the accompanying drawings and specific implementation methods.
[0036] In conjunction with the specific application environment architecture or specific hardware architecture on which the execution of the data transmission method based on the serial port device depends, the specific application environment architecture or the specific hardware architecture is described herein.
[0037] With the continuous advancement of technology, SoC (System on a Chip) systems are experiencing significant improvements in multi-core, multi-threaded processing and hardware acceleration performance. Simultaneously, SoC peripherals, such as UARTs and IICs, should also be equipped with additional functionality while meeting their typical needs to match the overall system and functionality of the SoC. This also lays a solid foundation for a wider range of communication needs and system designs.
[0038] In the embodiment of the present application, the serial port device provided in the SOC system is used as an example for description. Figure 1 As shown, Figure 1 In the figure, M represents the master and S represents the slave. In a typical SOC system, the peripheral device is equipped with only one serial port, M1, which is used to connect to the external slave device to complete the interaction. However, as the functions and performance of SOC systems continue to improve, multiple serial ports to achieve multi-master and multi-slave communication should be necessary. In practical applications, the above serial port device can also be applied to other systems or devices that require serial port communication, and this application is not limited to this.
[0039] Figure 2 This is the data transmission format of a conventional serial port, generally consisting of a start bit, eight data bits D0-D7, a parity bit, and a stop bit. In the embodiments of this application, a UART serial port device is used as an example for description. In actual applications, RS485, RS232, and other serial port devices can also be used, and this application is not limited to them.
[0040] In the related art, when using the UART serial port, there are relatively few modes that can be freely switched between one master and multiple slaves, multiple masters and multiple slaves, etc., and both one master and multiple slaves and multiple masters and multiple slaves have their defects. Therefore, it is very necessary to design a UART serial port device that can support multiple modes and can be freely switched while being efficient, convenient and fast. In addition, the serial port is a bridge connecting the chip and the external communication device, and it is also very necessary for the functional mode of data verification. In response to the problems existing in the above related art, the embodiment of the present application provides a solution that can be applied to the system on chip and uses the serial port device to realize communication between the master and the slave. The overall content of the solution will be introduced below.
[0041] The embodiment of the present application provides a data transmission method based on a serial port device, which is applied to a host. The data bits of the transmission data packet of the serial port device mentioned in the embodiment of the present application include: a first data bit for selecting a transmission mode, a second data bit and a plurality of third data bits for transmitting data. Specifically, by Figure 2The data bits are expanded by two on the basis of eight bits, that is, the data bits become 10 bits, such as Figure 3 As shown in the figure, the first 8 bits are still used for data transmission, and their functions are the same as before. The main purpose is to achieve multi-mode and multi-function serial port transmission through the change of the last two bits. Among them, the 9th and 10th data bits are mainly designed for one master and multiple slaves, or multiple masters and multiple slaves, such as one master and multiple slaves mode or opening the data verification function mode. It should be noted that Figure 3 The specific positions of the two expanded data bits are only for example. In actual applications, based on the total 10 data bits, any two of them can be selected as the first data bit and the second data bit, and the remaining eight bits can be selected as the third data bit. This application is not limited to this.
[0042] like Figure 4 As shown, the data transmission method based on the serial port device provided in the embodiment of the present application specifically includes the following steps:
[0043] Step S401: Acquire data to be transmitted and the address of a target slave device corresponding to the data to be transmitted.
[0044] Specifically, the data to be transmitted can be communication data such as commands sent by the host to the slave, or there can be multiple data to be transmitted. The target slave can be set to one or more according to the host communication requirements to achieve different communication requirements of one master and multiple slaves and one master and one slave.
[0045] Step S402, when there are multiple addresses of the target slave machine, configure the transmission sequence identifier of the data to be transmitted, configure the first data bit as the first identifier, configure the second data bit as the second identifier, and configure each third data bit as the address of the current target slave machine, to obtain multiple first data packets to be transmitted with transmission sequence identifiers, the first identifier is used to indicate that the current transmission mode is a multi-slave mode, and the second identifier is used to indicate that the first data packet to be transmitted transmits an address.
[0046] Specifically, the transmission sequence identifier is used to characterize the transmission priority of the data to be transmitted. For example, by configuring the ID number, each data to be transmitted corresponds to an ID number, and the size of the ID number indicates the transmission priority of the corresponding data to be transmitted. The transmission priority of each data to be transmitted can be set according to actual needs, such as according to the order in which the data to be transmitted is obtained or a pre-set priority order, etc. The present invention is not limited to this.
[0047] For example, since each data bit has only two data elements, 0 and 1, the first identifier is configured as 1 to indicate that the current transmission mode is a multi-slave mode, i.e., a mode in which one or more masters communicate with multiple slaves. The second identifier is also configured as 1 to indicate that the data packet to be transmitted is an address, facilitating address comparison and response by the slave. Furthermore, a communication protocol may be configured to specify that the first and second identifiers are configured as 0 to indicate the above, but this application is not limited thereto.
[0048] Step S403 : transmitting a plurality of first data packets to be transmitted based on the transmission sequence identifier, so that each target slave starts responding to the data packet to be transmitted corresponding to the transmission sequence identifier when verifying that the address transmitted in the first data packet to be transmitted is consistent with its own address.
[0049] Specifically, when there are multiple data to be transmitted, there will be multiple first data packets to be transmitted corresponding to different transmission sequence identifiers, so that the transmission priority is determined by comparing the transmission sequence identifiers of each data packet to be transmitted, and then the data packets to be transmitted are transmitted in sequence according to the transmission priority, avoiding communication conflicts and data loss problems. Accordingly, when the slave receives data sent by multiple hosts, the existence of the transmission sequence identifier can avoid the problem of jamming, and the slave can determine whether the target slave of the data packet is itself by comparing the transmission address in the data packet with its own address. If so, it responds to the transmission data packet corresponding to the transmission sequence identifier to achieve communication with the host, while avoiding interference with communication between other slaves. There is no need to specially configure the slave pins, making the entire data transmission process more efficient and convenient.
[0050] Step S404: configure the first data bit as the first identifier, configure the second data bit as the third identifier, and configure each third data bit as data to be transmitted, to obtain a second data packet to be transmitted with a transmission sequence identifier, wherein the third identifier is used to indicate that the second data packet to be transmitted transmits data.
[0051] For example, the third identifier is configured as 0 to indicate that the data packet to be transmitted is data, so that the slave can perform address comparison and response. In addition, the communication protocol can also be set to configure the third identifier as 1 to indicate the above content, as long as it can be distinguished from the second identifier, and this application is not limited to this.
[0052] Step S405 : transmitting the second data packet to be transmitted based on the transmission sequence identifier, so that each target slave receives the second data packet to be transmitted based on the transmission sequence identifier of the second data packet to be transmitted.
[0053] Specifically, when there are multiple data packets to be transmitted, there will be multiple second data packets to be transmitted corresponding to different transmission order identifiers. The transmission priority is determined by comparing the transmission order identifiers of each data packet to be transmitted, and then the data packets to be transmitted are transmitted in sequence according to the transmission priority to avoid communication conflicts and data loss problems.
[0054] Through the present application, due to the expansion of the data bits in the transmission data packet of the serial port device, the mode configuration of the host communicating with multiple slaves is realized, and there is no need to specially configure the slave pins. In this mode, only the participating host and slaves need to respond, and other hosts and slaves will not respond to these data, avoiding communication interference between slaves. Sequential transmission is performed by configuring the transmission sequence identifier, which can well replace the arbitration mechanism and polling mechanism, realize orderly communication between multiple hosts and slaves, avoid communication conflicts and data loss problems, reduce the error probability, make the communication between the host and the slave more efficient, convenient and fast, facilitate smoother communication, and improve data transmission efficiency.
[0055] In some optional implementations, the steps of transmitting the first data packet to be transmitted or the second data packet to be transmitted based on the transmission sequence identifier in step S403 and step S405 specifically include the following steps:
[0056] Step a1: Determine the transmission order of the first data packet to be transmitted or the second data packet to be transmitted based on the transmission order identifier.
[0057] Illustratively, the sequence of the ID numbers of the data to be transmitted is the transmission sequence of the data packets to be transmitted.
[0058] Step a2: transmitting the first data packet to be transmitted or the second data packet to be transmitted based on the transmission order.
[0059] This application determines the transmission order of each data to be transmitted by configuring the transmission sequence identifier, avoiding the problem of jamming that may easily occur during communication between multiple hosts and multiple slaves, and further improving data transmission efficiency.
[0060] Furthermore, the data transmission method based on the serial port device provided in the embodiment of the present application further includes the following steps:
[0061] Step b1: monitoring the transmission status of each data packet to be transmitted.
[0062] Specifically, the process of entering the transmission work corresponding to different transmission modes is that each data packet to be transmitted enters the state machine stage after configuring the relevant data, and the serial port working state, that is, the transmission state of the data packet, is determined by checking the current state machine of the serial port.
[0063] Step b2: when the transmission status of the current data packet to be transmitted is abnormal, the current data packet to be transmitted is cleared, and the process returns to the step of transmitting the first data packet to be transmitted or the second data packet to be transmitted based on the transmission order.
[0064] Specifically, the abnormality of the data packet transmission status includes: being stuck in the data transmission state, the transmission waiting state, etc. In this case, the current data packet to be transmitted is cleared to avoid its impact on the transmission of other data packets to be transmitted, so that other data packets can be transmitted normally according to the transmission order.
[0065] In addition, in actual applications, the following processing steps are also included for data packets with abnormal transmission status:
[0066] Step c1: extracting the currently to-be-transmitted data from the currently abnormal data packet to-be-transmitted.
[0067] Step c2: reconfigure the transmission sequence identifier of the data to be transmitted, and return to the above step S402 to continue executing the subsequent process.
[0068] The embodiment of the present application retransmits the abnormally transmitted data packets by reconfiguring the transmission sequence identifier, thereby improving the data transmission success rate, avoiding the problems of communication data loss and jamming between the host and the slave, and improving the communication quality between the host and the slave.
[0069] In some optional implementations, the serial port device provided in the embodiments of the present application is provided with an enable register, which enables various functions of the serial port device. The above-mentioned data transmission method based on the serial port device further includes the following steps:
[0070] Step d1: when the first data bit in the data packet to be transmitted is configured as the first flag, the enable register is opened to enable various functions of the serial port device.
[0071] For example, when Figure 3When the 9th bit of the data shown is configured as 1, the serial port device enters the most important mode of this application, the multi-slave mode, that is, supports one master and multiple slaves / multi-master and multiple slaves mode (mode 2). When the 9th bit is configured as 1, even if it is valid, a register will be opened accordingly. The register has an ID and various functions such as FIFO buffer, DMA function, automatic flow control, diagnostic function, infrared support, and debugging support. When this mode is turned on (when the 9th and 10th bits are valid), the many functions of the above serial port have the effect of one-key enabling, so that various functions can be effectively managed. By increasing the typical transmission bit width of the serial port device, while meeting its own typical functions, its additional functions are added to match the overall system and functions of the SOC system. At the same time, it also lays a more solid foundation for a wider range of communication needs and system design.
[0072] like Figure 5 As shown, another data transmission method based on a serial port device provided in an embodiment of the present application specifically includes the following steps:
[0073] Step S501, obtain the data to be transmitted and the address of the target slave corresponding to the data to be transmitted. Figure 4 The description of step S401 is omitted here.
[0074] Step S502: determine whether the data to be transmitted has verification requirements.
[0075] Specifically, in order to ensure the accuracy of data transmitted between the master and the slave, a data verification function can be set to perform verification. The data used for verification is the transmission data agreed upon between the master and the slave. If the data to be transmitted is the data used for verification, it is considered that there is a verification requirement. Otherwise, the data to be transmitted is considered to be ordinary transmission data between the master and the slave.
[0076] Step S503, when the data to be transmitted has a verification requirement, the first data bit is configured as the fourth identifier, the second data bit is configured as the sixth identifier, and each third data bit is configured as the data to be transmitted to obtain a fourth data packet to be transmitted. The fourth identifier and the sixth identifier are used to characterize that the current transmission mode is a data verification mode.
[0077] Similarly, the fourth identifier only needs to be distinguishable from the first identifier. When the first identifier is configured as 1, the fourth identifier is configured as 0, and vice versa. The sixth identifier is configured as 1 to indicate the data used for data verification of the currently transmitted data, so that the slave completes the data verification function after introducing the data packet. In addition, the data used for data verification of the currently transmitted data can also be identified by configuring the sixth identifier as 0, and this application is not limited to this.
[0078] Step S504: Transmit the fourth data packet to be transmitted to the target slave, so that the target slave verifies the data transmitted in the fourth data packet to be transmitted based on the sixth identifier.
[0079] Step S505, when there is no verification requirement for the data to be transmitted, the first data bit is configured as the fourth identifier, the second data bit is configured as the fifth identifier, and each third data bit is configured as the data to be transmitted to obtain a third data packet to be transmitted. The fourth identifier and the fifth identifier are used to characterize that the current transmission mode is the basic transmission mode.
[0080] Among them, the above-mentioned fifth identifier only needs to be distinguished from the above-mentioned sixth identifier. When the sixth identifier is configured to 1, the fifth identifier is configured to 0, and vice versa. For example, when the fourth identifier and the fifth identifier are both configured to 0, it indicates that the current transmission mode is the basic transmission mode, that is, the normal mode, and a single host communicates with a single slave. This is similar to the data transmission method in the relevant technology and will not be repeated here.
[0081] Step S506: Transmit the third data packet to be transmitted to the target slave device.
[0082] Through this application, due to the expansion of the data bits in the transmission data packet of the serial port device, the selection and switching of multiple different communication modes between the host and the slave are realized, and multi-mode transmission is supported, so that the UART serial port device can take on more data transmission tasks in future SOC systems and increase the functionality of the serial port device.
[0083] The specific working principle and working process of the data transmission method based on the serial port device provided in the embodiment of the present application will be described in detail below with reference to specific application examples.
[0084] by Figure 3 For example, when the 9th data bit is set to 1, the most important configuration is the ID-related configuration. In multi-slave mode (Mode 2), when the master communicates with the slave, it first configures the ID, then the address, and data. When multiple masters want to communicate with the same slave, they execute them one by one in an orderly manner according to the order of the IDs. This method can effectively replace the arbitration mechanism and polling mechanism, reduce the probability of errors, and facilitate smoother communication.
[0085] With the 9th bit configured as 1, the 10th bit distinguishes between address and data. When the 10th bit is 0, it indicates that the address is being transmitted; when the 10th bit is 1, it indicates that the data is being transmitted. In this way, that is, using the address / data identification bit method, only the participating masters and slaves need to respond, and other masters and slaves will not respond to this data.
[0086] When the 9th bit is configured to 0 and the 10th bit is configured to 0, the serial port device is in basic transmission mode, which is equivalent to basic transmission mode (mode 0), that is, the last two bits of the data bits are not required, and only eight bits of data are required, namely, a start bit, eight data bits, a parity bit and a stop bit.
[0087] When the 9th bit is set to 0 and the 10th bit is set to 1, the serial port device enters another mode, namely data verification mode (mode 1), which is used to verify the accuracy of the transmitted data and provide a verification function for the transmission.
[0088] In summary, the serial port device of the embodiment of the present application can realize three modes, namely mode 0, mode 1, and mode 2, through the configuration of the last two data bits, i.e. the 9th and 10th bits. Among them, mode 0 is the normal mode, and the 9th and 10th bits are 0 and 0 respectively, i.e. the general mode of serial port transmission, which can be realized without the 9th and 10th bits. Mode 1 is the data check mode, and the 9th and 10th bits are 0 and 1 respectively, i.e. the transmitted data is checked, such as CRC check. Mode 2 is the advanced mode, and the 9th and 10th bits are 1 and X respectively (0 represents the transmission address, 1 represents the transmission data), i.e. it supports one master and multiple slaves / multi-master and multiple slave modes. Through the change of ID, only the participating host and slave need to respond, and other hosts and slaves will not respond to these data.
[0089] Figure 6 The state transitions of the three modes mentioned above are shown. Figure 4 As you can see, first, the serial port device is in idle state, then it receives the transmission command and enters the mode selection. If it is mode 0, which is the basic transmission mode, it directly performs data transmission, and after the transmission is completed, it enters the transmission completion state. Mode 0 state transition is as follows Figure 7 shown.
[0090] If it is mode 1, which is the data verification mode, the next step is also data transmission. In this process, there is a data verification process. After the verification is completed, there needs to be a response state. After the response is completed, that is, after the transmission is completed, it is the transmission completion state. Mode 1 state transition is as follows Figure 8 shown.
[0091] If it is mode 2, which supports one master and multiple slaves / multi-master and multiple slaves, first configure the relevant parameters to distinguish the order of transmission based on address / data and the change of ID (if the address of the master to the slave is consistent). The next step is data transmission. Because this mode will configure many addresses and data, it is necessary to wait for transmission and transmit in sequence. After the transmission is completed, it is the transmission completion state. Mode 2 state transition is as follows Figure 9 shown.
[0092] For example, Figure 10The following is a diagram of the UART serial port workflow, specifically including:
[0093] S1: Waiting for the MCU to issue a transmission command.
[0094] S2: Enter the transmission work corresponding to different modes: After configuration, the process enters the state machine stage.
[0095] S3: Check the working status of UART: Check whether data transmission and data verification are successful.
[0096] The above-mentioned embodiments of the present application increase the typical transmission bit width of the UART serial port to support multiple data bit widths and multiple data formats. While meeting its own typical functions, it also adds additional functions to match the overall system and functions of the SOC system. At the same time, it also lays a more solid foundation for a wider range of communication needs and system designs.
[0097] In view of the shortcomings of the related art in which the one-master-multiple-slave / multi-master-multi-slave communication mode requires more pin configurations, logic devices, and arbitration module support, which is not efficient, convenient, and fast, and is prone to jamming, the technical solution provided by the embodiment of the present application can effectively solve the above-mentioned drawbacks. Based on the extra data bit width or data format, the transmission of one-master-multiple-slave, multi-master-multi-slave and other modes can be accurately carried out by relying on the change of data bits, that is, the change of address / data. Data verification can also be performed. And by using the address / data identification bit, only the participating host and slave need to respond, and other hosts and slaves will not respond to this data.
[0098] To address the problem that UART serial port devices play an important role in SOC but have a single function, the embodiments of the present application support multi-mode transmission, so that UART serial port devices can take on more data transmission tasks in future SOC systems, that is, the transmission modes are increased.
[0099] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus the necessary general hardware platform, and of course it can also be implemented by hardware, but in many cases the former is a better implementation method.
[0100] The embodiment of the present application also provides a data transmission device based on a serial port device, which is applied to a host. The data bits of the transmission data packet of the serial port device include: a first data bit for selecting a transmission mode, a second data bit and a plurality of third data bits for transmitting data, such as Figure 11 As shown, the device includes:
[0101] An acquisition module 1101 is used to acquire data to be transmitted and an address of a target slave machine corresponding to the data to be transmitted;
[0102] A first processing module 1102 is configured to, when there are multiple addresses of a target slave, configure a transmission sequence identifier for data to be transmitted, configure the first data bit as the first identifier, configure the second data bit as the second identifier, and configure each third data bit as the address of the current target slave, to obtain multiple first data packets to be transmitted with the transmission sequence identifier, wherein the first identifier is used to indicate that the current transmission mode is a multi-slave mode, and the second identifier is used to indicate that the first data packets to be transmitted transmit addresses;
[0103] The second processing module 1103 is configured to transmit the plurality of first data packets to be transmitted based on the transmission sequence identifier, so that each target slave starts responding to the data packet to be transmitted corresponding to the transmission sequence identifier when verifying that the address transmitted in the first data packet to be transmitted is consistent with its own address;
[0104] A third processing module 1104 is configured to configure the first data bit as a first identifier, configure the second data bit as a third identifier, and configure each third data bit as data to be transmitted, to obtain a second data packet to be transmitted with a transmission sequence identifier, wherein the third identifier is used to indicate that the second data packet to be transmitted transmits data;
[0105] The fourth processing module 1105 is configured to transmit the second data packet to be transmitted based on the transmission sequence identifier, so that each target slave receives the second data packet to be transmitted based on the transmission sequence identifier of the second data packet to be transmitted.
[0106] In some optional implementations, the data transmission device based on the serial port device provided in the embodiment of the present application further includes:
[0107] a fifth processing module, configured to, when the address of the target slave is single, configure the first data bit as the fourth identifier, configure the second data bit as the fifth identifier, and configure each third data bit as data to be transmitted, to obtain a third data packet to be transmitted, wherein the fourth identifier and the fifth identifier are used to indicate that the current transmission mode is the basic transmission mode;
[0108] The sixth processing module is configured to transmit the third data packet to be transmitted to the target slave device.
[0109] In some optional implementations, the data transmission device based on the serial port device provided in the embodiment of the present application further includes:
[0110] A seventh processing module, configured to determine whether the data to be transmitted has verification requirements;
[0111] an eighth processing module, configured to, when the data to be transmitted has a verification requirement, configure the first data bit as a fourth identifier, configure the second data bit as a sixth identifier, and configure each third data bit as the data to be transmitted, to obtain a fourth data packet to be transmitted, where the fourth identifier and the sixth identifier are used to indicate that the current transmission mode is a data verification mode;
[0112] The ninth processing module is configured to transmit the fourth data packet to be transmitted to the target slave machine, so that the target slave machine verifies the data transmitted in the fourth data packet to be transmitted based on the sixth identifier.
[0113] In some optional implementations, the data transmission device based on the serial port device provided in the embodiment of the present application further includes:
[0114] The tenth processing module is configured to call the fifth processing module when there is no verification requirement for the data to be transmitted.
[0115] In some optional embodiments, the above-mentioned first processing module or fourth processing module is specifically used to determine the transmission order of the first data packet to be transmitted or the second data packet to be transmitted based on the transmission order identifier; and transmit the first data packet to be transmitted or the second data packet to be transmitted based on the transmission order.
[0116] In some optional implementations, the data transmission device based on the serial port device provided in the embodiment of the present application further includes:
[0117] A monitoring module, used to monitor the transmission status of each data packet to be transmitted;
[0118] The processing module is used to clear the current data packet to be transmitted when the transmission status of the current data packet to be transmitted is abnormal, and return to the step of transmitting the first data packet to be transmitted or the second data packet to be transmitted based on the transmission order.
[0119] In some optional implementations, the serial port device is provided with an enable register, and the enable register enables various functions of the serial port device. The data transmission device based on the serial port device provided in the embodiment of the present application further includes:
[0120] The enabling module is used to open the enabling register when the first data bit in the data packet to be transmitted is configured as the first flag, so as to enable various functions of the serial port device.
[0121] For descriptions of features in the embodiments corresponding to the data transmission device based on the serial port device, reference may be made to the relevant descriptions of the embodiments corresponding to the data transmission method based on the serial port device, which will not be described in detail here.
[0122] The embodiment of the present application also provides an electronic device, such as Figure 12 As shown, it includes a memory 10 and a processor 20, wherein the memory 10 stores a computer program, and the processor 20 is configured to run the computer program to execute the steps in any of the above-mentioned embodiments of the data transmission method based on the serial port device.
[0123] An embodiment of the present application further provides a computer-readable storage medium storing a computer program, wherein the computer program is configured to execute the steps of any of the above-mentioned embodiments of the data transmission method based on a serial port device when running.
[0124] In an exemplary embodiment, the computer-readable storage medium may include, but is not limited to, various media that can store computer programs, such as a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk, or an optical disk.
[0125] An embodiment of the present application further provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the steps of any of the above-mentioned embodiments of the data transmission method based on a serial port device are implemented.
[0126] An embodiment of the present application further provides another computer program product, including a non-volatile computer-readable storage medium, wherein the non-volatile computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of any of the above-mentioned embodiments of the data transmission method based on a serial port device are implemented.
[0127] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the above description has generally described the components and steps of each example according to their functions. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0128] The above is a detailed introduction to the data transmission method, device, equipment and medium based on a serial port device provided by the present application. Specific examples are used herein to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method and core ideas of the present application. It should be pointed out that for ordinary technicians in this technical field, without departing from the principles of the present application, several improvements and modifications can be made to the present application, and these improvements and modifications also fall within the scope of protection of the claims of the present application.
Claims
1. A data transmission method based on a serial port device, applied to a host, characterized in that: The data bits of the transmission data packet of the serial port device include: a first data bit for transmission mode selection, a second data bit and a plurality of third data bits for transmitting data, and the method includes: Acquire the data to be transmitted and the address of the target slave machine corresponding to the data to be transmitted; When there are multiple addresses of the target slave, configuring a transmission sequence identifier of the data to be transmitted, configuring the first data bit as a first identifier, configuring the second data bit as a second identifier, and configuring each third data bit as the address of the current target slave, to obtain multiple first data packets to be transmitted with the transmission sequence identifier, the first identifier being used to indicate that the current transmission mode is a multi-slave mode, and the second identifier being used to indicate that the first data packets to be transmitted transmit addresses; transmitting the plurality of first data packets to be transmitted based on the transmission sequence identifier, so that each target slave starts responding to the data packet to be transmitted corresponding to the transmission sequence identifier when verifying that the address transmitted in the first data packet to be transmitted is consistent with its own address; Configuring the first data bit as a first identifier, configuring the second data bit as a third identifier, and configuring each third data bit as the data to be transmitted, to obtain a second data packet to be transmitted with the transmission sequence identifier, wherein the third identifier is used to indicate that the second data packet to be transmitted transmits data; The second data packet to be transmitted is transmitted based on the transmission sequence identifier, so that each target slave receives the second data packet to be transmitted based on the transmission sequence identifier of the second data packet to be transmitted.
2. The data transmission method based on a serial port device according to claim 1, characterized in that: The method further comprises: When the address of the target slave is single, the first data bit is configured as a fourth identifier, the second data bit is configured as a fifth identifier, and each third data bit is configured as the data to be transmitted, to obtain a third data packet to be transmitted, wherein the fourth identifier and the fifth identifier are used to indicate that the current transmission mode is the basic transmission mode; The third data packet to be transmitted is transmitted to the target slave device.
3. The data transmission method based on a serial port device according to claim 2, characterized in that: When the address of the target slave is single, the method further includes: Determining whether the data to be transmitted has verification requirements; When the data to be transmitted has a verification requirement, configuring the first data bit as a fourth identifier, configuring the second data bit as a sixth identifier, and configuring each third data bit as the data to be transmitted, to obtain a fourth data packet to be transmitted, the fourth identifier and the sixth identifier being used to indicate that the current transmission mode is a data verification mode; The fourth data packet to be transmitted is transmitted to the target slave machine, so that the target slave machine verifies the data transmitted in the fourth data packet to be transmitted based on the sixth identifier.
4. The data transmission method based on a serial port device according to claim 3, characterized in that: The method further comprises: When there is no verification requirement for the data to be transmitted, return to the step of configuring the first data bit as the fourth identifier, configuring the second data bit as the fifth identifier, and configuring each third data bit as the data to be transmitted to obtain a third data packet to be transmitted.
5. The data transmission method based on a serial port device according to claim 1, characterized in that: The transmitting the first data packet to be transmitted or the second data packet to be transmitted based on the transmission sequence identifier includes: Determining a transmission order of the first data packet to be transmitted or the second data packet to be transmitted based on the transmission order identifier; Based on the transmission order, the first data packet to be transmitted or the second data packet to be transmitted is transmitted.
6. The data transmission method based on a serial port device according to claim 5, characterized in that: The method further comprises: Monitor the transmission status of each data packet to be transmitted; When the transmission status of the current data packet to be transmitted is abnormal, the current data packet to be transmitted is cleared, and the process returns to the step of transmitting the first data packet to be transmitted or the second data packet to be transmitted based on the transmission sequence.
7. The data transmission method based on a serial port device according to any one of claims 1 to 6, characterized in that: The serial port device is provided with an enable register, and the enable register has the enable of each function of the serial port device, and the method further includes: When the first data bit in the data packet to be transmitted is configured as the first flag, the enable register is turned on to enable various functions of the serial port device.
8. A data transmission device based on a serial port device, applied to a host, characterized in that: The data bits of a transmission data packet of the serial port device include: a first data bit for transmission mode selection, a second data bit and a plurality of third data bits for transmitting data, and the device includes: An acquisition module, configured to acquire data to be transmitted and an address of a target slave machine corresponding to the data to be transmitted; a first processing module, configured to, when there are multiple addresses of the target slave machine, configure a transmission sequence identifier for the data to be transmitted, configure the first data bit as a first identifier, configure the second data bit as a second identifier, and configure each third data bit as the address of the current target slave machine, to obtain multiple first data packets to be transmitted with the transmission sequence identifier, wherein the first identifier is used to indicate that the current transmission mode is a multi-slave mode, and the second identifier is used to indicate that the first data packets to be transmitted transmit addresses; a second processing module, configured to transmit the plurality of first data packets to be transmitted based on the transmission sequence identifier, so that each target slave machine starts responding to the data packet to be transmitted corresponding to the transmission sequence identifier when verifying that the address transmitted in the first data packet to be transmitted is consistent with its own address; a third processing module, configured to configure the first data bit as a first identifier, configure the second data bit as a third identifier, and configure each third data bit as the data to be transmitted, to obtain a second data packet to be transmitted with the transmission sequence identifier, wherein the third identifier is used to indicate that the second data packet to be transmitted transmits data; The fourth processing module is configured to transmit the second data packet to be transmitted based on the transmission sequence identifier, so that each target slave receives the second data packet to be transmitted based on the transmission sequence identifier of the second data packet to be transmitted.
9. An electronic device, characterized in that: include: memory for storing computer programs; A processor, configured to implement the steps of the data transmission method based on a serial port device as claimed in any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, wherein when the computer program is executed by a processor, the steps of the data transmission method based on a serial port device according to any one of claims 1 to 7 are implemented.