Application scheme and analysis based on CAN bus and MCU

Application scheme and analysis based on CAN bus and MCU

CAN is a field bus that is widely used in the world. MCS96 series microcontrollers are embedded controllers that are widely used in the industry. The 87C196CA microcontroller core itself has a CAN controller, which supports standard and extended information frames. That is to follow the CAN2.0A and CAN2.0B protocols. The CAN bus thus formed supports distributed control and real-time control, and its serial communication mode is flexible and reliable, and the transmission distance is long.

Authors: Zhang Lin, Li Lanchong

1 Introduction

CAN is a field bus that is widely used in the world. MCS96 series microcontrollers are embedded controllers that are widely used in the industry. The 87C196CA microcontroller core itself has a CAN controller, which supports standard and extended information frames. That is to follow the CAN2.0A and CAN2.0B protocols. The CAN bus thus formed supports distributed control and real-time control, and its serial communication mode is flexible and reliable, and the transmission distance is long. Because CAN bus has the advantages of high communication rate, high working reliability, strong anti-interference ability, convenient network connection and high cost performance, it has been widely used in automotive engine control components, automotive anti-skid systems, industrial automation, machine tools, elevator control and other fields. wider application.

2 Hardware configuration

2. 1 CAN bus connection

When two 87C196 single-chip microcomputers based on CAN bus are connected to the network, the CAN receiving and sending lines of the single-chip computer are respectively connected to the CAN bus through the PCA82C250 CAN bus transceiver to form a multi-microcontroller CAN bus connection. The communication medium can be twisted pair, coaxial cable or optical fiber, and its bus connection is shown in Figure 1.

Application scheme and analysis based on CAN bus and MCU
Figure 1 CAN bus connection

The maximum communication rate of this network is 1Mbit/s, and when the transmission rate is 5Kbit/s, the maximum communication distance can reach 10Km. Up to 110 network nodes can be connected on its CAN bus, and any node on the network can actively send information to other nodes on the network at any time. The data transmission and reception can be carried out by means of point-to-point, point-to-multipoint or global broadcast.

2. 2 87C196CA MCU

87C196CA is a high-performance 16-bit microprocessor with integrated CAN2.0B bus controller, especially suitable for on-site real-time event control and distributed control. The on-chip CAN controller is software compatible with the Intel 82527 independent CAN controller. The input and output pins of each CAN controller are connected to the CAN bus by two twisted pairs. The CAN controller consists of an input pin (RXCAN), an output pin (TXCAN), control and status registers, error detection and management logic. Figure 2 is a block diagram of the CAN controller.

Application scheme and analysis based on CAN bus and MCU
Figure 2 Block Diagram of CAN Controller

2. 3 CAN bus transceiver

PCA82C250 is the interface between CAN protocol controller and physical transmission line, which is a key factor affecting network performance. It provides differential transmission capability to the bus and differential reception capability to the CAN controller, and its maximum transmission rate can reach 1Mbit/s. Its main feature is that the chip has a current-limiting circuit inside, which can prevent the output stage from short-circuiting to the power supply, ground or load; due to the differential receiving and transmitting method, it has strong anti-electromagnetic interference ability; it has a low-current power-saving standby mode; The CAN bus transceiver can connect at least 110 nodes. Using PCA82C250 can also easily establish photoelectric isolation between the CAN controller and the driver to achieve electrical isolation between nodes on the bus.

3 Communication software

For the communication software programming between the microcontrollers connected by the CAN bus, it is necessary to define a series of control words and configure them on the two microcontrollers. That is, power-on initialization is performed first, the CAN control register is defined, the bit timing register is defined to select the communication rate of CAN, and the message body mask register is defined to select the receiving object. Secondly, initialize the information body, define the working mode of the two information bodies, the number of bytes sent, and select the CAN2.0A or CAN2.0B mode. Its program code:

/*CAN controller initialization*/
can_con = 0x41; /*CAN controller CCE bit 1,
Then you can define the CAN timer*/
can_ btime0 = 0x41 ; /* Define the CAN timer as
250 Kb/s*/
can_btime1 = 0x67 ;
can_con = 01 ; /* allows the CAN controller to be soft
file initialization */
can_sgmsk = 0x0 ; / * Define standard CAN communication format
mask control word of the type, all bits are not filter paper */
can_msg1con0 = 0x55 ; /* message body 1 controller 0
init*/
can_msg1con1 = 0x55 ; /* message body 1 controller 1
init*/
can_msg1cfg = 0x88 ; / * Define message body 1 as sending
Send, send 8 bytes, standard CAN format*/
can_msg1id = 0xc8c8c8c8 ; / * ID of message body 1
The register initialization identifier is c8c8c8c8;
can_ msg1con0 = ox95 ; /* message body 1 controller
0MSGVAL bit 1, indicating that message body 1 is valid*/
can_msg2con0 = 0x55 ; /* message body 2 controller 0
init*/
can_msg2con1 = 0x55 ; /* message body 2 controller 1
init*/
can_msg2cfg = 0x80 ; / * Define message body 2 as the connection
Receive, receive 8 bytes, standard CAN format*/
can_msg2id = 0xc8c8c8c8 ; / * Information body 2 ID
The register initialization identifier is c8c8c8c8 */
can_ msg2con0 = ox95 ; /* message body 2 controller
0MSGVAL bit 1, indicating that message body 2 is valid*/
can_con = 0x02 ; /* CAN controller software initialization
Finish*/
/* Send 8 bytes of data: */
can_msg1con1 = 0x5a ; /* CPUUPD is set to 1, so that
Software refresh data, NEWDA T is set to 1 to make information set to 1 to make information
body effective*/
can_msg1data0 = 0x00 ; / * Give message body 1 the first
data assignment */
can_msg1data1 = 0x11 ; / * Give message body 1 the second
data assignment 3*/
can_msg1data2 = 0x22 ; / * Give message body 1 the third
data assignment */
can_msg1data3 = ox33 ; / * Give message body 1 the 4th
data assignment */
can_msg1data4 = 0x44 ; / * Give the 5th message body 1
data assignment */
can_msg1data5 = 0x55 ; / * Give message body 1 the 6th
data assignment */
can_msg1data6 = 0x66 ; / * Give message body 1 the 7th
data assignment */
can_msg1data7 = ox77 ; /* Give message body 1 the 8th
data assignment */
/*Receive 8 bytes of data: */
can_msg2cfg = 0x80 ;
can_msg2id = oxc8c8c8c8 ;
can_msg2con1 = 0x55;
can_msg2con0 = 0x99;

4 Conclusion

The serial communication of the 16-bit 87C196CA single-chip microcomputer based on CAN bus, due to the use of CAN bus technology, simplifies and compacts the circuit design, greatly improves the reliability and real-time performance of the system, the system has strong anti-interference performance, low cost, and high performance and installation ratio. High, simple and convenient installation and maintenance, more suitable for vehicle control, factory automation control, elevator control, medical equipment, etc., has a very broad application prospects.

The Links:   CM150RX-24T NL6448BC26-01F

Daily Management Of CNC Machine Tools Design of Balance System for High Speed ​​Precision Press Based on Motion Simulation