CAN bus master station management module based on STM32

Through the STM32-based CAN bus master station management module, the ring buffer unit and register monitoring are used to solve the problem of slave station offline misjudgment in CAN bus communication, and achieve more accurate slave station status judgment and stable communication.

CN223437088UActive Publication Date: 2025-10-14天津瑞源电气有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202422135770.9
Authority / Receiving Office
CN · China
Patent Type
Utility models(China)
Current Assignee / Owner
Filing Date
2024-09-02
Publication Date
2025-10-14
Estimated Expiration
2034-09-02

AI Technical Summary

Technical Problem

In the prior art, the mailbox capacity in CAN bus communication is limited, resulting in a high rate of misjudgment of slave offline status, which affects the accuracy of communication between the master and slave stations.

Method used

The CAN bus master station management module based on STM32 is adopted, and the ring buffer unit and register monitoring are used. The messages are managed by the ring first-in-first-out and first-in-last-out buffer units. The serial communication is realized in combination with the SP3232EEN chip to avoid offline misjudgment.

Benefits of technology

The accuracy of slave offline judgment is improved, misjudgment is reduced, and the stability and reliability of communication between the master and slave stations are enhanced.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN223437088U_ABST
    Figure CN223437088U_ABST
Patent Text Reader

Abstract

The utility model provides a CAN bus master station management module based on STM32, comprising an MCU chip used for managing CAN communication, generating slave station communication sending messages, processing received slave station communication receiving messages, sending data to slave station nodes in a physical layer and a data link layer, and receiving slave node return data; the sending mailbox comprises a sending message annular first-in first-out cache unit, the sending message annular cache unit of the slave station node is divided into a preset first number of subunits, and each subunit stores a sending message; the second annular cache first-in-second-out unit is divided into a preset second number of sub-units, and each sub-unit stores a sending message in each sub-unit in the annular cache unit for sending the message by the first slave station node; and the MCU chip is electrically connected with the sending mailbox. Different processing signals may be returned for different situations. And communication offline misjudgment of the slave nodes is avoided.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The utility model belongs to CAN bus technical field especially, it is a kind of CAN bus master station management module based on STM32. BACKGROUND

[0002] With the rapid development of power electronics technology, the application of can bus is more and more widely, and at present, the use form of can bus is the CAN+CANopen communication protocol integrated in MCU to realize the related functions of embedded system local area network. CAN bus protocol defines the physical layer and data link layer of ISO seven-layer communication protocol model, and its specific implementation has been solidified into CAN bus control chip, without software implementation. CANopen protocol is an application layer protocol based on can bus protocol, which focuses on defining the content and object type of object.

[0003] The communication between the master station and the slave station can be realized by using can bus, and the communication situation can be managed. In the prior art, the communication situation of the master station and the slave station can be judged by using the mailbox configuration in CAN bus, and then the offline situation of the slave station can be judged. In the process of realizing the present application, the inventor finds the following technical problems: because the mailbox capacity is limited, when the message sending is unsuccessful, the slave node offline is judged by corresponding register flag bit, this kind of way will produce a large number of offline misjudgment, and then affect the communication between the master station and the slave station. CONTENT OF UTILITY MODEL

[0004] Therefore, the utility model aims at providing a kind of CAN bus master station management module based on STM32 to solve the technical problem of higher error rate of slave station offline state in prior art by using mailbox.

[0005] To achieve the above-mentioned purpose, the technical scheme of the utility model is as follows:

[0006] A kind of CAN bus master station management module based on STM32, comprising:

[0007] MCU chip, the MCU chip is used to manage CAN communication, generates slave station communication sending message, and processes received slave station communication receiving message, and sends data to slave node in physical layer and data link layer, and receives data returned from node;

[0008] Sending mailbox, the sending mailbox includes:

[0009] Sending message ring first-in first-out cache unit, the slave node sending message ring cache unit is divided into a preset first quantity of subunits, and each subunit respectively stores a sending message;

[0010] The second ring buffer FIFO unit is divided into a preset second number of sub-units, and each sub-unit respectively stores the sending message in each sub-unit in the ring buffer FIFO unit of the first slave node.

[0011] The MCU chip is electrically connected with the sending mailbox.

[0012] Further, the MCU chip is an STM32 chip, and a bxcan module in the STM32 chip serves as a physical layer and a data link layer.

[0013] Further, the bxcan module comprises:

[0014] The CAN sending state register is used for sending mailbox monitoring and sending state monitoring.

[0015] The receiving register monitors the number of message suspensions in the receiving mailbox.

[0016] Further, the device further comprises a CAN transceiver chip, which is electrically connected with the STM32 chip.

[0017] Further, the CAN transceiver chip is a TJA1050T chip, a txd pin of the TJA1050T chip is electrically connected with a CAN tx pin of the STM32 chip, and a rxd pin of the TJA1050T chip is electrically connected with a CAN rx pin of the STM32 chip.

[0018] Further, the device further comprises:

[0019] An SP3232EEN chip, which is electrically connected with the STM32 chip.

[0020] Further, a PA9 pin of the STM chip is electrically connected with a USART1_TX pin of USART1 of the SP3232EEN chip, and a PA10 pin is electrically connected with a USART1_RX pin of USART1.

[0021] Compared with the prior art, the CAN bus master station management module based on an STM32 has the following advantages:

[0022] (1) The CAN bus master station management module based on STM32 described in the present invention is configured by setting an MCU chip, wherein the MCU chip is used to manage CAN communication, generate slave station communication transmission messages, process received slave station communication reception messages, and send data to the slave station node at the physical layer and data link layer, and receive data returned from the slave node; a sending mailbox, wherein the sending mailbox includes: a sending message ring first-in-first-out cache unit, wherein the slave station node sending message ring cache unit is divided into a preset first number of sub-units, each sub-unit stores a sending message respectively; a ring cache first-in-last-out unit, wherein the second ring cache first-in-last-out unit is divided into a preset second number of sub-units, each sub-unit stores the sending message in each sub-unit of the first slave station node sending message ring cache unit respectively; the MCU chip is electrically connected to the sending mailbox. Without the need for software modification, by using the ring cache unit as a mailbox, multiple unsuccessful messages sent to the slave station can be stored. By utilizing the buffering function of the ring cache unit, the sending conditions of multiple messages can be judged, and different processing signals can be returned for different conditions. Avoids incorrect judgment of slave node communication offline.

[0023] (2) The STM32-based CAN bus master management module described in the present invention can communicate with the CAN bus slave station using serial communication when the CAN bus slave station is offline by additionally setting up the SP3232EEN chip. BRIEF DESCRIPTION OF THE DRAWINGS

[0024] The accompanying drawings, which constitute part of the present invention, are intended to provide a further understanding of the present invention. The exemplary embodiments of the present invention and their descriptions are intended to explain the present invention and do not constitute an improper limitation of the present invention. In the accompanying drawings:

[0025] Figure 1 This is a schematic diagram of the structure of the STM32-based CAN bus master management module according to an embodiment of the present invention;

[0026] Figure 2 This is a schematic diagram of the connection of the CAN transceiver chip in the STM32-based CAN bus master management module according to an embodiment of the present invention;

[0027] Figure 3 This is a schematic diagram of the connection of the SP3232EEN chip in the STM32-based CAN bus master management module described in an embodiment of the present invention. DETAILED DESCRIPTION

[0028] It should be noted that, in the absence of conflict, the embodiments of the present invention and the features therein can be combined with each other.

[0029] In the description of the utility model, it is necessary to understand that the orientation or positional relationship indicated by the terms "center", "longitudinal", "transverse", "upper", "lower", "front", "rear", "left", "right", "vertical", "horizontal", "top", "bottom", "inner", "outer" and the like is the orientation or positional relationship shown based on the drawings, and is only for the convenience of describing the utility model and simplifying the description, and therefore cannot be understood as indicating or implying that the devices or elements indicated must have a particular orientation, be constructed and operated in a particular orientation, and therefore cannot be understood as limiting the utility model. In addition, the terms "first", "second" and the like are only for the purpose of description, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of the technical features indicated. Therefore, the features limited by "first", "second" and the like can explicitly or implicitly include one or more features. In the description of the utility model, unless otherwise specified, the meaning of "a plurality of" is two or more.

[0030] In the description of the utility model, it should be explained that, unless otherwise explicitly specified and limited, the terms "mounting", "connection", "connection" should be understood broadly, for example, it can be fixedly connected, or it can be detachably connected, or integrally connected, it can be mechanically connected, or it can be electrically connected, it can be directly connected, or it can be indirectly connected through an intermediate medium, it can be the communication inside two elements. For ordinary skilled in the art, the specific meaning of the above terms in the utility model can be understood through specific circumstances.

[0031] The utility model will be described in detail below with reference to the drawings and in combination with the embodiments.

[0032] Figure 1 The structure diagram of the CAN bus master station management module based on STM32 described in the embodiments of the utility model, see Figure 1 The CAN bus master station management module based on STM32 can include: MCU chip, the MCU chip is used for managing CAN communication, generating slave station communication sending message, and processing the received slave station communication receiving message, and sending data to slave node at physical layer and data link layer, and receiving data returned from node; Sending mailbox, the sending mailbox includes: sending message ring first-in first-out cache unit, the slave node sending message ring cache unit is divided into a preset first number of subunits, each subunit respectively stores a sending message; Ring cache first-in last-out unit, the second ring cache first-in last-out unit is divided into a preset second number of subunits, each subunit respectively stores the sending message in each subunit in the first slave node sending message ring cache unit;The MCU chip is electrically connected with the sending mailbox.

[0033] In the prior art, when the master station uses the CAN bus to send a message to the slave station, in the STM32 CAN controller, one mailbox, data length and send data are selected each time, and the TXRQ bit of CAN_TIxR is set to 1. When requesting to send, the mailbox wait is made the highest priority and waits for the bus to be idle for sending.

[0034] If a slave is offline, unsuccessful messages are saved in a mailbox and a flag is written to the corresponding register. This flag can be used to determine if there are unsuccessful messages and, therefore, whether the slave is offline. The specific implementation is already built into the CAN bus controller chip, eliminating the need for software implementation.

[0035] Since mailboxes can usually only store a small number of messages, if there is a communication delay within a short period of time, the mailbox will quickly fill up, causing a false judgment that the slave is offline. At the same time, it is not conducive to the master station management module to make adjustments.

[0036] Therefore, in this embodiment, the mailbox is adjusted. For example, the mailbox can adopt the form of a ring-shaped FIFO buffer unit and a ring-shaped FIFO buffer unit. The ring-shaped FIFO buffer unit represents a fixed-size, end-to-end buffer data structure suitable for caching data streams. Because it uses a FIFO method, messages to be sent to the slave station can be sent in sequence.

[0037] By using the message ring FIFO buffer unit, the number of slave messages to be sent can be adjusted, thereby avoiding the probability of false judgment of slave offline due to a small number of messages stored in the mailbox.

[0038] Furthermore, a ring cache first-in-last-out unit can be provided, which can be connected to the message ring cache unit to store the uncovered messages in the ring cache unit. At the same time, in order to avoid excessive delays and the sent messages not matching the current situation, a first-in-last-out method is adopted.

[0039] Furthermore, this type of mailbox can handle the storage capacity of the two message units differently. For example, if the ring FIFO buffer overflows, the register flag is used to reduce the message transmission frequency. If the ring FIFO buffer is full, the register flag is used to determine that the slave is offline. This makes it easier for users to accurately understand the status of the slave.

[0040] The CAN bus master station management module based on STM32 described in the present utility model is provided with an MCU chip, the MCU chip is used to manage CAN communication, generate slave communication transmission messages, and process the received slave communication reception messages, and send data to the slave node at the physical layer and data link layer, and receive the slave node return data; a sending mailbox, the sending mailbox includes: a sending message ring first-in-first-out buffer unit, the slave node sending message ring buffer unit is divided into a preset first number of sub-units, each sub-unit stores a sending message respectively; a ring buffer first-in-last-out unit, the second ring buffer first-in-last-out unit is divided into a preset second number of sub-units, each sub-unit stores the sending message in each sub-unit of the first slave node sending message ring buffer unit respectively; the MCU chip is electrically connected to the sending mailbox. Without the need for software modification, by using the ring buffer unit as a mailbox, multiple unsuccessful messages sent to the slave station can be stored. By utilizing the buffering function of the ring buffer unit, multiple message sending situations can be judged, and different processing signals can be returned for different situations. Avoiding the judgment of slave node communication offline errors.

[0041] Figure 2 This is a schematic diagram of the connection of the CAN transceiver chip in the STM32-based CAN bus master management module according to an embodiment of the present invention; Figure 3 This is a schematic diagram of the connection of the SP3232EEN chip in the STM32-based CAN bus master management module according to the embodiment of the present invention. Figure 2 and Figure 3 , a CAN transceiver chip, the CAN transceiver chip is electrically connected to the STM32 chip. Further, the CAN transceiver chip is a TJA1050T chip, the TXD pin of the TJA1050T chip is electrically connected to the CAN TX pin of the STM32 chip, and the RXD pin of the TJA1050T chip is electrically connected to the CAN RX pin of the STM32 chip. CAN communication between the master station and the slave station is implemented using the CAN transceiver chip.

[0042] In addition, in the embodiment, the STM32-based CAN bus master management module further comprises an SP3232EEN chip, which is electrically connected with the STM32 chip. A PA9 pin of the STM chip is electrically connected with a USART1_TX pin of a USART1 of the SP3232EEN chip, and a PA10 pin is electrically connected with a USART1_RX pin of the USART1. The SP3232EEN chip is a serial communication module. By using the above setting, when communication failure occurs between the can master station and the slave station, the STM32 chip can still maintain direct communication between the two through the serial port. When the can bus slave station is offline, the serial communication mode can be used to communicate with the slave station.

[0043] The above merely provides the preferred embodiments of the present application, and is not intended to limit the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.

Claims

1. A CAN bus master station management module based on STM32, characterized in that: include: MCU chip, which is used to manage CAN communication, generate slave communication transmission messages, process received slave communication reception messages, send data to slave nodes at the physical layer and data link layer, and receive return data from the slave nodes; Send mailbox, the sending mailbox includes: a sending message annular first-in-first-out buffer unit, wherein the sending message annular buffer unit is divided into a preset first number of subunits, each subunit storing a sending message; A ring buffer first-in last-out unit, wherein the ring buffer first-in last-out unit is divided into a preset second number of subunits, each subunit respectively storing a send message in each subunit of the ring buffer unit of the first slave node; The MCU chip is electrically connected to the sending mailbox.

2. The CAN bus master station management module based on STM32 according to claim 1, wherein The MCU chip is an STM32 chip, and the bxcan module in the STM32 chip serves as the physical layer and data link layer.

3. The CAN bus master station management module based on STM32 according to claim 2, wherein The bxcan module includes: The CAN send status register is used to monitor the send mailbox and send status; The receive register monitors the number of pending messages in the receive mailbox.

4. The CAN bus master station management module based on STM32 according to claim 3, wherein The STM32-based CAN bus master station management module also includes: a CAN transceiver chip, and the CAN transceiver chip is electrically connected to the STM32 chip.

5. The CAN bus master station management module based on STM32 according to claim 4, wherein The CAN transceiver chip is a TJA1050T chip, the txd pin of the TJA1050T chip is electrically connected to the CAN tx pin of the STM32 chip, and the rxd pin of the TJA1050T chip is electrically connected to the CAN rx pin of the STM32 chip.

6. The CAN bus master station management module based on STM32 according to claim 4, wherein The STM32-based CAN bus master station management module also includes: SP3232EEN chip, the SP3232EEN chip is electrically connected to the STM32 chip.

7. The CAN bus master station management module based on STM32 according to claim 6, characterized in that, The PA9 pin of the STM32 chip is electrically connected to the USART1_TX pin of the USART1 of the SP3232EEN chip, and the PA10 pin is electrically connected to the USART1_RX pin of the USART1.