Method for receiving byte data of different lengths in serial port FIFO based on DSP

By combining the FIFO functions of the timer module and the SCI module, the problem of interruption and chip overhead when the DSP serial port receives data of different lengths is solved, and the integrity of data reception and the improvement of motor control performance is achieved.

CN116346287BActive Publication Date: 2025-08-29GUIZHOU AEROSPACE LINQUAN MOTOR CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310328997.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-03-30
Publication Date
2025-08-29
Estimated Expiration
2043-03-30

AI Technical Summary

Technical Problem

When the DSP serial port FIFO receives data of different lengths, it cannot determine the length of the received data, resulting in the reception interrupt being easily interrupted, the data is incomplete, and multiple interrupts entering the interrupts cause large chip overhead, affecting the motor driving performance.

Method used

The timer module is used to combine the FIFO function of the SCI module. Through the timer interrupt frequency and the receiving FIFO module, the judgment of the received data length and data integrity verification are realized. The FIFO is cleared by the timer interrupt and the reception completion flag bit is output.

Benefits of technology

It solves the problems of easy interruption of DSP serial port reception and large chip overhead, ensures data reception integrity, and improves DSP's control performance on the motor.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116346287B_ABST
    Figure CN116346287B_ABST
Patent Text Reader

Abstract

The present invention discloses a method for receiving byte data of varying lengths using a DSP-based serial port FIFO. By coordinating a timer interrupt with the serial port's receive FIFO module, this method solves the problem of data reception being interrupted by the DSP serial port receive interrupt and excessive chip overhead. It also solves the problem of the DSP's serial port FIFO receiving being unable to determine the length of received data, resulting in the inability to generate a receive completion flag. The present invention utilizes the DSP's SCI module and timer module to optimize conventional methods for receiving byte data of varying lengths, significantly reducing the DSP's CPU overhead in receiving data of varying lengths, thereby reducing the impact of received data on motor control and significantly improving the DSP chip's motor control performance.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to a method for receiving byte data of different lengths of a serial port FIFO based on DSP, and belongs to the technical field of robot joints and steering gear motor driving. Background Art

[0002] In order to ensure the security and reliability of the robot's internal communication and meet the robot's needs to perform various complex actions, the robot system communication protocol often adopts MODBUS and other protocols with variable data length per frame.

[0003] In the current existing technology, since the DSP's serial port FIFO cannot determine the length of the received data when receiving byte data of different lengths, it is impossible to generate a receive completion flag. The generally adopted solution is to receive data one by one through the serial port (SCI) receive interrupt of the DSP or other MCU. Applying this method will make the receive interrupt easily interrupted by other interrupts, which will then cause the data to be overwritten and the received data to be incomplete. In addition, multiple interrupts will cause large chip overhead, affecting the speed of other programs running, thereby reducing the DSP or MCU's driving performance of the motor. Summary of the Invention

[0004] In order to solve the above technical problems, the present invention provides a method for receiving byte data of different lengths in a serial port FIFO based on DSP.

[0005] The present invention is achieved through the following technical solutions.

[0006] The present invention provides a method for receiving byte data of different lengths in a serial port FIFO based on a DSP. The DSP has a timer module and an SCI module, and the SCI module has a function of receiving a FIFO. The method specifically includes the following steps:

[0007] ① Initialize DSP and set up SCI module and timer module;

[0008] ② Assume that the total length of a frame of data to be received is X bytes, the total length of the receive array is Y bytes, the receive wait timeout is B seconds, the receive wait time count is Time_cnt, the current length of the receive array is Z, and Time_cnt = 0, Z = 0;

[0009] ③ The system enters the timer interrupt, and in the interrupt, it judges the flag bit of how many bytes the FIFO in the SCI module has received. If the number of bytes N received by the FIFO is equal to 0, jump to step ④; otherwise, jump to step ⑤;

[0010] ④ Determine whether Z is greater than 0. If so, Time_cnt = Time_cnt + 1 and jump to step ⑥; otherwise, the system exits the timer interrupt and jumps to step ②;

[0011] ⑤ The N bytes of data in the receive FIFO are stored in the receive array, Z = Z + N, Time_cnt = 0, the system exits the timer interrupt and jumps to step ③;

[0012] ⑥ Determine whether Time_cnt / A is greater than or equal to B. If so, jump to step ⑦; otherwise, the system exits the timer interrupt and jumps to step ③;

[0013] ⑦ Determine whether Z is equal to X. If so, jump to step ⑧; otherwise, the system exits the timer interrupt and jumps to step ②;

[0014] ⑧ Determine whether the check code of the received array complies with the communication protocol. If the check code of the received array is wrong, the system exits the timer interrupt and jumps to step ②; otherwise, outputs the reception success flag, the system exits the timer interrupt, and data reception ends.

[0015] In step ②, the total length of X is obtained by calculating the data length in each frame, and Y is greater than or equal to the maximum value MAX(X) of X.

[0016] In the step ①, the receiving FIFO depth of the SCI is set to 16 bytes, and the interrupt frequency of the timer is set to A Hz.

[0017] A is greater than P / (16*Q), and A is greater than 3*K, where P is the baud rate of serial communication, Q is the length of 1 byte, and K is the sending frequency of serial communication.

[0018] The receiving waiting timeout time B is less than 1 / K-(MAX(X)*Q) / P seconds and greater than or equal to (3.5*Q) / P seconds, where K is the sending frequency of the serial communication, X is the total length of a frame of data to be received, Q is the length of 1 byte, and P is the baud rate of the serial communication

[0019] The beneficial effects of the present invention are as follows: utilizing the receiving FIFO module of the serial port solves the problem that the receiving data will be interrupted due to the receiving interrupt of the DSP serial port and the chip overhead is too large; utilizing the setting of the timer interrupt frequency to regularly clear the data in the receiving FIFO of the serial port and perform the receiving waiting time, solves the problem that the FIFO reception cannot determine the length of the received data and thus cannot generate the receiving completion flag; ensuring the integrity of the data reception, making the data receiving method suitable for receiving communication protocol data with an indefinite length of each frame of data being returned. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] Figure 1 It is a flow chart of the present invention. DETAILED DESCRIPTION

[0021] The technical solution of the present invention is further described below, but the scope of protection claimed is not limited to the description.

[0022] like Figure 1 As shown, a method for receiving byte data of different lengths in a serial port FIFO based on DSP, wherein the DSP has a timer module and an SCI module, and the SCI module has a function of receiving FIFO, specifically comprising the following steps:

[0023] ① Initialize DSP and set up SCI module and timer module to realize the receive FIFO function of SCI module and the interrupt function of timer module;

[0024] ② Assume that the total length of a frame of data to be received is X bytes, the total length of the receive array is Y bytes, the receive wait timeout is B seconds, the receive wait time count is Time_cnt, the current length of the receive array is Z, and Time_cnt = 0, Z = 0;

[0025] ③ The system enters the timer interrupt, and in the interrupt, it judges the flag bit of how many bytes the FIFO in the SCI module has received. If the number of bytes N received by the FIFO is equal to 0, jump to step ④; otherwise, jump to step ⑤;

[0026] ④ Determine whether Z is greater than 0. If so, Time_cnt = Time_cnt + 1 and jump to step ⑥; otherwise, the system exits the timer interrupt and jumps to step ②;

[0027] ⑤ The N bytes of data in the receive FIFO are stored in the receive array, Z = Z + N, Time_cnt = 0, the system exits the timer interrupt and jumps to step ③;

[0028] ⑥ Determine whether Time_cnt / A is greater than or equal to B. If so, jump to step ⑦; otherwise, the system exits the timer interrupt and jumps to step ③;

[0029] ⑦ Determine whether Z is equal to X. If so, jump to step ⑧; otherwise, the system exits the timer interrupt and jumps to step ②;

[0030] ⑧Calculate the check code of the received array according to the communication protocol, and determine whether the check code of the received array is consistent with the calculated check code. If the check code of the received array is inconsistent with the calculated check code, the system exits the timer interrupt and jumps to step ②; otherwise, output the flag bit of successful reception, the system exits the timer interrupt, and data reception ends.

[0031] The total length of a frame of data to be received is X bytes. X is variable and can be calculated by adding the length of the data in each frame to the fixed length of the frame header, address code, function code, check code, etc., and Y is greater than or equal to the maximum value of X, MAX(X).

[0032] In the step ①, the receiving FIFO depth of the SCI is set to 16 bytes, and the interrupt frequency of the timer is set to A Hz.

[0033] Specifically, assume that the baud rate of the serial communication is P bps, the sending frequency of the serial communication is K Hz, the length of one byte is Q bits, and the receive wait timeout time B is less than 1 / K-(MAX(X)*Q) / P seconds and greater than or equal to (3.5*Q) / P seconds.

[0034] Specifically, the interrupt frequency of the timer is A Hz, A is greater than P / (16*Q), and A is greater than 3*K.

[0035] After receiving the data, the address, function, etc. of the received data are judged and converted according to the communication protocol to parse out the current control instructions.

[0036] As described above, the present invention aims to solve the problem that the reception of byte data of different lengths by using the serial port (SCI) of the DSP is easily interrupted by other interrupts, resulting in data being overwritten and incomplete received data, and multiple interrupts causing large chip overhead, affecting the operation of other programs. The problem that the length of the received data cannot be determined when using the serial port FIFO of the DSP to receive byte data of different lengths, resulting in the inability to generate a reception completion flag, is solved by cooperating with the timer interrupt and the serial port receiving FIFO module. The problem that the reception of data by the DSP serial port receiving interrupt may be interrupted and the chip overhead is too large is also solved. The problem that the serial port FIFO of the DSP cannot determine the length of the received data, resulting in the inability to generate a reception completion flag, is also solved.

[0037] In summary, the present invention uses the SCI module and timer module of DSP to optimize the traditional method of receiving byte data of different lengths, greatly reducing the CPU overhead of DSP in receiving data of different lengths, thereby reducing the impact of received data on motor control, and greatly improving the control performance of the DSP chip on the motor.

Claims

1. A method for receiving byte data of different lengths from a serial port FIFO based on DSP, characterized by: The DSP has a timer module and an SCI module, and the SCI module has a receiving FIFO function, which specifically includes the following steps: ① Initialize DSP and set up SCI module and timer module; ② Assume that the total length of a frame of data to be received is X bytes, the total length of the receive array is Y bytes, the receive wait timeout is B seconds, the receive wait time count is Time_cnt, the current length of the receive array is Z, and Time_cnt = 0, Z = 0; ③ The system enters the timer interrupt, and in the interrupt, it judges the flag bit of how many bytes the FIFO in the SCI module has received. If the number of bytes N received by the FIFO is equal to 0, jump to step ④; otherwise, jump to step ⑤; ④ Determine whether Z is greater than 0. If so, Time_cnt = Time_cnt + 1 and jump to step ⑥; otherwise, the system exits the timer interrupt and jumps to step ②; ⑤ The N bytes of data in the receive FIFO are stored in the receive array, Z = Z + N, Time_cnt = 0, the system exits the timer interrupt and jumps to step ③; ⑥ Determine whether Time_cnt / A is greater than or equal to B. If so, jump to step ⑦; otherwise, the system exits the timer interrupt and jumps to step ③; where A is the timer interrupt frequency; ⑦ Determine whether Z is equal to X. If so, jump to step ⑧; otherwise, the system exits the timer interrupt and jumps to step ②; ⑧ Determine whether the check code of the received array complies with the communication protocol. If the check code of the received array is wrong, the system exits the timer interrupt and jumps to step ②; otherwise, outputs the reception success flag, the system exits the timer interrupt, and data reception ends.

2. The method for receiving byte data of different lengths from a serial port FIFO based on DSP as claimed in claim 1, wherein: In step ②, the total length of X is obtained by calculating the data length in each frame, and Y is greater than or equal to the maximum value MAX(X) of X.

3. The method for receiving byte data of different lengths in a serial port FIFO based on DSP as claimed in claim 1, wherein: In the step ①, the receiving FIFO depth of the SCI is set to 16 bytes, and the interrupt frequency of the timer is set to A Hz.

4. The method for receiving byte data of different lengths in a serial port FIFO based on DSP as claimed in claim 3, wherein: A is greater than P / (16*Q), and A is greater than 3*K, where P is the baud rate of serial communication, Q is the length of 1 byte, and K is the sending frequency of serial communication.

5. The method for receiving byte data of different lengths in a serial port FIFO based on DSP as claimed in claim 1, wherein: The receiving wait timeout time B is less than 1 / K-(MAX(X)*Q) / P seconds and greater than or equal to (3.5*Q) / P seconds, where K is the sending frequency of the serial communication, X is the total length of a frame of data to be received, Q is the length of 1 byte, and P is the baud rate of the serial communication.

Citation Information

Patent Citations

  • IEEE1394 data sending / receiving method based on DSP hardware platform

    CN101493802A

  • System and method for increasing communication fault-tolerant rate of single-chip microcomputers

    CN106445717A