Design of CAN bus communication system based on C8051F040

Publisher:清新心情Latest update time:2012-12-29 Source: autoooKeywords:C8051F040 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1 Introduction

CAN bus, or controller area network bus, is a serial communication network that effectively supports distributed control or real-time control. Due to its high performance, high reliability, unique design and suitable price, it is widely used in industrial field control, intelligent buildings, medical equipment, transportation tools, sensors and other fields, and has been recognized as one of the most promising field buses.

At present, the CAN system mostly uses independent CAN controllers. The parallel port of the microcontroller is used to control the CAN controller. In addition to 8 data lines, several control lines are required. This design not only occupies the pins of the microcontroller, but also increases the area of ​​the circuit board. At the same time, due to the use of parallel communication, the reliability of the system is reduced. Therefore, it is imperative to use a microcontroller with an integrated CAN controller in the system.

Based on the C8051F040 microcontroller with internal integrated CAN controller of Cygnal Company, this paper introduces the specific design and application of the communication interface of CAN bus. The use of the microcontroller with integrated CAN controller greatly simplifies the circuit and improves the reliability of the system.

2 C8051F040 integrated CAN controller

C8051040 has an internal integrated CAN controller, which is compatible with CAN technical specifications 2.0A and 2.0B. It mainly consists of a CAN core, message RAM (independent of CIP-51's RAM), a message processing unit and control registers. Figure 1 shows the internal CAN bus structure of C8051F040.

In Figure 1, the CAN core consists of a CAN protocol controller and a serial/parallel conversion RX/TX shift register responsible for message transmission and reception. The message RAM is used to store message targets and arbitration masks for each target. This CAN processor has 32 message targets that can be configured to send and receive messages at will, and each message target has its own identification mask. All data transmission and reception filtering are completed by the CAN controller, not by CIP-51. The CAN internal registers store all CAN control and configuration information, including control registers, status registers, bit timing registers for setting baud rate, test registers, error counters, and message interface registers. Usually, the CAN core cannot directly access the message RAM, but must access it through the interface registers IF1 or IF2. In addition, the SFR of CIP51 cannot directly access all units of the CAN internal registers. Its configuration of CAN, message target, reading of CAN status, acquisition of received data, and transmission of sent data are all completed by 6 special registers in the SFR. Among them, the three registers CAN0CN, CAN0TST and CAN0STA can directly obtain or modify the corresponding registers in the CAN controller, and the three registers CAN0DATH, CAN0ATL, and CAN0ADR are mainly used to access and modify other CAN internal registers that cannot be directly accessed. Among them, CAN0ADR is used to point out the address of the register to be accessed, and CA0DATH and CAN0DATL are equivalent to the mapping registers of the high and low bytes of the 16-bit register to be accessed, and their reading and writing are equivalent to the reading and writing of the pointed registers.

Figure 2 shows how CIP-51 accesses the control registers and each message path in the CAN. The message processing unit is used to control the data transfer between the shift register and the message RAM in the CAN core according to the message in the register. At the same time, it can also be used to manage the generation of interrupts.

3 Hardware Design of Intelligent Node Communication Part

The C8051F040 has a built-in CAN bus protocol controller. As long as an external bus driver chip and an appropriate anti-interference circuit are connected, a practical CAN bus intelligent measurement and control node can be easily established. This article uses the PHILIP company's TJA1050T CAN bus driver, and the hardware schematic diagram is shown in Figure 3.

In order to enhance the anti-interference ability of CAN bus nodes, the following measures can be taken:

(1) TX0 and RX0 of F040 are not directly connected to TXD and RXD of TJA1050T, but connected to TJA1050T through high-speed optocoupler 6N137, which well realizes the electrical isolation between CAN nodes on the bus. However, it should be noted that the two power supplies VA and VB used in the optocoupler circuit must be completely isolated, otherwise the use of optocouplers will lose its meaning. Although these parts increase the complexity of the node, they improve the stability and security of the node.

(2) The CANH and CANL pins of TJA1050T are each connected to the CAN bus through a 5Ω resistor. The resistor can play a certain current limiting role and protect TJA1050T from overcurrent shock.

(3) Two 30pF small capacitors are connected in parallel between CANH and CANL and the ground to filter out high-frequency interference on the bus and to provide a certain degree of protection against electromagnetic radiation.

(4) In addition, a protection diode can be reversely connected between the two CAN bus access terminals and the ground. When the CAN bus has a high negative voltage, the short circuit of the diode can provide a certain overvoltage protection effect. [page]

4. Communication software design for intelligent nodes

The CAN communication of nodes mainly includes system initialization program, sending program, receiving program, etc. The quality of the software design will directly determine whether the system can work normally. It is a difficulty and a key point for designers who are new to the CAN bus system. In this paper, the system software adopts a structured programming scheme to make it have good modularity and portability. For different system functions or different application environments, it can be easily reprogrammed.

4.1 System Initialization

ecms.*

The initialization program mainly completes the initialization of all message objects (generally all values ​​are set to zero), sets the CAN control register (CAN0CN) and the bit timing register (BITREG), and also initializes the sending message object and the receiving message object respectively. Among them, the setting of the bit timing register is more complicated. Here, the external crystal oscillator is 11.0592MHz, the CAN communication rate is 1Mb/s, and the initial value of BITREG is 0x2640. The main program stipulates object initialization, sending and receiving initialization, and finally starts the CAN processing mechanism (initializes BITREG and CAN0CN). The following is the CAN startup program:

4.2 Sending and Receiving Procedures

The sending program is mainly responsible for writing the content to be sent in the interface register into the specific message object, while the function to be implemented by the receiving program is exactly the opposite of the sending program. The receiving program is responsible for reading the received content from the message object into the interface register. Since the programs of the two are similar, the sending program code is given below.

5 Conclusion

Using a microcontroller with an internally integrated CAN controller module to design a fieldbus intelligent node is not only simple and reliable in hardware design, but also more convenient and concise when compiling the corresponding software. This article adopts this design scheme and introduces in detail the hardware interface and software design method when using C8051F040 to design the CAN bus intelligent node communication interface. The actual operation of the system verifies the correctness and reliability of the design.

Keywords:C8051F040 Reference address:Design of CAN bus communication system based on C8051F040

Previous article:Introduction to AT89C51 Microcontroller
Next article:Multi-machine communication based on hardware arbitration and serial bus

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号