Reprinted: CAN knowledge

Author: Plato
Link: https://www.zhihu.com/question/35630289/answer/650086824
Source: Zhihu
The copyright belongs to the author. For commercial reprint, please contact the author for authorization, for non-commercial reprint, please indicate the source.
 

1 Where there are automotive electronics engineers, there is CAN

The wave of intelligent networked vehicles has swept the global background. Big data, cloud platforms, artificial intelligence, and autonomous driving...have long become familiar words for automotive electronics practitioners. However, the CAN bus technology born in 1986 is enduring and full of vitality. It is foreseeable that the CAN bus will still be one of the main forces of the vehicle network for a long period of time in the future.

It is no exaggeration to say that the use of CAN bus is a compulsory course for every beginner in automotive electronics engineering , whether you are an automotive electronics hardware engineer, software engineer, system engineer, test engineer, road test engineer, calibration engineer... Anyway, as long as you are an automotive electronics "brick-moving" engineer, you can't escape taking your oscilloscope, or CAN OE, Vehicle spy to collect CAN data in the car and analyze various intractable diseases . If you have never played CAN OE or Vehicle spy, you are ashamed to say that you have done automotive electronics development .

vector VN1640 CAN tool

can oe interface

vehicle spy CAN tool

vehicle spy interface


2 Basic knowledge of CAN

Since it is a compulsory course for automotive electronics engineers, it is necessary to study it solidly. After decades of development and popularization, there are countless materials about CAN on the Internet. You can search the Internet. Here is a recommended book that I read more when I was studying.

CAN Primer - Graphics - Baidu Library Wenku.baidu.com/view/7701528a6529647d2728520f.html

This introductory book comes from Renesas, a famous automotive chip manufacturer. Personally, I feel that the characteristics of this material are very meaningful in actual combat, and it is more suitable for learning and using in actual combat development.

Here is a brief summary of the keywords and knowledge points in the book:

(1) CAN network

As shown in the figure, the CAN network usually consists of N nodes, and the nodes are connected by bus. Each node must include a CAN transceiver , a CAN controller, and a main control CPU ( usually the CAN controller and the main control CPU are integrated solutions ) . The more common CAN communication rates are 500Kbps and 125kbps, that is, the so-called low-speed fault-tolerant CAN and high-speed CAN in the industry, which have different physical characteristics.

CAN connection diagram

Low-speed fault-tolerant CAN : When only one of CAN_H or CAN_L is disconnected, it can still communicate normally. It is mainly used in occasions with high reliability requirements such as body control CAN network channels .

High-speed CAN : used for higher data throughput capacity, mainly used in occasions with real-time performance and large data transmission volume, such as CAN channel of automobile power system, etc.

High-speed CAN VS low-speed CAN​blog.csdn.net/ppdyhappy/article/details/71498688

(2) CAN frame classification

CAN frames can be divided into data frames, remote control frames, error frames, overload frames, and frame intervals . The uses of various frame types are shown in the table below. As the carrier of data transmission, data frames are the most important. Normal control commands, status information, diagnostic data, and refresh data are all transmitted through data frames.

(3) Composition of CAN data frame

To understand CAN, you must, absolutely, and absolutely must know the composition of the data frame , especially pay attention to the arbitration segment and the data segment. The following figure shows the frame format of the standard frame (the arbitration segment is 11bit). The ID value range can be 0x000~0x7FF; different manufacturers will divide the data segment into regions, such as (just for example ) :

0x00~0xFF : used for high priority event message transmission;

0x100~0x4FF : used for periodic message transmission;

0x500~0x5FF : used for the transmission of network management messages;

0x600~0x6FF : Used for debugging, development, and transmission of calibration-related messages;

0x700~0x7FF : used for the transmission of diagnostic related messages;

The composition of the standard frame

Extended frame:

Compared with the standard data frame in the above figure, there is also an extended CAN data frame, and the SOF bit in the CAN data frame is a 32-bit arbitration field. The first 11 bits of the arbitration field are the most significant bits (Most Significant bit, MSb) of the 29-bit identifier (base ID). Following these 11 bits is the Substitute Remote Request (SRR) bit, defined as a recessive state. After the SRR bit is the lDE bit, which means that this is an extended CAN frame when it is in a recessive state.


3 Main contents of CAN development in automobile development

After reading the introductory book, I have a preliminary understanding of the concept of CAN. Let's briefly talk about the development of CAN.

Since I am involved in more software development, I will not describe too much about hardware development here.

(1) CAN driver development

To achieve CAN transceiver, CAN driver development must be implemented first. CAN driver development mainly includes: CAN controller driver development and CAN transceiver driver, the more classic NXP TJA104X series CAN transceiver, and most NXP MCU integrated flexCAN controllers . This part of the development is more about reading the chip manual of the corresponding model of CPU and controller, combined with the sample code, digging out sentence by sentence, typing line by line, and then cooperating with oscilloscope (logic analyzer) and various CAN tools to explore repeatedly .

The main registers related to FlexCan of a certain chip of NXP

Schematic diagram of TJA1043T (screenshot from NXP official website)

The most critical part of the development of the CAN transceiver driver is to understand the switching methods of different working modes of the transceiver. As shown in the figure below, the state switching diagram of the TJA1043T transceiver is divided into NORMAL Mode, STADBY Mode, GO-TO-SLEEP Mode, and SLEEP Mode.

Schematic diagram of TJA1043T transceiver state switching (from NXP official website screenshot)

(2) CAN communication matrix

The CAN communication matrix is ​​usually defined by the vehicle manufacturer, and each node in the vehicle network needs to follow the communication matrix to complete information interaction and sharing.

As shown in the figure, the vector tool opens the XXX.dbc file (commonly used to save the communication matrix file format). You can see that the CAN message Message1 can transmit 8 bytes at a time, that is, 64bits of information. 64bits are composed of multiple signals, and each signal is distributed in different positions of the message. (Example) The blue openwindow can be expressed as a window opening control command.

like:

①When openwindow=0, it means open the window; when openwindow=1, it means close the window;

②vehiclespeed indicates vehicle speed information, vehiclespeed=5 indicates 5km/h.

Here is just a simple example. The actual car development will also involve the conversion of certain physical values ​​​​and logical values .

In this way, when Message1 is sent to the CAN bus, those who receive the CAN node can obtain the CAN control command or status value at this time.

Schematic diagram of message1 in the dbc file

It is worth noting that when defining the communication matrix, different manufacturers may have different choices. For example, different manufacturers have their own preferences when choosing between the Motorola format and the Intel format .

The difference between Intel format and Motorola format blog.csdn.net/bingdianlanxin/article/details/41522373

(3) CAN-based vehicle diagnosis

Encyclopedia- Car Diagnosis : Under the condition of not dismantling (or only removing individual parts), determine the technical condition of the car, and find out the location and cause of the fault. It includes detection and diagnosis of automobile engine, detection and diagnosis of automobile chassis, detection and diagnosis of automobile body and accessories, detection and detection of automobile exhaust pollutants and noise, etc. CAN can well meet the above requirements.

The development of automobile diagnosis is a very important part in the development of automobile electronic appliances, and the most common one for CAN diagnosis is UDS. The UDS protocol is ISO14229, which is Unified Diagnostic Services, a unified diagnostic service, and a standardized standard for diagnostic services. It is widely used in automotive diagnostics. As shown in the figure, in order to meet the diagnostic needs, a series of services are defined in UDS.

Of course, in order to ensure the stable transmission of diagnostic messages, there is also the ISO 15765 protocol, which is a diagnostic protocol on the CAN bus.

in:

ISO 15765-1 includes physical layer and data link layer,

ISO 15765-2 describes the network layer,

ISO 15765-3 specifies specific services at the application layer.

The content of the above-mentioned standard is relatively complicated, so I won’t expand it here. It is inevitable for students who are determined to do a good job in CAN development, especially for CAN diagnosis, to be familiar with ISO14229 and ISO 15765.

Schematic diagram of the protocol based on CAN diagnosis

(4) Refresh based on CAN

Due to design defects or function upgrades, the on-board controller will have software refresh requirements during its life cycle. As the almost only data channel between the controller and the outside world, the software refresh of the on-board controller is usually implemented by the CAN channel, and CAN-based refresh is closely related to CAN-based diagnosis.

(5) CAN network management

I will talk about it in detail later, mainly divided into OSEK network management and AUTOSAR network management.


4 Advanced stage - AUTOSAR must be mentioned

The popularity of AUTOSAR in the automotive electronics industry should not be inferior to that of "Liushen" in the Chinese perfume industry. Simply put, AUTOSAR is jointly established by global automakers (BMW, Daimler, Ford...), component suppliers and other electronics (Continental, Bosch...), semiconductor and software system companies, and each member maintains a development partnership . Since 2003, the partner companies have worked together to develop an open, standardized software architecture for the automotive industry .

Founding member of AUTOSAR Alliance

CAN is the most important form of communication in the field of automotive electronics. How can AUTOSAR not define and standardize CAN? It can be said that the architecture of AUTOSAR has had an important impact on today’s software architecture. The figure shows the preliminary arrangement of CAN related modules and architecture in AUTOSAR. It can be clearly seen that the CAN driver, interface layer, transport layer, CAN diagnosis, CAN network management, etc. are defined systematically from bottom to top.

At present, major domestic OEMs and component suppliers are also actively promoting AUTOSAR, so to become an advanced master of CAN, it is absolutely necessary to have a good understanding of AUTOSAR.

----However, AUTOSAR is really profound, and we will have the opportunity to study in depth together in the future.


5 Do it, do it, do it

" XX Technology from Beginner to Master ", "Teaching You to Play XXX Hands-On", " Ten Days to Master XXX ", I believe everyone has heard of this kind of books, and those who are lucky may have read it once or twice, but after reading the book, can they really be proficient, or have fun? I believe that there are very few people who can achieve the Tao by just relying on a book. After all, not everyone is Zhang Wuji, who can pick up a copy of The Great Teleportation of the Universe and practice it within a few hours.

Real knowledge comes from practice, and practice is the only criterion for testing truth. These are all eternal truths. To learn CAN well, I believe you must:

(1) A set of CAN development version , there are many development versions of this type in Taobao, and the price ranges from tens to hundreds;

(2) A CAN data reading and writing tool can be easily obtained by spending a few hundred yuan. Of course, if there are project conditions or mine series at home, you can directly use Vector’s VN1640 and Interpez ’s vehicle spy;

(3) Logic analyzer (optional) , students who don’t want to keep the understanding of CAN frames only on paper, can prepare a logic analyzer for students who have a lower level understanding of CAN.

Then it is to test the truth in practice and sum up experience in practice.


Summarize:

I personally think that the learning of CAN may be divided into the following levels (stages):

Understand and use CAN : read the CAN introductory book and learn about CAN tools, basically you will be able to collect and refresh (use) CAN messages;

★★

Further master the working principle of CAN : build a development version on the basis of 1, read the chip manual, type the code, and measure the waveform with the oscilloscope;

★★★

Engage in automotive CAN development : On the basis of the above, familiarize yourself with various CAN standards (ISO14229, ISO11898, ISO15765), systematically learn CAN drive, CAN diagnosis, CAN network management and other knowledge, and continuously improve your cognition and accumulate experience in actual combat.

★★★★★

Become a master of CAN : master the AUTOSAR architecture, and be familiar with the functions, working principles, and implementation methods of each CAN module defined in autosar.

Digression: CAN is a technology that has been developed and popularized for decades, and its technical standards and tools have been quite perfect. Although CAN will continue to exist for a long time in the future, it will inevitably lack potential; besides, there are many rising stars in automotive network technology. Among them, automotive Ethernet is the one with the most potential, so you can pay more attention.

Guess you like

Origin blog.csdn.net/gonggong11qqqww/article/details/123703460