“CAN bus is a serial data communication protocol. Its communication interface integrates the physical layer and data link layer functions of the CAN protocol, which can complete the framing of data. The user can develop a system that meets the actual needs of the system on the basis of it. Application layer communication protocol. One of the biggest features of the CAN protocol is to abolish the traditional station address coding, and replace it with the coding of the communication data block. Using this method can make the number of nodes in the network not theoretically limited, and it can also make different nodes at the same time Receive the same data.
1 Can bus overview
CAN, the full name of “Controller Area Network”, is one of the most widely used field buses in the world. In the early 1980s, the German Bosch company developed the CAN bus in order to solve the data exchange problem between numerous control and test instruments in modern cars. CAN bus can effectively support distributed control or real-time control serial communication network. It has the advantages of strong anti-interference and reliable use. It was mainly used in the automotive industry at first, and is now widely used in automation fields such as the automotive industry, aviation industry and industrial control. Such as distributed environmental monitoring system, greenhouse environmental monitoring system, substation transformer monitoring system, etc.
CAN bus is a serial data communication protocol. Its communication interface integrates the physical layer and data link layer functions of the CAN protocol, which can complete the framing of data. The user can develop a system that meets the actual needs of the system on the basis of it. Application layer communication protocol. One of the biggest features of the CAN protocol is to abolish the traditional station address coding, and replace it with the coding of the communication data block. Using this method can make the number of nodes in the network not theoretically limited, and it can also make different nodes at the same time Receive the same data.
CAN bus provides high-speed data transmission. It has high-speed (1Mbit/s) data transmission capability at short distances (40m), and low-speed (5kbits/s) transmission capabilities at a maximum distance of 10,000m, which is very suitable for high-speed industrial automation applications. On the above, CAN bus can connect a variety of sensors with different functions (such as position, temperature or pressure, etc.) on the same network.
Other characteristics of CAN bus are as follows:
(1) It is a multi-master bus, that is, each node machine can become a master, and communication between the node machines can also be carried out;
(2) The communication medium can be twisted pair, coaxial cable or optical fiber, and the communication rate can reach 1Mbps;
(3) The length of the data segment is up to 8 bytes, which can meet the general requirements of control commands, working status and test data in the general industrial field. At the same time, 8 bytes will not occupy the bus for too long, thus ensuring real-time communication;
(4) The CAN protocol adopts CRC inspection and can provide corresponding error handling functions to ensure the reliability of data communication.
CAN can work in a multi-master mode, and any node on the network can actively send information to other nodes on the bus at any time, realizing point-to-point, point-to-multipoint and global broadcasting to send and receive data; CAN uses a non-destructive bus Arbitration technology, when two nodes send information to the bus at the same time, the node with lower priority actively stops data transmission, while the node with higher priority can continue to transmit data without being affected, saving bus conflict arbitration time.
Figure 1-1 is a CAN bus application system, which mainly consists of a host and various nodes. The host and nodes are connected through a CAN transceiver and a CAN controller. A single node includes a single-chip controller, a CAN transceiver and a CAN controller. Device. One of the typical applications is: the host receives the field data sent by each node, such as field temperature, current or pressure and other parameters. The host computer makes corresponding control commands after comprehensive calculation and judgment. These commands will be transmitted to each node through the CAN bus. Each node has a single-chip microcomputer as the controller, which is used to collect various parameters on the spot and execute various commands sent by the host. These commands will eventually be transmitted to various actuators, such as valves, motors, or pumps.
Figure 1-1 CAN bus application system
This article will introduce the design of CAN bus intelligent node based on Lingyang 8-bit general-purpose industrial-control single-chip microcomputer. This article will explain the application characteristics of the main controller SPMC65P2404A in the intelligent node in this scheme, and the communication between the main controller and the CAN bus controller.
2 Introduction to chip characteristics
SPMC65P2404A is an 8-bit industrial control microcontroller launched by Sunplus, with a maximum operating frequency of 8MHz, an operating voltage of 3.0V “5.0V, 192 bytes of RAM and 4K bytes of OTP ROM, 23 programmable IO ports, built-in /Pull-down resistor, 8-channel 10-bit A/D converter (100KHz), SPMC65P2404 other features include:
◆Sunplus 8-bit MCU 182 instructions 11 kinds of addressing modes support bit operation (Set, Clear, Inverse, Test)
◆Two 8-bit programmable timers/counters (automatically preset the initial count value) ordinary timer/counter with 8-bit capture function and 8-bit comparison function
◆2 16-bit programmable timer/counter (automatically preset the initial count value) ordinary timer/counter with 8 or 16-bit capture function, 16-bit comparison function, 12-bit PWM output
◆Interrupt mode supports IRQ and NMI interrupts, 4 types of external interrupts, 12 types of internal interrupts
◆With SPI bus: the highest communication rate is 2Mbps
◆5 reset functions: power-on reset, low-voltage reset, watchdog reset, external reset and error address reset
◆Support 3 kinds of clock circuits: crystal oscillator, RC oscillator, external signal
◆2 low power consumption modes: Halt mode and Stop mode
◆A buzzer drive output port
3 Intelligent node hardware design
In industrial control, real-time acquisition, reliable transmission, and real-time Display of signals such as voltage, current, and temperature are usually required to realize the effective control of CAN intelligent nodes on the PC side. In order to meet these control requirements on industrial control, the nodes on the CAN bus usually need a microcontroller as the main controller of the node. The main controller completes the collection of various parameters on site, responds to related external events, accepts external key commands, generates drive signals, displays related parameters and communicates with the CAN bus controller. Figure 3-1 shows SPMC65P2404A as a node controller, the schematic diagram of the connection of each component.
Figure 3-1 Schematic diagram of smart node
Data collection components:
In the industrial control field, there are usually various sensors, such as current transformers, temperature sensors, pressure sensors, etc., which convert the field current, temperature and pressure parameters into analog electrical signals, and these analog signals are input to the A/D in the MCU Converter, finally get a transmittable digital signal. SPMC65P2404A has 8-channel 10-bit precision A/D converter, and can select internal or external reference voltage, which can meet multi-channel, high-precision analog-to-digital conversion.
On-site human-computer interaction components:
The human-computer interaction components can realize the operation and control of a certain node by the staff on the spot. The human-computer interaction components include keyboard, infrared remote control, LED or LCD Display. For example, the display module can display field parameters in real time, and the staff can operate certain keys on the keyboard or remote control to start motors or electric valves and other actuators, so that the system can achieve a preset effect. SPMC65P2404A has multiple groups of capture functions, using the capture function, you can easily achieve infrared signal decoding.
Respond quickly to external emergencies:
In the industrial control field, the emergency protection mechanism is very important. Quick response to emergencies at the scene and protective actions will make the control scene safer. In the node design, you can use the MCU to respond to external interrupts quickly, and cut off the output of the drive signal in the MCU’s interrupt program. SPMC65P2404A can respond to 4 external interrupts, and each external interrupt can be set as a non-masked interrupt or a shielded interrupt.
Generate the drive signal of the actuator:
Node communication connection:
In the design of the intelligent node, a CAN controller and a CAN transceiver need to be used as the connection medium between the main controller and the CAN bus. This intelligent node uses MCP2510 as CAN controller and PCA82C250 as CAN transceiver. The connection between them is: the MCU master controller communicates with the CAN controller through the SPI bus, and the CAN controller connects with the CAN transceiver through the photoelectric isolation device. SPMC65P2404A integrates SPI bus, SPI bus supports full-duplex synchronous transmission, with master and slave modes, and the highest communication rate is 2Mbps. The CAN controller MCP2510 also has an SPI bus.
4 Intelligent node software design
The intelligent node program includes two parts: the main program and the interrupt program. The main program deals with conventional data acquisition and control operations, and the interrupt program deals with abnormal events and infrared signal decoding.