CAN bus and USB transfer technology
USB (Universal Serial Bus) is a universal serial bus. With the development and widespread application of computer technology, people have put forward higher requirements for serial bus. Therefore, the development of a compatible low-speed and high-speed technology, to provide users with a shared, scalable, easy to use serial bus has become a common goal of many manufacturers.
USB bus is a new type of fast, bidirectional, synchronous transmission, and hot-swappable data transmission bus. It satisfies the requirements of bus ease of use, scalability and low cost. Therefore, USB is in PC peripherals. The transmission rate of the domain has increased from a low speed of 1.5 Mbps and a full speed of 12 Mbps to today's 480 Mbps high-speed data transmission. At present, the USB bus has gradually become the most widely used peripheral bus connection specification in the computer field.
At the same time, CAN (Controller Area Network) bus technology is also becoming mature, with long transmission distance, high transmission rate, strong anti-interference ability, easy networking, and cost saving. It has been recognized as one of the most promising fieldbuses. And has gained widespread attention in the field of control at home and abroad. At present, the interior control systems of Hyundai Motor Company and several other major European automobile companies use CAN bus, many domestic industrial control systems (such as vehicle control systems, medical control systems and intelligent control systems in many intelligent communities). Both use CAN bus technology. With the introduction of the more complete CAN2.0B protocol, experts abroad have predicted that the application life of CAN bus will be at least 20 years.
Although the characteristics of the above two buses are more prominent, their application in the control field still has its own limitations. The transmission distance of USB usually does not exceed tens of meters, and often does not meet the requirements of industrial applications; and the connection between the CAN adapter and the host on the traditional interface is very cumbersome and complicated, which is not conducive to the application expansion of CAN. Therefore, this design considers the CAN bus technology with a long transmission distance combined with the plug-and-play USB interface technology, that is, the USB interface is convenient to realize the connection between the CAN bus and the host, thereby effectively expanding the monitoring of the CAN bus and Management functions to expand the application range of the CAN bus.
1 Overall design of the interface module
The overall block diagram of the USB-CAN switching technology introduced in this paper is shown in Figure 1. The design is divided into two parts: one is the USB control part connected to the host USB interface; the other is the CAN controller part connected to the CAN bus. The two are connected by a single chip microcomputer. The USB control part uses the USB interface control chip CH372 to realize data reception and transmission; the CAN controller SJA1000 is used to implement data communication between CAN buses. The microcontroller is used for corresponding control, coordination, and system communication.
2 AT89C52 features in the system
The single chip AT89C52 plays a role in bridge and coordinated control in the system. The host sends the data to the MCU through CH372, and the MCU sends the data to the CAN bus through SJA1000, thus realizing the communication of the whole system. In addition, the microcontroller needs to initialize the CH372 and SJA1000, and access the CH372 and SJA1000 in a multiplexed manner by address/data. Since the MCU cannot read the correct data when accessing one of the chips, if the other chip still has an output, the MCU needs to assign an effective address through the chip select control signal. The MCU mainly monitors the communication of the system through the main loop. The main loop flow chart is shown in Figure 2.
3 USB control section
The USB control section uses the USB interface control chip CH372 to implement data reception and transmission. CH372 is a general-purpose device interface chip of USB bus. CH372 is on the MCU side, with 8-bit data bus and read, write, chip select control lines and interrupt output, so it can be easily hooked up to the microcontroller/DSP/MCU controller. On the system bus; in the computer system, the supporting software of CH372 provides a simple and easy-to-use operation interface. Therefore, communication with the local-side MCU is as simple as reading and writing files.
CH372 provides an application layer interface on the computer side. The application layer interface is a function-oriented API provided by the CH372 dynamic link library DLL. All APIs will return after the call, but there is no need to respond to the data. The API provided by the CH372 dynamic link library includes: device management API, data transfer API, interrupt processing API, and the like.
In the application layer design, the author uses the method of requesting plus response. The method uses a downlink active request and an uploaded passive response to perform interactive two-way data communication, and the downlink and upload one-to-one correspondence and mutual correlation. The active request refers to the data request transmitted from the computer application layer to the single chip microcomputer, and the passive response is the response data uploaded to the computer application layer after the single chip receives the data request. All communication is initiated by the computer application layer and then terminated by the response to the receiving microcontroller. The complete process includes the following steps:
(1) The computer application layer sends the data request to the CH372 chip in a pre-agreed format;
(2) The CH372 chip notifies the microcontroller by interrupt mode;
(3) The MCU enters the interrupt service routine to obtain the interrupt status of the CH372 and analyze it;
(4) If it is an upload, release the current USB buffer and then exit the interrupt program;
(5) If it is a downlink, the data block is read from the data downlink buffer;
(6) Analyze the received data block, prepare the response data, or exit the interrupt program and then process it;
(7) The MCU writes the response data to the upload buffer of the bulk endpoint, and then exits the interrupt routine;
(8) The CH372 chip returns the response data to the computer;
(9) The computer application layer receives the response data.
On the MCU side, the CH372 chip occupies two address bits. When the A0 pin is high, the system selects the command port. At this time, the command can be written. When the A0 pin is low, the data port is selected. Write data. When the MCU reads and writes the CH372 chip through the 8-bit parallel port, all operations consist of one command code, several input data and several output data.
However, some commands do not require input data, and some commands may not have output data.
The CH372 chip is designed to handle USB communications. After receiving the data or sending the data, the CH372 will notify the microcontroller to process in the interrupt mode. The flow chart of receiving and transmitting data by the MCU through CH372 is shown in Figure 3.
4 CAN controller section
The CAN controller SJA1000 can receive the signal on the CAN bus through the bus driver PCA82C250 and transmit it to the microcontroller, and receive the signal from the microcontroller, and then transmit it to the CAN bus through the driver.
Since the SJA1000 is shared with the CH372 address/data bus, it should be distinguished by chip selection. During operation, the address latch pin ALE/AS can be connected to the ALE/P of the microcontroller, and the WR and RD pins are respectively connected to the WR and RD of the microcontroller. When the MODE pin is pulled high, the INTEL mode is selected. When using the interrupt pin INT should be connected to INT1 of AT89C52, and connected to external interrupt 1, and should be connected to pull 10 kΩ resistor. A decoupling capacitor should be connected between the power supply and ground.
The TX0 and RX0 pins of the SJA1000 are connected to the TX and RX of the driver 82C250, respectively, and can be used to send and receive data to the CAN bus. At this point, you need to connect the RX1 pin to a stable level and ground the RX1 in the system.
On the CAN bus side, the microcontroller controls the transmission process. The initialization of SJA1000 is completed by the MCU. The initialization flow chart is shown in Figure 4. In the normal working mode, the MCU can control the SJA1000 transceiver and other operations to complete the communication with the CAN bus. When the host sends data, the MCU forwards the data to the SJA1000's transmit buffer, which is automatically encapsulated by the SJA1000 according to the CAN protocol and sent to the CAN bus. When the SJA1000 receives a valid message from the CAN bus, The system will generate a hardware interrupt signal (low active) on the INT pin. When the microcontroller receives the interrupt signal, it will enter the interrupt service routine to complete the data reception and processing. The interrupt service flow is shown in Figure 5.
5 Conclusion
The USB-CAN switching system described in this article can achieve the desired goals. It can realize the transmission of data, thus providing a convenient and practical USB interface for the connection between the CAN bus and the PC.
This series is a professional advertising LED Screen for classic indoor use. Small in size, it is convenient to be placed in shops, cafes, clothing stores, restaurants and many other places. Easy to operate. Wifi connect and controlled by mobile App, USB to play video or display pictures. Cabinet with wheels, easy moveable. Regular size around 640*1920mm in Poster LED Display, it will be a very good choice for advertising screen for all shops. It can be customized to ourdoot types or different sizes.
Waterproof Led Display Screen Wall,Led Display Advertising,Led Display Advertising Billboards,Full Color Led Display
Guangzhou Cheng Wen Photoelectric Technology Co., Ltd. , https://www.ledscreencw.com