Design of CAN bus system based on C8051F040 single chip microcomputer

Publisher:JoyfulSerenadeLatest update time:2011-04-13 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Abstract: This design is a data control system of the CAN bus based on the C8031F040 microcontroller with a CAN controller. Through the USB port, data transmission between two CAN nodes and the host computer is realized. The CAN node is a temperature acquisition system designed based on the C8051F040 microcontroller and can receive data from the host computer. The host computer software is an interface designed based on VB language to interact with the CAN node. It mainly realizes the functions of receiving temperature data and displaying it in real time through charts and sending data to the CAN node. This design is of great significance for studying and understanding the application of communication and control between CAN multi-nodes.
Keywords: CAN bus; CAN-USB; Design

0 Introduction
In the early 1980s, the German Bosch company proposed the CAN (Controller Area Network) bus, that is, the controller local area network solution to solve the communication problem between automotive control devices. After more than 20 years of development, CAN bus is now widely used in the automotive field. The application of CAN bus in automotive control systems can realize the software implementation of hardware solutions, greatly simplify the design, reduce hardware costs and design and production costs, and reduce data duplication. Data sharing reduces data processing and saves costs. It can reduce signal lines to a minimum, reduce wiring, and further reduce costs. Due to the high performance, high reliability, unique design and suitable price of CAN bus communication, it can be widely used in industrial field control, intelligent buildings, medical equipment, transportation and sensors. It is recognized as one of the most promising field buses.

1 System Overall Design
The overall structure of the CAN bus system is shown in Figure 1, which mainly includes host computer control software, USB-CAN conversion module, CAN node, and CAN bus medium (twisted pair cable is used here). One of the CAN nodes is connected to the PC through the USB interface. The host computer control software can display the data of each CAN node in real time and can send data to each CAN node through the host computer software to control the light or off of the 8 light-emitting diodes of each node.

a.JPG

2 System Hardware Circuit
This system consists of a microcontroller peripheral circuit, a CAN bus hardware circuit, and a USB-CAN conversion circuit. The microcontroller peripheral circuit includes a power supply circuit module, a reset circuit module, and a serial communication module. The CAN bus hardware circuit includes an electrical isolation module, an optical coupler isolation module, and a CAN driver circuit. The USB-CAN conversion circuit includes a CH375 and microcontroller interface circuit module and a USB interface circuit module.
The controller area network (CAN) controller inside the C8051F040 microcontroller is a protocol controller that does not provide a physical layer driver (i.e., a transceiver) and requires an external reconnection to the physical layer driver. TJ1050 is used here. TJA1050 is an interface between the controller area network (CAN) protocol controller and the physical bus and is a standard high-speed CAN transceiver. TJA1050 can provide differential transmission performance for the bus and differential reception performance for the CAN controller.
TJA1050 is the successor of the PCA82C250 and PCA82C251 high-speed CAN transceivers. Its functional block diagram is shown in Figure 2.

b.JPG


2.1 CAN bus anti-interference design
(1) Bus impedance matching Two 120 Ω resistors must be connected to the end of the CAN bus. They play an important role in bus impedance matching and cannot be omitted. Otherwise, the reliability and anti-interference of bus data communication will be greatly reduced, and it may even lead to communication failure.
(2) Two 30 pF small capacitors are connected in parallel between the CANH and CANI terminals of TJA1050 and the ground to filter out high-frequency interference on the bus and prevent electromagnetic radiation.
(3) A 5 Ω resistor is connected in series between the CANH and CANL terminals of TJA1050 and the CAN bus to limit the current and protect TJA1050 from overcurrent shock.
(4) A 100 nF decoupling capacitor is added between the power supply terminal and the ground of integrated circuits such as TJA1050 and TLP113 to reduce interference.

3 System software design
The system software design mainly includes the design of CAN communication program and CAN-USB conversion program. In addition, in order to collect the data of CAN nodes and send them to the host computer for display, a program for collecting the temperature sensor data inside the microcontroller is also added. The CAN communication program mainly completes the CAN data transmission of each node. It can send data to other nodes and receive data from other nodes to control the corresponding LED. The CAN-USB conversion program mainly completes the data transfer. It can receive data from the host computer and package it into data corresponding to the CAN protocol, and can send CAN protocol data to the host computer. The temperature sensor acquisition mainly converts the voltage on the internal thermistor through ADC0 and converts it into the actual temperature.
3.1 CAN communication program flow circle
As shown in Figure 3, the main program includes IO configuration, crystal oscillator initialization, clearing message RAM, sending and receiving function initialization and CAN initialization.

c.JPG


3.2 System interrupt handling program flow chart
The system interrupt handling program flow chart is shown in Figure 4. This program responds to the interrupt request sent by the CAN control and mainly completes the data reception work.

d.JPG
3.3 USB-CAN conversion program flow
All communications are initiated by the computer application layer and then end with the receipt of the response from the microcontroller. The detailed process of USB-CAN conversion is shown in Figure 5.

e.JPG



4 System and host computer interaction results
Figure 6 shows the running status of the host computer software during data collection. The two curves in the figure have a large rise and fall because the temperature rises when the fingers are placed on the microcontrollers of the two CAN nodes. When the fingers are released, the temperature gradually drops.

f.JPG


Click the setting button to make the window in the upper right corner effective. You can set the sampling time, which indicates how long it takes to send a data packet to the lower computer. The left side shows the current temperature value of each node in real time, and the curve on the right shows the temperature change. The figure also shows that 15 is sent to node 1 and 170 is sent to node 2.

5 Conclusion
This paper uses C8051HNO microcontroller as CAN controller, uses USB interface to communicate with the upper computer, realizes the function of CAN bus, and achieves the expected effect, reflecting the practicality of CAN bus. However, the USB interface chip can reach full speed mode, but this design does not reflect its fast transmission rate, which will be improved in future work.

Reference address:Design of CAN bus system based on C8051F040 single chip microcomputer

Previous article:Design of campus self-guided tour device based on C51 single chip microcomputer
Next article:Software Implementation of Digital Filter in High Impact Signal Acquisition System

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号