Design of single-line CAN bus isolation repeater based on STM32 microcontroller

Publisher:塞上老马Latest update time:2018-03-19 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

    Aiming at some limiting factors of CAN bus in field application and the problems existing in CAN bus networking control of hydraulic support electro-hydraulic control system in coal mine, this paper proposes a single-line CAN bus isolation repeater based on STMicroelectronics STM32 microcontroller. The characteristics of dual bxCAN controller integrated in STM32F105 series microcontroller and single-line CAN transceiver of Freescale MC33879 are fully utilized to form a soft repeater. Practice has proved that this design effectively solves the problems of multi-point power supply, network scale limitation and electromagnetic compatibility, and has great significance for improving the safety and efficiency of coal mine automation production.

    CAN bus is a multi-master serial communication bus with excellent stability, real-time performance, remote communication capability and super hardware CRC error correction. The application of CAN bus technology is no longer limited to the automotive industry, but has expanded to energy, manufacturing and other industries, and is recognized as one of the most promising field buses. Therefore, CAN bus has been increasingly used in various systems in coal mines. Due to the limitation of CAN transceiver, the communication distance of CAN bus and the number of nodes in the network are limited to 10 km and 110 nodes respectively. However, in the coal mine field equipment system with many nodes, long distance and complex power supply system, CAN bus repeater is needed to expand the CAN bus network.
    CAN repeater is one of the key technical equipment for system networking. The use of repeater can increase the number of nodes and communication distance of the network, and can connect two CAN bus networks with different baud rates, greatly expanding its scope of use. In view of this, a single-line CAN bus isolation repeater based on STM32 is designed, and it will be applied to the hydraulic support electro-hydraulic control system to realize the communication between hydraulic supports and between hydraulic supports and upper computer monitoring system.

1 Overall system solution
    There are generally two design methods for CAN bus repeater: one is to use hard relay mode, that is, only the combination of gate circuits and some discrete devices is used to design the circuit, but the forwarding efficiency is not high; the other is to use soft relay mode, that is, the CPU is used to receive and forward the data on both sides of the CAN bus. Although the structure of this scheme is complex, the forwarding efficiency is high. The data on both sides are received by the CPU and then forwarded to the other side. In addition to the program filtering and self-diagnosis functions, the soft repeater can also realize the connection of network segments with different speeds to meet the actual application requirements; therefore, this design adopts the soft relay method.

a.JPG

    2 Hardware Design
    2.1 Main Control Circuit Design
    The hardware circuit of the repeater designed for the harsh industrial environment of coal mines must not only be stable and reliable, but also have low power consumption. The CPU of the repeater adopts the STM32F105 series microcontroller based on the Cortex-M3 core of ST. The STM32F105 series is specially designed for fast and simple programming and can be used for highly integrated and low-power industrial applications. The operating frequency of the STM32F105 series can reach 72 MHz, and the power consumption is much lower than that of microcontrollers with the same performance. In addition, it also has a 128KB on-chip FLASH program memory with in-system programming (ISP), which brings great flexibility for operations such as data storage and firmware upgrades. The STM32F105 series integrates two independent CAN controllers, which simplifies the hardware circuit design of the repeater; the acceptance filter of its CAN controller has a fast hardware search algorithm, supports a large number of CAN identifiers, and allows clear definition and group definition of 11-bit and 29-bit CAN identifiers, simplifying the software design and operation burden of the system.
2.2 Communication circuit design
    The CAN bus interface circuit is shown in Figure 2. The CAN transceiver in the figure uses the single-line CAN transceiver MC33897. It is a single-bus CAN bus transceiver chip launched by Freescale for a ground loop, mainly used in multi-channel transmission applications. It provides a single-line physical interface for data transmission between CAN bus controllers, that is, compared with traditional CAN bus transceivers, it only needs one signal line to complete CAN bus communication, which saves communication costs for mutual communication between nodes and facilitates system installation and subsequent maintenance. In addition, the CAN bus interface and the CPU are isolated by dual-channel magnetic coupling ADuM1201. Compared with high-speed optical coupling, magnetic coupling has small delay and low power consumption. This design method solves the problem of different brackets using different power supplies and signals with different grounds, and improves the anti-interference ability.

b.JPG


  3 Software Design
  3.1 Initialization Subroutine
  The initialization of the CAN controller of STM32 is directly related to whether the CAN controller can work properly. The initialization of the CAN controller of STM32 mainly includes the initialization of the CAN basic unit and the filter. Because ST has launched a set of firmware libraries for STM32, it is only necessary to make corresponding settings at the beginning of the program. The key link in this initialization subroutine is to set the baud rate of CAN. The baud rate calculation formula in the STM32 data sheet is as follows:     c.JPG
    where tq=(BRP[9:0]+1)xtPCLK. As in the above CAN unit initialization subroutine: tBS1=tq×(TS1[3:0]+1), tBS2=tqx(TS2[2:0]+1), BRP[9:0], TS1[3:0] and TS2[2:0] are all set in the CAN_BTR register, and the CAN clock of STM32 is provided by APB1. Assuming the system clock is 72 MHz, APB1 is the 9-frequency division of the system clock, combined with the initialization subroutine, BRP[9:0]=0, TS1[3:0]=7, TS2[2:0]=6, and the baud rate can be calculated by substituting it into the baud rate calculation formula to obtain a baud rate of 500Kb/s. In this repeater, the filter of the CAN controller is set to work in the mask bit mode, and any bit of the identifier is processed according to the principle of must match or don't care. In the repeater, since it is necessary to forward the data on all buses, the filter does not need to be set in detail, and it only needs to be set to receive data with any ID number.
3.2 Data forwarding subroutine
    The task of the repeater is essentially to realize the forwarding of messages. The STM32F105 integrates a dual bxCAN controller, which includes 3 sending mailboxes and 2 3-level deep FIFOs. Combined with the characteristics of the STM32 F105, a dual FIFO forwarding mechanism is adopted, and its principle is shown in Figure 3. According to Figure 3, when the STM32F105 receives a new message, it is processed by the data processing module and, under the management of the data forwarding process, the receive FIFO buffers of the two bxCAN controllers are monitored. If one buffer is not empty, it is forwarded to the other.

d.JPG

    
    The process of sending a message by STM32F105 is as follows: the application selects an empty sending mailbox; sets the identifier, data length and data to be sent; then sets the TXRQ position of the CAN_TIxR register to 1 to request sending. After the TXRQ position is set to 1, the mailbox is no longer an empty mailbox; once the mailbox is no longer empty, the software no longer has write permission to the mailbox register. After the TXRQ position is set to 1, the mailbox immediately enters the registered state and waits to become the highest priority mailbox. Once the mailbox becomes the highest priority mailbox, its state changes to the scheduled sending state. When the CAN bus enters the idle state, the message in the scheduled sending mailbox is immediately sent. After the message in the mailbox is successfully sent, it immediately becomes an empty mailbox; the hardware correspondingly sets the RQCP and TXOK positions of the CAN_TSR register to 1, indicating a successful transmission.
    In order to improve the real-time data transmission of the repeater, the reception of CAN messages adopts the interrupt mode. Therefore, during the CAN initialization process, the CAN1 and CAN2 peripheral interrupts should be enabled, and their corresponding interrupt vector tables and corresponding interrupt levels should be set. The data receiving module process is shown in Figure 4.

e.JPG

    
    In addition, assuming that the total time for data sent from point A on the CAN bus is t, the shortest time for the data to be received at point B on the other side of the soft repeater is t. When the bus rate is not large and the timing requirements for each bus device are not high, this time can be ignored. However, in CAN bus systems where data is frequently exchanged between some nodes, attention must be paid to this issue and its impact on the system must be minimized as much as possible.

  4 Conclusion
    The CAN bus repeater makes full use of the internal integrated dual bxCAN controller to simplify the design of the hardware circuit, and the rich firmware library functions shorten the development cycle. Practice shows that the single-line CAN bus isolation repeater has completed various design indicators, meets the requirements of the project, and can effectively complete data forwarding and network expansion in the hydraulic support electro-hydraulic control system, and has high practical value.


Keywords:STM32 Reference address:Design of single-line CAN bus isolation repeater based on STM32 microcontroller

Previous article:Hardware circuit connection diagram and software program design based on STM32 processor
Next article:Design of closed-loop tension control system based on STM32

Recommended ReadingLatest update time:2024-11-15 15:35

A brief analysis of STM32 startup mode
I didn't quite understand the serial port download in the Zhengdian Atomic Development Guide, so I simply read the manual. STM32 can be divided into three boot modes: 1: boot from main Flash; 2: boot from system memory (actually ROM); 3: boot from embedded SRAM (actually regular RAM). The three modes are determined
[Microcontroller]
A brief analysis of STM32 startup mode
STM32TIM module generates PWM
 This is the PWM output mode of STM32. The TIM1 module of STM32 is an enhanced timer module, which is born for motor control. It can generate 3 groups of 6 PWMs. At the same time, each group of 2 PWMs is complementary and can have a dead zone, which can be used to drive the H-bridge.   The following code is an example
[Microcontroller]
STM32 103 USART
Open the corresponding GPIO clock multiplexing clock USART clock RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO | RCC_APB2Periph_USART1,  ENABLE ); USART2     RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,  ENABLE ); USART3 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,  ENABLE );   RCC_A
[Microcontroller]
Summary of learning STM32 SD card
Since I am also using SD cards, I have encountered some problems in the process of using them. The following is the experience of zxb1717, an expert on the EDN forum, I hope it can help you Key points for debugging: 1. When powering on, the delay should be long enough to give the SD card a preparation process. In my
[Microcontroller]
About stm32 HardFault_Handler exception handling crash
When developing the system, the HardFault_Handler hardware exception occurs, that is, the system crashes. Especially for a system that calls the OS, the program volume is large, and the stack overflow and array overflow detection are detected. After searching for a long time and finding nothing, I probably want to die
[Microcontroller]
About stm32 HardFault_Handler exception handling crash
STM32 I2C_EEPROM read and write
EEPROM data organization:  EEPROM devices divide their storage matrix into pages:  The AT24C02 EEPROM is divided into 32 pages, and each page can store 8 bytes of data. If more than 8 bytes are written to the same page, the excess will be written at the starting address of the page (that is, the part written at the b
[Microcontroller]
STM32 FSMC bus multiplexing debugging notes
The following points are mainly encountered when debugging the FSMC bus multiplexing mode: 1. Register configuration, first of all, pay attention to enable address data multiplexing, and secondly, select FSMC_MemoryType_NOR for the memory type, otherwise the NADV signal will not appear.     FSMC_NORSRAMInitStructure
[Microcontroller]
STM32 FSMC bus multiplexing debugging notes
STM32 USB software transplantation precautions and hardware wiring precautions
I transplanted a custom HID USB program to the STM32 development board and it worked successfully, but it didn't work on the board I made recently (using F103C8T6). After several debugging, I finally found the problem. Here is a summary: 1. Make sure the USB clock is 48MHZ;  Use PLL as system clock SCLK; USB clock
[Microcontroller]
Latest Microcontroller Articles
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
    Since development under LINUX is still quite troublesome, is there a more convenient and simple development method under WINDOWS? The answer is yes. Of course, it is not a development tool like ADS, because it ...
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
  • Learn ARM development(18)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号