Method for realizing communication between double processors of electro-hydraulic servo controller through SPI bus

By introducing STM32 and DSP state machines and flow control pins into the electro-hydraulic servo controller, the communication state between the two processors is coordinated, solving the problem of low reliability of SPI communication and achieving stability and accuracy of data transmission.

CN116203882BActive Publication Date: 2026-06-02CHONGQING UNIV

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
CHONGQING UNIV
Filing Date
2023-03-07
Publication Date
2026-06-02

AI Technical Summary

Technical Problem

The existing SPI communication method lacks a flow control mechanism in electro-hydraulic servo controllers, resulting in low data transmission reliability, especially prone to transmission failure under the influence of interference signals.

Method used

An STM32 microprocessor is used to set up the STM32 state machine, and a DSP microprocessor is used to set up the DSP state machine. Through flow control pins and a custom communication data message format, the working state switching between the two processors is coordinated to ensure that data interaction is only performed after normal communication between the two parties. A data verification mechanism is added to improve reliability.

Benefits of technology

This effectively avoids data transmission errors, improves the operational and data reliability of the electro-hydraulic servo controller, and ensures the stability and accuracy of communication.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116203882B_ABST
    Figure CN116203882B_ABST
Patent Text Reader

Abstract

This invention discloses a method for implementing SPI bus communication between two processors in an electro-hydraulic servo controller. The STM32 microprocessor has an STM32 state machine, and the DSP microprocessor has a DSP state machine. The switching of operating states is coordinated through the transitions between the STM32 and DSP state machines. The method includes the following steps: A1: After receiving a start command from the host computer, the STM32 microprocessor controls the DSP microprocessor to operate via its flow control pin; A2: The STM32 microprocessor controls the DSP microprocessor to switch its DSP state machine to data communication mode via a command message; A3: The STM32 microprocessor acquires sensor data collected by the DSP microprocessor; A4: The STM32 microprocessor determines whether it has received a stop command from the host computer. If yes, proceed to step A5; otherwise, proceed to step A3; A5: The STM32 microprocessor controls the DSP microprocessor to switch its DSP state machine to sleep mode via a command message. This invention avoids data transmission errors caused by the DSP microprocessor prematurely sending data to the STM32 microprocessor, thus improving the reliability of the servo controller.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of electro-hydraulic servo controller technology, and in particular to a method for implementing SPI bus communication between two processors in an electro-hydraulic servo controller. Background Technology

[0002] An electro-hydraulic servo system is a hydraulic control system with a servo element (servo valve or servo pump) as the control core. It typically consists of a command device, controller, amplifier, hydraulic source, servo element, actuator, feedback sensor and load.

[0003] In electro-hydraulic servo systems, the stable movement of the actuator depends on the effective acquisition and processing of feedback sensor information. Electro-hydraulic servo system controllers often need to collect information from multiple sensors for preprocessing such as filtering. The processed data is then subjected to certain calculations by the controller before controlling the output signal, thereby enabling the actuator to achieve the desired motion effect. Currently, numerous papers and patents have researched and verified electro-hydraulic servo controllers with dual-core processor structures, for example:

[0004] In their paper "Design and Matlab Simulation of an Electro-hydraulic Servo Controller," Yao Kunshan et al. proposed an architecture for an electro-hydraulic servo controller using a dual-core processor architecture of STM32F103ZET6 and TMS320F28335. The two processors collaborate through a high-speed, full-duplex, synchronous communication bus called SPI (Serial Peripheral Interface), fully leveraging the control advantages of the microcontroller and the data processing capabilities of the DSP.

[0005] Chinese patent application CN203759526U designs a dual-processor electro-hydraulic servo controller based on an STM32 microprocessor (model STM32F103RET6) and a DSP microprocessor (model TMS320F28335). The controller uses the STM32 microprocessor to acquire data and then sends the acquired signals to the DSP microprocessor for processing and calculation via the SPI bus.

[0006] SPI communication consists of a master device and a slave device. The basic framework of SPI bus communication is as follows: the master device initiates the CS chip select signal and simultaneously initiates a synchronization clock on the SCLK signal line. The master and slave devices complete bidirectional data transmission based on the SCLK signal on the MOSI signal line (master output, slave input) and the MISO signal line (master input, slave output).

[0007] However, existing SPI communication methods lack specified flow control and an acknowledgment mechanism to confirm data reception. In electro-hydraulic servo controller applications, when SPI performs high-speed serial data transmission at bit-by-bit rates, transmission failures are frequently caused by interference signals, significantly reducing data reliability.

[0008] The reliability of SPI bus communication between the two processors in an electro-hydraulic servo controller is crucial. In addition to taking hardware protection measures to eliminate interference, how to improve and enhance the reliability of SPI communication through software is a technical problem that needs to be solved in this field. Summary of the Invention

[0009] In view of at least one deficiency of the prior art, the purpose of this invention is to provide a method for implementing SPI bus communication between two processors in an electro-hydraulic servo controller. The STM32 microprocessor is equipped with an STM32 state machine, and the DSP microprocessor is equipped with a DSP state machine. This invention executes the subsequent data interaction process only after both communication processors are in a normal communication state, which can effectively avoid the phenomenon of the DSP microprocessor sending data to the STM32 microprocessor in advance, causing data transmission communication errors, and improve the working reliability of the electro-hydraulic servo controller.

[0010] To achieve the above objectives, the present invention adopts the following technical solution: a method for implementing SPI bus communication between two processors in an electro-hydraulic servo controller, wherein the two processors of the electro-hydraulic servo controller include an STM32 microprocessor and a DSP microprocessor. The STM32 microprocessor is used to connect to a host computer, and the DSP microprocessor is used to connect to sensors and servo components. The DSP microprocessor and the STM32 microprocessor communicate via an SPI bus, with the DSP microprocessor acting as the SPI communication master and the STM32 microprocessor acting as the SPI communication slave. A flow control pin is also provided between the STM32 microprocessor and the DSP microprocessor. The STM32 microprocessor has an STM32 state machine, and the DSP microprocessor has a DSP state machine. The switching of the working states of the STM32 microprocessor and the DSP microprocessor is coordinated by the transformation between the STM32 state machine and the DSP state machine; the method includes the following steps:

[0011] Step A1: After receiving the start command from the host computer, the STM32 microprocessor controls the DSP microprocessor to start working through the flow control pin;

[0012] Step A2: The STM32 microprocessor controls the DSP microprocessor to switch the DSP state machine to the data communication state via command messages;

[0013] Step A3: The STM32 microprocessor acquires the sensor data collected by the DSP microprocessor;

[0014] Step A4: Does the STM32 microprocessor determine if it has received a stop command from the host computer? If yes, proceed to step A5; if no, proceed to step A3.

[0015] Step A5: The STM32 microprocessor controls the DSP microprocessor to switch the DSP state machine to sleep state via command messages.

[0016] The STM32 state machine includes four states: Closed; Listening; Data Communication; and Sleep.

[0017] The STM32 state machine transitions during SPI bus communication include the following steps:

[0018] Step B1: After the STM32 microprocessor finishes running the initialization program, it waits for the host computer to send the power-on command. When the host computer sends the power-on command, the STM32 microprocessor generates a rising edge through the flow control pin, and the STM32's state machine changes from the CLOSED state to the LISTEN state.

[0019] Step B2: The STM32 microprocessor listens for instructions from the DSP microprocessor. When it receives a SYN-SENT instruction from the DSP microprocessor, it replies with a SYN ACK message, i.e., requests to send an acknowledgment command; and its status changes to DATA-COM. Otherwise, it waits for the DSP microprocessor to send the message. The SYN-SENT instruction is a request to send an instruction.

[0020] Step B3: The STM32 microprocessor and the DSP microprocessor perform normal data interaction;

[0021] Step B4: After receiving the sleep command from the host computer, the STM32 microprocessor sends a sleep command to the DSP microprocessor. After receiving the FIN ACK message from the DSP microprocessor, the STM32 microprocessor state machine enters the SLEEP state.

[0022] Step B5: After receiving the start command from the host computer, the STM32 microprocessor sends a rising edge to the DSP microprocessor through the flow control pin, and the STM32 state machine changes from the SLEEP state to the LISTEN state.

[0023] The DSP state machine includes five states: Closed (CLOSED); Listen (LISTEN); Request sent (SYN-SENT); Data communication (DATA-COM); and Sleep (SLEEP).

[0024] The DSP microprocessor state machine transitions during SPI bus communication include the following steps:

[0025] Step C1: After the DSP microprocessor is initialized, it enters the LISTEN state from the CLOSED state and waits to receive instructions from the STM32 microprocessor.

[0026] Step C2: After the DSP microprocessor receives the rising edge signal from the STM32 microprocessor's flow control pin, the controller begins to acquire signals from external sensors and process them. Once the first set of data is processed, the DSP's state machine enters the SYN-SENT state and sends a SYN-SENT command to the STM32.

[0027] Step C3: After receiving the SYN ACK message, the DSP microprocessor sends the latest processed data to the buffer, the state machine switches to the DATA-COM state, and begins to actively send the data in the buffer to the STM32 microprocessor.

[0028] Step C4: After receiving the FIN message from the STM32 microprocessor, the DSP microprocessor sends a FIN ACK, which is a request to end the response command; it then enters the SLEEP state; the FIN message is the sleep message.

[0029] The DSP microprocessor stops acquiring information from external sensors.

[0030] The instruction and data interaction between the STM32 microprocessor and the DSP microprocessor uses the following communication data message format, which includes a frame header, data segments, and a cyclic redundancy check (CRC) field. Specific communication data messages include command messages and sensor data messages.

[0031] The frame header includes: a message type field and a command type field; the frame header includes an ACK field, a SYN field, a FIN field, and a Type field; the command type field includes an ACK field, a SYN field, and a FIN field;

[0032] The meanings and values ​​of each field in the frame header are as follows:

[0033] ACK: 1 bit long, representing the acknowledgment flag, where 1 indicates that the bit is valid and 0 indicates that it is invalid;

[0034] SYN: 1 bit long, representing the transmission flag, where 1 indicates that the bit is valid and 0 indicates that it is invalid;

[0035] FIN: 1 bit long, representing the end flag, where 1 indicates that the bit is valid and 0 indicates that it is invalid;

[0036] Type: 2 characters long, representing the message type field, where 0b00 indicates a command message type and 0b11 indicates a data message type;

[0037] DATA: 32 bits in length, stores the data from external sensors collected by the DSP microprocessor when the electro-hydraulic servo controller is running normally, and is set to 0 in the command message type;

[0038] The CRC field is 2 bytes long and is calculated using a cyclic redundancy check method based on CRC16. The calculation range includes the frame header and the DATA part, and the parameters are as follows: 1. Check polynomial bit 0x1021; 2. Initial value 0xFFFF; 3. XOR value 0x0000.

[0039] The message type field determines the target frame based on the data in the Type bit; a Type bit of 0b00 represents a command frame, and a Type bit of 0b11 represents a data frame.

[0040] The command type field indicates that if both the ACK and SYN bits are 1, the command type is a request to send an acknowledgment command, i.e., SYNACK; if both the ACK and FIN bits are 1, the command type is a request to end the acknowledgment command, i.e., FIN ACK.

[0041] The DSP microprocessor acts as the SPI communication master, sending and receiving data via interrupts; the STM32 microprocessor acts as the SPI communication slave, sending and receiving data using DMA-based SPI communication.

[0042] The STM32 microprocessor controls the high and low levels of the flow control pin; after confirming that it has received the start command from the host computer, the STM32 microprocessor switches the state of the flow control pin from low to high and sends communication status indication information to the DSP microprocessor to confirm that it has started working.

[0043] Significant Effects: This invention provides a method for implementing SPI bus communication between two processors in an electro-hydraulic servo controller. The STM32 microprocessor is equipped with an STM32 state machine, and the DSP microprocessor is equipped with a DSP state machine. This invention executes subsequent data interaction only after both processors are in a state of normal communication capability. This effectively avoids data transmission errors caused by the DSP microprocessor prematurely sending data to the STM32 microprocessor, thus improving the reliability of the electro-hydraulic servo controller. Furthermore, the verification information carried in the communication message is used by both processors to verify the correctness of the received data, further enhancing the data reliability of communication between the two processors. Attached Figure Description

[0044] Figure 1 A schematic diagram of a dual-processor framework for an electro-hydraulic servo controller provided in the prior art;

[0045] Figure 2This is a schematic diagram of a 5-wire SPI communication method provided in an embodiment of the present invention;

[0046] Figure 3 This is a schematic diagram of the data packet format structure provided in an embodiment of the present invention;

[0047] Figure 4 This is a schematic diagram of dual-processor communication for an electro-hydraulic servo controller provided in an embodiment of the present invention;

[0048] Figure 5 This is a state machine transition diagram for the dual-processor communication of an electro-hydraulic servo controller provided in an embodiment of the present invention.

[0049] Figure 6 A flowchart of the SPI communication method for an electro-hydraulic servo controller provided in an embodiment of the present invention. Detailed Implementation

[0050] The present invention will now be described in further detail with reference to the accompanying drawings and specific embodiments.

[0051] like Figures 1-6 As shown, this invention provides a method for implementing SPI bus communication between two processors in an electro-hydraulic servo controller. In the electro-hydraulic servo controller, the SPI bus slave device is configured with DMA-based SPI communication, while the master device is configured with interrupt-based SPI communication. If the host computer controls the electro-hydraulic servo controller to start working, the SPI bus slave device controls the master device to switch to normal working state according to pre-set instructions via a state machine. Because this invention executes subsequent data interaction processes only after both communication devices are in a state of normal communication capability, it effectively avoids the phenomenon of data transmission errors caused by the DSP microprocessor sending data to the STM32 microprocessor prematurely, thus improving the operational reliability of the electro-hydraulic servo controller. Furthermore, the verification information carried in the communication message is used by both communication devices to verify the correctness of the received data, improving the data reliability of communication between the two processors.

[0052] The technical solution adopted in this invention is as follows: a DSP microprocessor is set as the SPI communication master, and an STM32 microprocessor is set as the SPI communication slave. The STM32 slave uses DMA (Direct Memory Access) to receive and send communication data.

[0053] Within the basic framework of SPI bus communication, a flow control pin is added for communication, which is pointed from the STM32 microprocessor to the DSP microprocessor.

[0054] Define a custom communication data message format to facilitate the sending of instructions and effective data exchange between the STM32 microprocessor and the DSP microprocessor;

[0055] Define a custom SPI bus communication state machine, and coordinate the switching of the working states of the two microprocessors through the changes in the state machine in conjunction with the communication data messages.

[0056] In view of this, the purpose of this invention is to provide an SPI bus communication method between two processors in an electro-hydraulic servo controller, which enables the TMS320F28335 DSP microprocessor and the STM32F429BIT6 STM32 microprocessor inside the controller to know each other's program running status, thereby facilitating the stable operation of the controller and reducing the occurrence of data transmission errors.

[0057] To address the aforementioned issues, this application proposes a method for implementing SPI bus communication between two processors in an electro-hydraulic servo controller, comprising the following steps:

[0058] S1: Set the DSP microprocessor as the SPI communication master and the STM32 microprocessor as the SPI communication slave. The STM32 slave uses DMA (Direct Memory Access) to receive and send communication data.

[0059] S2: In the basic framework of SPI bus communication, add a flow control pin for communication. This flow control pin is pointed from the STM32 microprocessor to the DSP microprocessor.

[0060] S3: Define a custom communication data message format to facilitate the interaction of instructions and valid data between the STM32 microprocessor and the DSP microprocessor;

[0061] S4: Define a custom SPI bus communication state machine, which, in conjunction with communication data messages, coordinates the switching of the working states of the two microprocessors through changes in the state machine.

[0062] Preferably, the DSP microprocessor is configured as the SPI communication master, and the STM32 microprocessor is configured as the SPI communication slave. The STM32 slave uses DMA to receive and send communication data. Specifically, in the SPI bus master-slave configuration, the DSP microprocessor is configured as the SPI communication master, sending and receiving data using interrupt mode. The STM32 microprocessor, as the SPI communication slave, uses DMA-based SPI communication to send and receive data.

[0063] Preferably, within the basic framework of SPI bus communication, a flow control pin is added for communication. This flow control pin is connected from the STM32 microprocessor to the DSP microprocessor. Specifically, a flow control pin is added between the STM32 microprocessor and the DSP microprocessor, and the STM32 controls the high and low voltage levels of this pin.

[0064] After receiving the start command from the host computer, the STM32 microprocessor switches its control pin from low to high, triggering it to send communication status indication information to the DSP microprocessor, thus enabling the DSP to confirm that it has started working.

[0065] Preferably, a custom communication data message format is defined to facilitate the interaction of instructions and valid data between the STM32 microprocessor and the DSP microprocessor. Specifically, the communication data message includes: a frame header, a data segment, and a CRC check field.

[0066] The frame header includes a message type field and a command type field, and the target frame is determined based on the message type field and the command type field.

[0067] The message type field specifies that a Type of 0b00 represents a command frame and a Type of 0b11 represents a data frame.

[0068] The command type field is configured such that if both the ACK and SYN bits are 1, the command type is a request to send an acknowledgment (SYNACK) command; if both the ACK and FIN bits are 1, the command type is a request to end an acknowledgment (FIN ACK) command.

[0069] The CRC check field provides a method for checking the validity of a message.

[0070] Preferably, a custom SPI bus communication state machine is used in conjunction with the communication data frame to coordinate the switching of the working states of the two microprocessors through changes in the state machine.

[0071] The STM32 state machine includes four states: Closed, Listen, Data-COM, and Sleep.

[0072] The DSP state machine includes five states: Closed, Listen, Request Send, Data Communication, and Sleep.

[0073] The SPI bus responds to the communication data message according to the preset communication data message format and the preset value message during the state machine switching process. The state switching of the communication state machine is controlled by the STM32 microprocessor to ensure that the electro-hydraulic servo controller operates in the required working mode.

[0074] Compared with existing technologies, this invention has the following advantages: This invention provides an SPI bus communication method between two processors in an electro-hydraulic servo controller. After receiving instructions from the host computer, the STM32 microprocessor notifies the DSP microprocessor to start working via a flow control pin. The two processors switch operating states through interactive communication messages, guided by a set state machine. After the electro-hydraulic servo controller is working normally, the DSP microprocessor periodically transmits data from external sensors required to control the electro-hydraulic servo system to the STM32 microprocessor. After receiving a stop command from the host computer, the STM32 microprocessor controls the DSP microprocessor to stop working via the state machine. Because this invention executes subsequent data interaction processes only after both communication devices are in a normal communication state, it effectively avoids the phenomenon of data transmission errors caused by the DSP microprocessor sending data to the STM32 microprocessor prematurely, thus improving the reliability of the electro-hydraulic servo controller. Furthermore, the verification information carried in the communication messages is used by both communication devices to verify the correctness of the received data, improving the data reliability of communication between the two processors.

[0075] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the present invention will be further described below with reference to the accompanying drawings.

[0076] like Figure 1 As shown, in the framework design of an electro-hydraulic servo controller, one architecture uses a DSP microprocessor and an STM32 microprocessor, with the two processors communicating via an SPI bus. The advantages of SPI communication are: full-duplex support, simple communication, and fast data transmission rate. However, the disadvantages of SPI communication are: no acknowledgment mechanism to confirm data reception, and no standardized data message format. Therefore, the current SPI communication method used between the two processors in an electro-hydraulic servo controller suffers from low reliability and an inability to coordinate the working states of the two processors.

[0077] To further address the aforementioned technical problems, this invention proposes a method for SPI bus communication between two processors in an electro-hydraulic servo controller. After the STM32 microprocessor is initialized, upon receiving a start command from the host computer, its state machine switches, and the DSP microprocessor starts working via a flow control pin. Both processors exchange instructions and data according to pre-set state machines and communication data messages. Once both the DSP microprocessor and the STM32 microprocessor are in normal working condition, the electro-hydraulic servo controller begins controlling the actuator. Because this invention only performs subsequent information exchange after confirming that both communicating parties are in a normal working state, it avoids errors in the communication of acquired external sensor data, improves communication reliability, and ensures the normal operation of the electro-hydraulic servo controller. The SPI bus communication method provided in this invention is described below.

[0078] Step 1: There are three ways to receive SPI bus data in a microprocessor: polling, interrupt, and DMA. The data communication efficiency of the three methods increases sequentially. The STM32 microprocessor's SPI peripheral supports all three methods, while the DSP microprocessor's SPI peripheral only supports polling and interrupt. To maximize the SPI communication efficiency between the two controllers, this application selects the DSP microprocessor as the master of the SPI bus communication, sending and receiving data via interrupt, and the STM32 microprocessor as the slave, receiving and sending data via DMA.

[0079] In the communication method described, both the DSP microprocessor and the STM32 microprocessor have sufficient memory allocated. When the DSP microprocessor needs to send data to the STM32 microprocessor, it stores the data packet to be sent in the allocated memory. When the memory is full, it calls the SPI peripheral via an interrupt to send the data to the STM32 microprocessor. The STM32 microprocessor's DMA automatically transfers the data received by the SPI peripheral.

[0080] In the aforementioned communication method, when the STM32 microprocessor needs to send data to the DSP microprocessor, it stores the instruction to be sent in the corresponding memory. The DMA will automatically put the data in the memory into the data register of the SPI peripheral. When the DSP microprocessor sends the instruction, the SPI peripheral will transfer the data to the corresponding register of the DSP microprocessor, and will trigger an interrupt in the DSP, so that the DSP can receive the data from the STM32 microprocessor.

[0081] Step 2: Within the basic framework of SPI bus communication, add a flow control pin for communication. This flow control pin is connected from the STM32 microprocessor to the DSP microprocessor.

[0082] Specifically, Figure 2 This is a schematic diagram of a 5-wire SPI communication method provided in an embodiment of the present invention. It employs a basic four-wire SPI communication link combined with a flow control pin. The STM32 microprocessor flow control pin remains low during controller initialization and normal operation. After receiving a start command from the host computer, the STM32 controls the flow control pin to generate a rising edge, thereby triggering its DSP microprocessor to enter the working state.

[0083] The external main controller between the two processors of the electro-hydraulic servo controller is an STM32 microprocessor. When the host computer controls the operation of the electro-hydraulic servo controller, the STM32 needs to be able to control the running state of the DSP program. The flow control pin provided by this invention can achieve the purpose of STM32 controlling the state of the DSP through changes in its voltage level.

[0084] Step 3: Define a custom communication data message format to facilitate instruction and data exchange between the STM32 microprocessor and the DSP microprocessor. The custom communication data message format is as follows: Figure 3 As shown, it includes: a frame header, a data segment, and a cyclic redundancy check (CRC) field. The meanings and values ​​of each field in the frame header are as follows:

[0085] ACK: 1 bit long, representing the acknowledgment flag, where 1 indicates that the bit is valid and 0 indicates that it is invalid.

[0086] SYN: 1 bit long, representing the send flag, where 1 indicates that the bit is valid and 0 indicates that it is invalid.

[0087] FIN: 1 bit long, representing the end flag, where 1 indicates that the bit is valid and 0 indicates that it is invalid.

[0088] Type: 2 characters long, representing the message type field, where 0b00 indicates a command message type and 0b11 indicates a data message type.

[0089] Scalable command: 3 bits long, reserved bits. This field can be used when the program is upgraded. In data communication messages, it is set to 0.

[0090] DATA: 32 bits in length, stores the data from external sensors collected by the DSP microprocessor when the electro-hydraulic servo controller is running normally, and is set to 0 in the command message type.

[0091] The CRC field is 2 bytes long and is calculated using a cyclic redundancy check method based on CRC16. The calculation range includes the frame header and the DATA part, and the specific parameters are as follows: 1. Check polynomial bit 0x1021; 2. Initial value 0xFFFF; 3. XOR value 0x0000.

[0092] Step 4: Define a custom SPI bus communication state machine. In conjunction with communication data messages, use state machine changes to coordinate the switching of the two microprocessors' operating states. Specifically, Figure 4 This is a schematic diagram of dual-processor communication for an electro-hydraulic servo controller provided in an embodiment of the present invention.

[0093] The STM32 state machine includes four states: Closed, Listen, Data-COM, and Sleep.

[0094] The DSP state machine includes five states: Closed, Listen, Request Send, Data Communication, and Sleep.

[0095] The SPI bus responds according to the pre-set communication data message format and the preset value message during the state machine switching process.

[0096] Specifically, Figures 5-6 This is a flowchart illustrating the state machine switching and SPI communication process of the dual-processor communication method for an electro-hydraulic servo controller provided in an embodiment of the present invention. (Refer to...) Figures 5-6 The STM32 state machine transitions during SPI bus communication include the following steps:

[0097] After the STM32 microprocessor finishes running the initialization program, it waits for instructions from the host computer. When the host computer sends the start-to-work instruction, the STM32 microprocessor generates a rising edge through the control flow pin, and the STM32's state machine changes from the CLOSED state to the LISTEN state.

[0098] The STM32 microprocessor listens for instructions from the DSP microprocessor. When it receives the SYN-SENT instruction from the DSP microprocessor, it replies with a SYN ACK message and changes its status to DATA-COM. Otherwise, it waits for the DSP microprocessor to send the message.

[0099] The STM32 microprocessor and the DSP microprocessor can perform normal data interaction.

[0100] After receiving the sleep command from the host computer, the STM32 microprocessor controller stops outputting external data and sends a sleep command to the DSP microprocessor. After receiving the FIN ACK message from the DSP microprocessor, the STM32 microprocessor state machine enters the SLEEP state.

[0101] After receiving the start command from the host computer, the STM32 microprocessor sends a rising edge to the DSP microprocessor through the flow control pin, and the STM32's state machine changes from the SLEEP state to the LISTEN state.

[0102] While the STM32 microprocessor is waiting for a response from the DSP microprocessor, a timer is started to time 1ms. If no response is received within the timeout period, the STM32 microprocessor will return an error message to the host computer.

[0103] Reference Figure 5 The DSP microprocessor state machine transitions during SPI bus communication include the following steps:

[0104] After the DSP microprocessor is initialized, it enters the LISTEN state from the CLOSED state, waiting to receive instructions from the STM32 microprocessor.

[0105] After the DSP microprocessor receives the rising edge signal from the STM32 microprocessor's flow control pin, the controller begins to acquire and process signals from external sensors. Once the first set of data has been processed, the DSP's state machine enters the SYN-SENT state and sends a SYN-SENT command to the STM32.

[0106] After receiving the SYN ACK message, the DSP microprocessor puts the latest processed data into the transmit buffer, switches the state machine to the DATA-COM state, and begins to actively send the data in the buffer to the STM32 microprocessor.

[0107] After receiving the FIN message from the STM32 microprocessor, the DSP microprocessor sends a FIN ACK and enters the SLEEP state.

[0108] The DSP microprocessor stops acquiring information from external sensors, terminates the execution of other non-essential programs, and enters the LISTEN state.

[0109] The SPI bus communication is initiated by the host. During the state machine switching process and the transmission of command message types, the DSP microprocessor actively sends data packets at 1ms intervals to provide the clock signal required for communication between the two processors.

[0110] During the transmission of the data message types, the DSP microprocessor controls the communication of the SPI bus according to the data transmission rate required by the controller in actual use. To ensure the real-time performance of the signal, the STM32 microprocessor directly discards erroneous data message types and records the number of communication data errors.

[0111] If the number of errors reaches 10 within 10ms, the host computer will control the electro-hydraulic servo controller to enter a sleep state and then restart the operation of the electro-hydraulic servo controller.

[0112] Finally, it should be noted that the above are only specific embodiments of the present invention. Of course, those skilled in the art can make modifications and variations to the present invention. If these modifications and variations fall within the scope of the claims of the present invention and their equivalents, they should be considered as being within the protection scope of the present invention.

Claims

1. A method for implementing SPI bus communication between two processors in an electro-hydraulic servo controller, wherein, The electro-hydraulic servo controller features a dual-processor architecture, comprising an STM32 microprocessor and a DSP microprocessor. The STM32 microprocessor connects to a host computer, while the DSP microprocessor connects to sensors and servo components. The DSP and STM32 microprocessors communicate via an SPI bus, with the DSP acting as the SPI master and the STM32 microprocessor as the SPI slave. A flow control pin is also provided between the two microprocessors. Both the STM32 and DSP microprocessors have their own state machines. The switching of the operating states of the STM32 and DSP microprocessors is coordinated through the transformations between their respective state machines. The controller is characterized by the following steps: Step A1: After receiving the start command from the host computer, the STM32 microprocessor controls the DSP microprocessor to start working through the flow control pin; Step A2: The STM32 microprocessor controls the DSP microprocessor to switch the DSP state machine to the data communication state via command messages; Step A3: The STM32 microprocessor acquires the sensor data collected by the DSP microprocessor; Step A4: The STM32 microprocessor determines whether it has received a stop command from the host computer. If yes, proceed to step A5; otherwise, proceed to step A3. Step A5: The STM32 microprocessor controls the DSP microprocessor to switch the DSP state machine to sleep state via command messages; The STM32 state machine includes four states: Closed; Listening; Data Communication; and Sleep. The STM32 state machine transitions during SPI bus communication include: Step B1: The STM32 microprocessor waits for instructions from the host computer. When the host computer sends an enable instruction, the STM32 microprocessor generates a rising edge through the flow control pin, and the STM32's state machine changes from the CLOSED state to the LISTEN state. Step B2: The STM32 microprocessor listens for instructions from the DSP microprocessor. When it receives the SYN-SENT instruction from the DSP microprocessor, it replies with a SYN ACK message, i.e., requests to send an acknowledgment command; and the status changes to DATA-COM. Otherwise, it waits for the SYN-SENT instruction from the DSP microprocessor. The SYN-SENT instruction is a request to send an instruction. Step B3: The STM32 microprocessor and the DSP microprocessor perform normal data interaction; Step B4: After receiving the sleep command from the host computer, the STM32 microprocessor sends a sleep command to the DSP microprocessor. After receiving the FIN ACK message from the DSP microprocessor, the STM32 microprocessor state machine enters the SLEEP state. The FIN ACK message is the request to end the response command. The DSP state machine includes five states: Closed (CLOSED); Listen (LISTEN); Request sent (SYN-SENT); Data communication (DATA-COM); and Sleep (SLEEP). The DSP microprocessor state machine transitions during SPI bus communication include the following steps: Step C1: After the DSP microprocessor is initialized, it enters the LISTEN state from the CLOSED state and waits to receive instructions from the STM32 microprocessor. Step C2: After the DSP microprocessor receives the rising edge signal from the STM32 microprocessor's flow control pin, the controller begins to acquire signals from external sensors and process them. When the first set of data is processed, the DSP's state machine enters the SYN-SENT state and sends the SYN-SENT instruction to the STM32. Step C3: After receiving the SYN ACK message, the DSP microprocessor sends the latest processed data to the buffer, the state machine switches to the DATA-COM state, and begins to actively send the data in the buffer to the STM32 microprocessor; the SYN ACK message is a request to send an acknowledgment command. Step C4: After receiving the FIN message sent by the STM32 microprocessor, the DSP microprocessor sends a FIN ACK, which is a request to end the response command; it enters the SLEEP state; the DSP microprocessor stops collecting information from external sensors.

2. The method for implementing SPI bus communication between dual processors in an electro-hydraulic servo controller according to claim 1, characterized in that: The instruction and data interaction between the STM32 microprocessor and the DSP microprocessor adopts the following communication data message format, which includes: frame header, data segment and cyclic redundancy check (CRC) field.

3. The method for implementing SPI bus communication between dual processors in an electro-hydraulic servo controller according to claim 2, characterized in that: The frame header includes: a message type field and a command type field; the frame header includes an ACK field, a SYN field, a FIN field, and a Type field; the command type field includes an ACK field, a SYN field, and a FIN field; In the command type field, if both the ACK and SYN fields are 1, it means the command type is a request to send an acknowledgment command, i.e., SYNACK; if both the ACK and FIN fields are 1, it means a request to end the acknowledgment command, i.e., FINACK. The Type field represents the message type, where 0b00 indicates a command message type and 0b11 indicates a data message type. The data segment, denoted by DATA, stores the data from external sensors collected by the DSP microprocessor during normal operation of the electro-hydraulic servo controller. In the command message type, it is set to 0. Cyclic Redundancy Check (CRC) fields provide a method for checking the validity of communication data packets.

4. The method for implementing SPI bus communication between dual processors in an electro-hydraulic servo controller according to claim 3, characterized in that: The Cyclic Redundancy Check (CRC) field is calculated using a CRC16-based CRC16 method. The calculation scope includes the frame header and DATA portion, with the following parameters:

1. Check polynomial bit 0x1021; 2. Initial value 0xFFFF; 3. XOR value 0x0000.

5. The method for implementing SPI bus communication between dual processors in an electro-hydraulic servo controller according to claim 1, characterized in that: The DSP microprocessor acts as the SPI communication master, sending and receiving data via interrupts; the STM32 microprocessor acts as the SPI communication slave, sending and receiving data using DMA-based SPI communication.

6. The method for implementing SPI bus communication between dual processors in an electro-hydraulic servo controller according to claim 1, characterized in that: The STM32 microprocessor controls the high and low levels of the flow control pin; after confirming that it has received the start command from the host computer, the STM32 microprocessor switches the state of the flow control pin from low to high and sends communication status indication information to the DSP microprocessor to confirm that it has started working.