Abstract: In view of the shortcomings of master-slave communication in single-chip multi-computer systems, the use of CAN controllers to implement peer-to-peer communication in single-chip multi-computer systems was proposed, and a detailed analysis of its hardware composition principles and communication program design was made.
Keywords: Single-chip microcomputer, multi-machine system, "peer-to-peer" communication, controller area network (CAN)
Many articles and related books have introduced the multi-machine communication of single-chip microcomputer, but most of them are "master-slave" in terms of multi-machine communication method. This communication method limits the function of single-chip microcomputer and its wide application. Although the literature [1] uses clever second hardware means to achieve "peer-to-peer" communication between multiple microcontrollers, the communication method is still essentially a "master-slave" type. This article introduces a single-chip multi-machine system based on CAN controller, which essentially realizes direct communication between any two machines, thereby overcoming the shortcomings of "master-slave" multi-machine communication.
1 Introduction to CAN technology
CAN (Controller Area Net) is a controller area network, which is a network mainly used for monitoring and controlling various processes (equipment). CAN was originally designed by the German BOSCH company for automotive monitoring and control systems. Because CAN has excellent characteristics and extremely high reliability, it is particularly suitable for the interconnection of monitoring equipment in industrial processes. Therefore, it has attracted more and more attention from the industry. Specifically speaking, CAN has the following characteristics:
(1) CAN can work in multi-master mode. Any node on the network can actively send information to other nodes on the network at any time, regardless of master and slave, and the communication method is flexible;
(2) CAN can transmit and receive data in point-to-point, point-to-multipoint (group) and global broadcast modes;
(3) Node information on the CAN network can be divided into different priorities, which can meet different real-time requirements;
(4) CAN uses non-destructive bus secondary technology. When two nodes are sending data to the network, the node with a lower priority actively stops sending data, while the node with a higher priority can continue to transmit data without being affected, which greatly saves the bus arbitration conflict time. When the network load is very high, In severe cases, network paralysis will not occur;
(5) The maximum direct communication distance of CAN can be up to 10km (the rate is less than 5kbps), and the maximum communication rate can be up to 1Mkbps (the longest distance is 40m at this time).
2 Software and hardware design of peer-to-peer microcontroller system based on CAN controller
2.1 System hardware design
2.1.1 System composition principle and communication process
The so-called peer-to-peer communication means that any node in a single-chip multi-machine system can actively exchange data directly with other nodes without going through a third party. From this perspective, the composition of the single-chip multi-machine system we designed based on CAN control is shown in Figure 1.
Each node in the system is composed of a microcontroller, a CAN controller, and a CAN transmitter. The microcontroller is mainly used for system calculation and information processing functions; the CAN controller is mainly used for system communication; the CAN transceiver is mainly used to enhance the system's driving capabilities. The sending process of the system is: after the microcontroller processes the information transmitted from the peripheral device or other nodes, it writes it into the sending buffer of the CAN controller according to the format specified by the CAN specification, and starts the sending command to send the data to the CAN bus. Above; the receiving process is: the CAN controller automatically receives data from the CAN bus, stores it in the CAN receiving buffer after filtering, and sends an interrupt request to the microcontroller. At this time, the microcontroller can read the data to be received from the CAN receiving buffer. .
2.1.2 Examples of hardware design of system nodes
Figure 2 is the hardware circuit diagram of the parts related to this article in the developed low-cost agricultural temperature control system.
The design should pay attention to the following points:
(1) There is a 120 Ω resistor at both ends of the bus, which plays a very important role in matching the bus impedance. Otherwise, the anti-interference and reliability of data communication will be greatly reduced, and communication will even become impossible.
(2) In order to synchronize the timing between CAN and the microcontroller, a CAN controller is generally used to provide a clock signal to the microcontroller. At this time, the clock signal should be connected to the XTALI pin for the CHMOS type microcontroller and the XTAL2 pin for the HMOS type microcontroller.
(3) If the CAN transceiver buffer uses integrated components, the RX1 pin should be grounded and the CDR bit should be set to logic 1. Otherwise, the RXI pin potential must be maintained above 2.5V, and the CBP bit in the CDR register should be set to logic 0 to form the logic level required by CAN.
2.2 System software design
The key to system software design is the design of communication programs. Communication software consists of three parts: Churuhua program, sending program, and receiving program. Since any node in the system can actively communicate with other nodes at any time, the communication procedures of each node are the same.
2.2.1 Initialization procedure
The initialization program mainly determines the working mode of the CAN controller by writing control words to the register memory in the CAN controller control section. There are three ways to enter the initialization harmony: one is a power-on reset; the other is a hardware reset; the third is a software reset, that is, by sending a reset request to the CAN controller during operation and setting the reset request bit to 1. During reset, the registers that must be initialized are: MR (PeliCAN mode) mode register, CDR time division register, ACR receiving code register, MAR mask register, BTR bus timing register, OCR output control register. Note that these registers are write-accessible only during reset. Therefore, before initializing these registers, you must ensure that the system enters the reset state. The flow chart of the initialization program is shown in Figure 3.
2.2.2 Sending program
Sending information from the CAN controller to the CAN bus is done automatically by the CAN miner. The sending program only needs to send the sent information frame to the CAN sending buffer and start the sending command. The sending program can be sent in query mode or interrupt mode, which is relatively simple. Here we only discuss the design of the interrupt mode sending program. For the interrupt mode, the sending program is divided into two parts: one is the main program; the other is the interrupt service program. The main program is mainly used to control the sending of information and temporarily store the sent information in the temporary storage area when the sending buffer is full; the interrupt sending program is responsible for sending the temporary information in the temporary storage area. The flow charts of the two are shown in Figure 4 and Figure 5 respectively.
2.2.3 Receiving procedure
The transfer of information from the CAN bus to the CAN receive buffer is automatically done by the CAN controller. The receiving program only needs to read the information to be received from the receiving buffer. The receiving program can also use the query mode or the interrupt mode. The two are equally complex and simple. Here, the flow chart of the receiving program is given using the query mode as an example (see Figure 6).
The flow charts given above are general flow charts. The use should be specific based on the actual project, and there may be emergency handling in the sending program and data overload in the receiving program. Due to space limitations, it will not be discussed here.
The single-chip multi-computer communication system based on CAN controller is suitable for small and medium-sized distributed control systems due to its high communication efficiency, strong anti-interference and long transmission distance. And due to its low price, it has extensive applications in the field of low-cost automation. application space.
Previous article:Frequency hopping communication and its applications
Next article:Circuit protection issues in communication design
- Popular Resources
- Popular amplifiers
- Molex leverages SAP solutions to drive smart supply chain collaboration
- Pickering Launches New Future-Proof PXIe Single-Slot Controller for High-Performance Test and Measurement Applications
- CGD and Qorvo to jointly revolutionize motor control solutions
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Nidec Intelligent Motion is the first to launch an electric clutch ECU for two-wheeled vehicles
- Bosch and Tsinghua University renew cooperation agreement on artificial intelligence research to jointly promote the development of artificial intelligence in the industrial field
- GigaDevice unveils new MCU products, deeply unlocking industrial application scenarios with diversified products and solutions
- Advantech: Investing in Edge AI Innovation to Drive an Intelligent Future
- CGD and QORVO will revolutionize motor control solutions
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Linux kernel startup process - Xunwei IMX6ULL development board (I)
- Analysis of the whole process of C language compilation
- How to replace potentiometers with programmable devices in analog circuit design?
- BMW Cooling System and Electric Coolant Pump Components (Electronic Water Pump) Functional Characteristics and Standards
- Inline instructions for TMS320C66x study notes
- Electric mask solutions
- 【Project Source Code】FPGA-based Ethernet design tutorial and program source code
- [ESP32-Audio-Kit Audio Development Board Review] Part 3: Comments on the Installation of the Development Environment
- Caibo International Customer Service Life Quotes
- Are there any good high current sensor chips now?