Communication of peer-to-peer microcontroller multi-computer system based on CAN controller

Publisher:csydtcLatest update time:2006-05-07 Source: 电子技术应用 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

    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.

Reference address:Communication of peer-to-peer microcontroller multi-computer system based on CAN controller

Previous article:Frequency hopping communication and its applications
Next article:Circuit protection issues in communication design

Latest Industrial Control Articles
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号