With the development of network technology and microprocessor technology, network and information appliances have increasingly appeared in people’s life, which makes the trend of home appliance bus network irreversible. In order to realize this trend, the embedded gateway connecting the Internet network is the key.

In reality, Ethernet expands the existing system, but fieldbus can not be completely replaced by industrial Ethernet. The latter has great potential and its application field will continue to expand. Therefore, it has become a trend to combine fieldbus and Ethernet to realize the close integration of bottom production and upper management. As one of the most widely used field buses in the world, can bus has also been widely used in China. This design takes can bus as industrial field bus to realize its interconnection with Ethernet.

Ethernet means that it was first created by Xerox. In 1980, Dec, lntel and Xerox jointly developed it into a standard. Ethernet is the most widely used LAN, including standard Ethernet (10mbit / s), fast Ethernet (100mbit / s) and 10g (10Gbit / s) Ethernet. CSMA / CD access control method is adopted, and they all comply with IEEE802.3. It is the most common communication protocol standard adopted by the existing LAN. Ethernet uses CSMA / CD (carrier monitoring, multiple access and conflict detection) technology and runs on various types of cables at a rate of 10m / s. Ethernet is similar to IEEE802.3 series standards.

1 hardware structure

Can is the abbreviation of controller area network (can). It was developed by BOSCH company, which is famous for developing and producing automotive electronic products, and finally became an international standard (iso118-8). It is one of the most widely used Fieldbus in the world. In North America and Western Europe, can bus protocol has become the standard bus for automotive computer control system and embedded industrial control LAN, and has J1939 protocol designed for large trucks and heavy machinery vehicles with can as the underlying protocol. In recent years, its high reliability and good error detection ability have attracted much attention. It is widely used in automotive computer control system and industrial environment with bad ambient temperature, strong electromagnetic radiation and large vibration

At present, there are two main methods for the design of embedded gateway connected with can and Ethernet: one is the design method of low-grade MCU plus interface chip, and the other is the design method of high-grade MCU plus EOS (real-time multitasking operating system) plus interface chip. Because can only adopts the first and second layers of ISO / OSI reference model, the protocol is relatively simple, which is more suitable for discrete control systems with low cost and low rate requirements. Considering the reasonable cost and effective utilization of processing capacity, the design adopts the method of low-grade MCU and interface chip, and its hardware block diagram is shown in Figure 1

What is the application of CAN bus in embedded gateway?

1.1 main control chip and Ethernet interface module

According to the requirements, the system selects the AT89C55 single chip microcomputer produced by ATMEL company with high performance and price. It is oriented to measurement and control object and embedded application, so its architecture, CPU, instruction system and peripheral unit circuit are specially designed according to this requirement. It has up to 20 KB flash program memory inside. AT89C55 is fully compatible with 8051 instruction set. On chip flash is convenient for users to program online. The working rate is up to 33 MHz, 256 B internal RAM, 32 programmable I / O ports, 3 16 bit timing / counters and 8 interrupt sources. It supports low-power idle working mode. RTL8019AS chip is selected as Ethernet interface. It is a highly integrated Ethernet controller produced by Realtek company, which can realize all functions of Ethernet media access layer (MAC) and physical layer (PHY). There are two ram areas in RTL8019AS: one is 16 KB, with addresses of 0x4000 ~ 0x7FFF. To receive and send data packets, you must read and write 16 KB ram in RTL8019AS through DMA. It is actually dual port RAM, that is, there are two buses connected with it. One bus is used for RTL8019AS to read / write or write / read the ram, that is, local DMA; Another bus is used for MCU to read or write the ram, namely remote DMA; The second is 32 bytes, the address is 0x0000 ~ 0x001f, which is used to store the Ethernet physical address. The hardware interface schematic diagram of the main control chip and Ethernet interface chip is shown in Figure 2. It is worth noting that the maximum packet of Ethernet can exceed 1500 bytes, and the on-chip RAM of AT89C55 is only 256 bytes, so it is impossible to store such a large packet. Therefore, a 32 KB external RAM is expanded here, which can also improve the data transmission speed of single chip microcomputer.

RAM (random access memory) ram random access memory. A memory in which the contents of the storage unit can be taken out or stored as needed, and the access speed is independent of the location of the storage unit. This kind of memory will lose its storage content in case of power failure, so it is mainly used to store programs used for a short time. According to different stored information, random access memory is divided into static random access memory (SRAM) and dynamic random access memory (DRAM).

What is the application of CAN bus in embedded gateway?

1.2 can interface module

The main components of can system are can controller and transceiver. In this design, SJA1000 chip and PCA82C250 chip are selected as can interface module. SJA1000 is an independent can controller. It is an alternative to another can controller pca82c200 of Philips company, and a new working mode (Peli can) is added, which supports can 2.0B protocol. SJA1000 mainly completes the communication protocol of can, realizes the assembly and splitting of messages, filtering and verification of received information, etc.

PCA82C250 is the interface between CAN controller and physical bus, which is mainly used to enhance the driving ability of the system. In the system using transceiver, the number of nodes can reach at least 110, and it also has the ability to reduce radio frequency interference (RFI) and strong anti electromagnetic interference (EMI). When dealing with this part of the circuit, there are several places to pay special attention to:

(1) Crystal oscillator circuit problems. 89c55 and SJA1000 should have their own independent crystal oscillator circuit, which can not use the clock output signal clkout of SJA1000 to drive the single chip microcomputer.

(2) Reset pin problem. Although the reset of SJA1000 is low level, it cannot be directly connected to the reset pin of MCU through a non gate. Generally, there are two ways to solve the problem of reset pin: the first is to use the I / O pin of single chip microcomputer to control the reset pin of SJA. Its advantage is that single chip microcomputer can completely control the reset process of SJA; The second is to use an appropriate reset chip. In order to reduce the cost, the design adopts the first method.

(3) The potential of rx1 pin must be maintained at about 0.5 VCC, otherwise the logic level required by CAN protocol cannot be formed.

(4) We must pay attention to the terminal impedance matching of the cable, which directly affects whether the CAN bus can work normally and the network performance. The hardware circuit diagram of the can interface module is shown in Figure 3. A slope resistance R is connected to the RS pin of PCA82C250, and the resistance can be adjusted appropriately according to the bus communication speed.

What is the application of CAN bus in embedded gateway?

2 communication module software design

2.1 implementation of SJA1000 driver

SJA1000 is an independent can controller, which is mainly used for regional network control of moving targets and general industrial environment. It is an alternative to pca82c200can controller (basiccan) of Philips semiconductor company, and it adds a new operation mode pelican, which supports CAN2.0B protocol with many new features.

SJA1000 driver is composed of SJA initialization function, sending function and receiving function. Figure 4 shows its flow chart.

What is the application of CAN bus in embedded gateway?

(1) Initialization of SJA1000. SJA1000 needs to be initialized after the system is powered on, the hardware is reset or the main controller sends a reset command to set its working mode, communication rate, output control mode, identifier shielding format and other important parameters. The initialization of CAN controller SJA1000 can only be completed in reset mode. The flow chart of the program is shown in Figure 4.

Firstly, the program detects whether the can interface works normally, that is, write and read to the test register of SJA1000 to verify whether the results are consistent. If the results are consistent, enter the reset mode for initialization setting. In the process of initialization, if the setting of a register exceeds the specified time and has not been completed, it is considered as initialization failure, and the initialization program automatically sends an error signal.

(2) Data sending and receiving. SJA1000 chip has one message sending buffer and two message receiving buffers for can message transmission. The data sent from the CAN controller SJA1000 to the CAN bus is automatically completed by the CAN controller. The sending data program takes out the data to be sent from the data storage area to form an information frame, and fills the ID address of the host into the frame header; Then, the information frame is sent to the transmission buffer of the CAN controller; Finally, start sending command. The information from the CAN bus to the can receiving buffer is also automatically completed by the CAN controller. The receiving program only needs to read the information to be received from the receiving buffer and store it in the data storage area.

2.2 implementation of RTL8019AS driver

RTL8019AS Ethernet controller is a highly integrated Ethernet control chip produced by Realtek company. It has 8 / 16 bit bus mode, integrates the performance of media access control sublayer (MAC) and physical layer of IEEE802.3 protocol standard, is compatible with NE2000, supports Ethernet full duplex communication mode, and supports automatic detection of UTP, AUI and BNC, It supports 16 I / O basic address options and additional I / O address input and output full decoding mode, supports instantaneous memory reading and writing, and can reach the rate of 10Mbps at the same time. The built-in 16kb SRAM can be easily connected with the microprocessor

The driver of RTL8019AS, like the driver of SJA, has three functions: chip initialization, packet receiving and contract awarding.

(1) Initialization of RTL8019AS. The initialization process of RTL8019AS is complex, but it is very important. It determines some important parameters in the communication process. For example, setting registers of relevant working modes, allocating and initializing receive and send buffers, initializing network card receive addresses, etc., the flow chart is shown in Figure 5.

What is the application of CAN bus in embedded gateway?

(2) Data sending and receiving. Because the Ethernet physical address setting has been completed in the initialization program of RTL8019AS, and the transmission buffer start page address register TPSR has been specified. In addition, the CRC check automatic generator of RTL8019AS is also enabled, the data packet transmission program of RTL8019AS is relatively simple. In the process of data packet transmission, AT89C55 only needs to write the data packet to be transmitted to the transmission buffer of SRAM in RTL8019AS chip through remote DMA and start the transmission process.

When receiving data packets, there are two methods: query and interrupt. In view of the limited processing capacity of AT89C55, the query method is adopted in this design. According to the judgment of curb = = bnry + 1, whether a new data packet is received can be judged. If so, the data can be read out from the network card chip ram through DMA read operation.

2.3 gateway protocol conversion process

The embedded network interface realizes the interconnection of the two networks. When the Ethernet application layer has data to be sent to the CAN node, first send the data to the gateway. The Ethernet controller protocol conversion module parses the complete can protocol data packet and sends it to the CAN bus through the CAN controller. On the contrary, when the can device has data to be sent to the user layer, first send the data to the transparent gateway, the CAN controller protocol module stores the complete can protocol data packet in the buffer, and then notify the main control chip, which calls the Ethernet control protocol conversion module, encapsulates the complete can protocol data packet as application layer data, and then sends it to the Ethernet application layer.

3 conclusion

The hardware and software design scheme of a low-cost, high reliability and fast can Ethernet gateway is introduced here. The practical application shows that the design can be used as a module of CAN bus node and can be combined with instruments and other equipment to make it have the ability of network communication. Compared with the design of similar products, the design can greatly improve its cost performance.

Leave a Reply

Your email address will not be published. Required fields are marked *