Serial asynchronous communication sending method and receiving method, storage medium

By packing data into N byte * 8 bit in serial asynchronous communication and verifying it, the problems of small data volume and low code error diagnosis coverage in the existing technology are solved, and efficient serial asynchronous communication protocol is realized, which improves the Data valid digits and error diagnostic coverage.

CN114826487BActive Publication Date: 2025-01-17SHANGHAI VMAX NEW ENERGY CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202210454707.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-04-24
Publication Date
2025-01-17
Estimated Expiration
2042-04-24

AI Technical Summary

Technical Problem

The existing serial port asynchronous communication protocol has a small amount of data in one frame and a low coverage of code error diagnosis, making it difficult to meet the efficient communication needs between complex ECUs.

Method used

By packing the data into one frame of N byte * 8 bit, filling the data and checking it, increasing the number of valid digits of each frame of data, and using a one-dimensional array for signal filling and verification, ensuring that the receiver can accurately parse and Verify data.

Benefits of technology

It significantly increases the number of data effective bits and error diagnosis coverage, and improves communication efficiency and data sorting accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114826487B_ABST
    Figure CN114826487B_ABST
Patent Text Reader

Abstract

The present invention discloses a sending method and a receiving method and a storage medium for serial asynchronous communication. In the data sending method of serial asynchronous communication, the sender packages the data to be sent in the form of N byte*8 bits as a frame of data, wherein N is greater than or equal to 1; and then sends out each frame of data after packaging; the packaging process includes: filling the data to be sent in the 1st bit to the 7th bit of the 0th byte to the N-2nd byte of each frame of data; verifying the data to be sent, and filling the verification result in the 1st bit to the 7th bit of the N-1st byte; assigning a value to the 0th bit of the 0th byte in each frame of data, and assigning a value to the 0th bit of the 1st byte to the N-1st byte in each frame of data, so that the value of the 0th bit of the 0th byte in each frame of data is different from the value of the 0th bit of the 1st byte to the N-1st byte. The serial asynchronous communication protocol of the present invention is efficient, has many valid data bits, high error diagnosis coverage, and flexible signal mapping.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to a serial asynchronous communication protocol between chips, and in particular to a serial asynchronous communication method between multiple chips in a complex ECU controller, specifically a serial asynchronous communication sending method and a serial asynchronous communication receiving method. Background Art

[0002] With the development of power electronics technology and the rapid development of automation and intelligence, products like automobiles often have dozens of ECUs, making it increasingly difficult to manage components for the entire vehicle, and the CAN communication topology between different ECUs is becoming increasingly complex. Therefore, integrating multiple ECUs into one controller and making all-in-one products is the current development trend of automotive component manufacturers. The corresponding CAN communication between multiple ECUs can also be converted into serial communication or SPI communication between chips in all-in-one products.

[0003] SPI communication requires 4 wires, occupies more chip pins, and has a master-slave concept, so the control is relatively complex and inconvenient for communication between vehicle chips. However, serial communication only requires 2 wires, occupies fewer chip pins, and has no master-slave concept, so it has good applicability.

[0004] Serial communication is divided into synchronous communication and asynchronous communication. Serial synchronous communication needs to send a synchronous clock before sending data, which is quite complicated to implement and is rarely used in practice. Serial asynchronous communication saves chip resources, has a simple protocol, and is easy to implement, so it is the most common inter-chip communication method. However, the traditional serial asynchronous communication protocol has less data per frame, only 7 data bits, and only one parity bit, so it has disadvantages such as low communication efficiency and low error diagnosis coverage.

[0005] Therefore, how to provide a sending method and a receiving method for serial asynchronous communication with a large amount of communication data in one frame and a high error diagnosis coverage is a technical problem that needs to be solved urgently in the industry. Summary of the invention

[0006] In order to solve the technical problems in the prior art that the amount of communication data in one frame is small and the error diagnosis coverage is low, the present invention proposes a sending method and a receiving method and a storage medium for serial asynchronous communication.

[0007] The data transmission method of serial asynchronous communication proposed by the present invention is that the sender packages the data to be sent in the form of Nbyte*8 bits as one frame of data, where N is greater than or equal to 1; and then sends out each frame of the packaged data;

[0008] The packaging process includes:

[0009] Fill the data to be sent in the first bit to the seventh bit of the 0th byte to the N-2th byte of each frame of data;

[0010] Verify the data to be sent and fill the verification result in the 1st to 7th bits of the N-1th byte;

[0011] Assign a value to the 0th bit of the 0th byte in each frame of data, and assign a value to the 0th bit of the 1st byte to the N-1th byte in each frame of data, so that the value of the 0th bit of the 0th byte in each frame of data is different from the value of the 0th bit of the 1st byte to the N-1th byte.

[0012] Furthermore, N is a multiple of 8.

[0013] Further, the filling process includes:

[0014] Define a one-dimensional array with data type UnitN;

[0015] One or more signals are filled into corresponding elements of the one-dimensional array by bitwise AND and shift.

[0016] Furthermore, when the data length of a signal exceeds N bits, a left shift or a right shift is used to obtain the corresponding positions of different elements in the high or low bits of the signal.

[0017] Furthermore, the verification is performed in a checksum manner.

[0018] Furthermore, the 0th bit of the 0th byte in each frame of data is assigned a value of 1, and the 0th bit of the 1st byte to the N-1th byte in each frame of data is assigned a value of 0.

[0019] The data receiving method of serial asynchronous communication proposed by the present invention, wherein the data is sent by the data sending method of serial asynchronous communication described in the above technical solution, comprises:

[0020] Prepare twice the length of a frame of data in advance as the length of the buffer;

[0021] Find the starting byte of a frame of data from the buffer according to the value of the 0th bit of the 0th byte when sending;

[0022] From the start byte to the N-2 byte, the 0th bit is removed to form a frame of N bytes.

[0023] Verify the N-byte data using the 1st bit to the 7th bit of the N-1th byte;

[0024] If the verification passes, the mapped signal is updated.

[0025] Furthermore, the cache receives the sent data through a one-dimensional array.

[0026] The computer-readable storage medium proposed in the present invention is used to store a computer program, and when the computer program is running, the data sending method of serial asynchronous communication described in the above technical solution is executed.

[0027] The present invention proposes a serial asynchronous communication protocol with high efficiency, many valid data bits, high error code diagnosis coverage, and flexible signal mapping. In a specific embodiment, the present invention proposes a communication method with 8 bytes as a frame, and a frame has a total of 7*7=49 bits as valid data segments. The last bit of each byte is in the format of 10000000 and is used as an identifier of the starting byte position. Compared with the traditional serial asynchronous communication protocol, in which a frame of data has only 7 data bits and only one parity bit, it can be seen that the communication protocol proposed by this patent greatly increases the valid data bits, improves the error code diagnosis coverage, and facilitates the receiver to perform correct data sorting. BRIEF DESCRIPTION OF THE DRAWINGS

[0028] The present invention is described in detail below with reference to the embodiments and accompanying drawings, wherein:

[0029] Figure 1 It is a schematic diagram of a frame of data in the prior art.

[0030] Figure 2 It is a schematic diagram of a frame of data of the present invention.

[0031] Figure 3 It is a filling practice flow chart of the present invention.

[0032] Figure 4 It is a signal filling schematic diagram of a specific embodiment of the present invention.

[0033] Figure 5 It is the receiving and parsing flow chart of the present invention. DETAILED DESCRIPTION

[0034] In order to make the technical problems, technical solutions and beneficial effects to be solved by the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.

[0035] Thus, a feature indicated in this specification will be used to illustrate one of the features of an embodiment of the present invention, rather than implying that each embodiment of the present invention must have the described feature. In addition, it should be noted that this specification describes many features. Although some features can be combined together to illustrate possible system designs, these features can also be used in other combinations that are not explicitly described. Thus, unless otherwise stated, the described combinations are not intended to be limiting.

[0036] Since the serial communication protocol has no master-slave concept, two electronic control units (ECUs) communicating with each other need to be configured with the same baud rate, and the sender and the receiver need to package and unpack the data according to the same protocol. The present invention mainly improves the communication protocol between two electronic control units communicating with each other, that is, the sending protocol and the receiving protocol are improved, so that the data volume of the serial asynchronous communication is larger and the error coverage rate is higher. Therefore, the specific description of the communication protocol of this patent will be carried out according to the sending protocol and the receiving protocol. The electronic control unit (ECU) is also called "driving computer", "on-board computer", etc. Like an ordinary computer, it is composed of a microcontroller (MCU), memory (ROM, RAM), input / output interface (I / O), analog-to-digital converter (A / D), and large-scale integrated circuits such as shaping and driving.

[0037] In the data transmission method of serial asynchronous communication of the present invention, the sender packages the data to be sent in the form of N bytes*8 bits (N bytes*8 bits) as one frame of data, and then sends out each frame of packaged data. Since the data starts from the 0th byte, N is greater than or equal to 1, that is, one frame of data of the present invention can send at least 2 bytes*8 bits (2 bytes*8 bits).

[0038] like Figure 2 The specific packaging process is described below. First, fill the data to be sent in the 1st bit to the 7th bit of the 0th byte to the N-2th byte of each frame of data. Assuming N is 8, the actual amount of data that can be contained in a frame of data is 7*7 bits.

[0039] The data to be sent is then verified, and the verification result is filled in the 1st to 7th bits of the N-1th byte.

[0040] Finally, assign a value to the 0th bit of the 0th byte in each frame of data, and assign a value to the 0th bit of the 1st byte to the N-1th byte in each frame of data, so that the value of the 0th bit of the 0th byte in each frame of data is different from the value of the 0th bit of the 1st byte to the N-1th byte, so as to identify the starting bit of the starting byte. Then the packaged frame of data can be sent out.

[0041] In a specific embodiment, the 0th bit of the 0th byte in each frame of data may be assigned a value of 1, and the 0th bit of the 1st byte to the N-1th byte in each frame of data may be assigned a value of 0.

[0042] like Figure 3 As shown in the above process, when filling the data corresponding to the signal, a one-dimensional array with a data type of UnitN can be defined, where N is an integer multiple of 8, and then one or more signals are filled into the corresponding elements of the one-dimensional array by bitwise AND and shift. For example, when the data is packaged in the form of 8byte*8bit as a frame, a one-dimensional array of unit8 with 8 elements is defined.

[0043] When the data length of a signal exceeds N bits, the high or low bits in the signal are shifted left or right to the corresponding positions of different elements.

[0044] In a specific embodiment, the verification may be performed in a checksum manner.

[0045] N of the present invention can be a multiple of 8. In view of the general capabilities of current chips, in one embodiment of the present invention, one frame of data can send at least 8 bytes*8 bits. In some chips with better capabilities, N can also be 16, that is, one frame of data sends 16 bytes*8 bits.

[0046] Based on the above technical solution, a specific sending protocol of the present invention is described.

[0047] When N is 8, the present invention can send a frame of data with a maximum length of 7*7=49 bits each time. The data to be sent is first filled according to the protocol format specified above. If the data bits of this frame are not filled (49 data bits), they are filled with 0. Then the checksum of this frame of data is calculated according to the filled data bits. The data bits corresponding to each of the first 7 bytes can be simply added together, or other encryption methods can be used. The present invention simply adds each of the first 7 bytes together as a column; finally, the last bit of each byte is filled with 1, and the last bit of the 1st to 7th bytes is filled with 0. The purpose of this is to facilitate the receiver to find the correct starting byte in sequence. In this way, the packaging of a frame of 64 bits of data is completed, and the packaged data is transmitted to the underlying serial communication SCI module for transmission. The SCI module is a serial communication module. The SCI module contains a baud rate generator inside, which divides the bus frequency to generate the baud rate required for serial communication.

[0048] Below Figure 4 As an example, according to the present invention, Figure 3 The data filling calculation of the sending frame is performed according to the process. The data type of the signal Signal1 is uint8, the data type of the signal Signal2 is uint16, and the data type of the signal Signal3 is uint8.

[0049] 1) Define a one-dimensional array uint8 TxArray[8] with a data type of uint8 and a dimension of 8.

[0050] 2) Fill the data segment (Data segment, i.e. 49-bit length data) of the signal to be sent. The data array can be filled by shifting and bitwise AND method to fill the signal data.

[0051] TxArray[0]=(Signal[1]&0x7F)<<1;

[0052] TxArray[1]=(Signal[2]&0x07FF)>>4<<1;

[0053] TxArray[2]=((Signal[2]&0x000F)<<4)+((Signal[3]&0x07)<<1).

[0054] The calculation of CheckSum is TxArray[7]=(TxArray[0]+TxArray[1]+TxArray[2])<<1.

[0055] 3) Fill the last bit of each byte. Fill bit0 of byte0 with 1 and bit0 of bytes1 to 7 with 0, that is, TxArray[0] = TxArray[0] | 0x01, TxArray[1 to 7] = TxArray[1 to 7] & 0xFE. This operation is to allow the receiver to accurately find the starting byte.

[0056] The above three steps can complete the filling of all bits of the sending frame.

[0057] The data receiving method of serial asynchronous communication of the present invention receives data sent by the data sending method of serial asynchronous communication of the above technical solution.

[0058] like Figure 5 As shown, the data receiving method of the serial asynchronous communication of the present invention needs to prepare twice the length of a frame of data as the length of the buffer in advance. Specifically, the buffer receives the sent data through a one-dimensional array.

[0059] The starting byte of a frame of data is found from the buffer according to the value of the 0th bit of the 0th byte when sending. Then, the 0th bit of the N-2th byte is removed from the starting byte to form a frame of N bytes of data. The N bytes of data are verified by the 1st bit to the 7th bit of the N-1st byte. If the verification passes, the mapped signal is updated.

[0060] When a frame of data is sent with 8 bytes*8 bits, the corresponding receiving protocol is as follows.

[0061] When the underlying SCI module receives data, it needs to define the receive data buffer length as 16 bytes, because the sender sends data in 8-byte length per frame. The receiver and sender of the serial asynchronous communication will not perform synchronous processing. Therefore, the 0th byte placed in the buffer by the receiver is not necessarily the 0th byte in a frame of data sent by the sender. In order to find a complete frame of data, the receiver needs to expand the receive buffer to twice that of the sender.

[0062] The specific implementation method is:

[0063] 1) First find the byte with bit0 set to 1 from the data in the cache as the starting byte;

[0064] 2) Count 7 bytes from the starting byte in the cache and add them to the starting byte to form a complete frame of 8-byte data;

[0065] 3) Remove the last bit of each byte in the 8 bytes to obtain the complete data bits, take the lower 7 bits of the value obtained by adding the data of bytes 0 to 6, and compare it with the value in the 7th byte. If they are the same, the CheckSum check is determined to be passed, and the mapped signal is updated using the data of bytes 0 to 6; if they are different, the CheckSum check is determined to be failed, and the signal is not updated.

[0066] In one embodiment, the receiving protocol is Figure 4 As an example, follow the signal protocol shown in Figure 5 The signal analysis of the received frame is performed according to the process.

[0067] 1) Find a complete frame in order: define the receive data buffer length as 16 bytes, define a one-dimensional array uint8 RxBuffer

[16] with a data type of uint8 and 16 elements, find the byte with bit0 set to 1 as the starting position byte0, count 7 bytes from the end, and assign these 8 bytes to the array uint8 RxArray[8];

[0068] 2) Get the complete Data segment: Shift each element in the RxArray array right by one bit. This operation is to remove the bit 0 that identifies the starting byte, that is, execute RxArray[0~7]>>1, and assign the result to RxArray_Data[0~7];

[0069] 3) Checksum and checksum:

[0070] Is (RxArray_Data[0]+RxArray_Data[1]+RxArray_Data[2])&0x7F equal to RxArray_Data[7]. If they are not equal, the communication is considered invalid and the signal is not assigned. If they are equal, the communication is considered valid and the following step 4) is executed to assign the signal.

[0071] 4) Finally, assign the signal: Signal1=RxArray_Data[0], Signal2=(RxArray_Data[1]<<4)+ (RxArray_Data[2]>>3), Signal3=RxArray_Data[2]&0x07.

[0072] The above four steps complete the error code diagnosis and signal assignment of the received frame.

[0073] Will Figure 1 and Figure 2 For comparison, Figure 1 It is a traditional serial asynchronous communication protocol. One frame of data has only 7 data bits and only one parity bit. The amount of data transmitted in one frame is small and the error diagnosis coverage is low. Figure 2 For a communication mode with 8 bytes as one frame, a frame has a total of 7*7=49 bits as valid data segments, and the last bit of each byte is in the format of 10000000, which is used as the identifier of the starting byte position. It can be clearly seen that the data volume of a frame of data of the present invention is larger, and the error diagnosis coverage rate is high. In some chips with higher capabilities, the present invention can also use a communication mode with 16 bytes as one frame, or a communication mode with 32 bytes as one frame, to further increase the communication data volume of a frame of the serial port, and the check code can also achieve a wide coverage rate.

[0074] The present invention also protects a corresponding computer-readable storage medium, which is used to store a computer program, and when the computer program is running, the data transmission method of the serial asynchronous communication of the above technical solution of the present invention is executed. Of course, when the computer program is running, it can also execute the data receiving method of the serial asynchronous communication of the above technical solution of the present invention.

[0075] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the protection scope of the present invention.

Claims

1. A data transmission method for serial asynchronous communication, characterized in that: It includes a data sending method for serial asynchronous communication and a data receiving method for serial asynchronous communication; The data transmission method of the serial asynchronous communication comprises: The sender packages the data to be sent in the form of N bytes*8 bits as one frame of data, where N is a multiple of 8, and then sends each frame of packaged data out; The packaging process includes: Fill the data to be sent in the 1st to 7th bits of the 0th byte to the N-2th byte of each frame of data; Verify the data to be sent and fill the verification result in the 1st to 7th bits of the N-1th byte; Assign a value to the 0th bit of the 0th byte in each frame of data, and assign a value to the 0th bit of the 1st byte to the N-1th byte in each frame of data, so that the value of the 0th bit of the 0th byte in each frame of data is different from the value of the 0th bit of the 1st byte to the N-1th byte; assign a value of 1 to the 0th bit of the 0th byte in each frame of data, and assign a value of 0 to the 0th bit of the 1st byte to the N-1th byte in each frame of data; The data receiving method of the serial asynchronous communication comprises: Prepare twice the length of a frame of data in advance as the length of the buffer; Find the starting byte of a frame of data from the buffer according to the value of the 0th bit of the 0th byte when sending; From the start byte to the N-2 byte, after the 0th bit is removed, a frame of N-1 bytes of data is formed; Verify the first N-1 bytes of data through the 1st bit to the 7th bit of the N-1th byte; If the verification passes, the mapped signal is updated; The filling process includes: Define a one-dimensional array with data type UnitN; Fill one or more signals into corresponding elements of the one-dimensional array by bitwise AND and shifting; The verification is performed in a checksum manner.

2. The data transmission method of serial asynchronous communication according to claim 1, characterized in that: When the data length of a signal exceeds N bits, a left shift or a right shift is used to obtain the corresponding positions of different elements in the high or low bits of the signal.

3. The data transmission method of serial asynchronous communication according to claim 1, characterized in that: The buffer receives the sent data through a one-dimensional array.

4. A computer-readable storage medium for storing a computer program, characterized in that: The computer program executes the data transmission method for serial asynchronous communication according to any one of claims 1 to 3 when running.

Citation Information

Patent Citations

  • Data transmission protocol method

    CN108512785A