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.
Previous article:Introduction to AT89C51 Microcontroller
Next article:Multi-machine communication based on hardware arbitration and serial bus
- Popular Resources
- Popular amplifiers
- Mission-oriented wireless communications for cooperative sensing in intelligent unmanned systems
- Principle and maintenance of automobile on-board network system (CAN-BUS)
- ICCV2023 Paper Summary: Fairness, Privacy, Ethics, Social-good, Transparency, Accountability in Vision
- Application of CAN bus in communication between electric vehicle BMS system and charging pile
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Today at 10:00 AM, live broadcast with prizes: The best assistant in human-machine interaction interface and machine vision applications—Renesas Electronics
- DSP digital anti-noise module for airborne communication equipment
- (Transfer) Bluetooth BLE GATT complete analysis and application
- Why do OEMs like to specify Ethernet connectors?
- "Play Board" + Shared Bicycle Control Panel 1
- Wire harness disc abnormal noise test
- Mid-Autumn Festival and Teachers' Day are coming together. I heard that there are only three times in a century.
- Liyuan Award Live Broadcast: Interpreting ON Semiconductor Power Solutions, Transforming Server Power Supplies and Solar Inverters
- CC2640R2F Battery Fuel Measurement
- 【AT-START-F425 Review】Use of GPIO port and OLED screen display driver