The CAN (Controller Area Network) bus protocol plays an indispensable role in the development of modern in-vehicle applications. As a standardized protocol for the internal network of a car, CAN Bus has become the basis for the communication of in-vehicle systems. In the process of Android in-vehicle application development, it is essential to understand and utilize the CAN Bus protocol.
So what is CAN Bus? How does it realize data transmission in in-vehicle applications? In this article, we will discuss the working principle of CAN Bus protocol and its application in Android in-vehicle application development.
With the development of intelligent vehicles, CAN Bus protocol occupies an important position in in-vehicle network communication. Especially in electric vehicles and self-driving cars, the reliability and real-time performance of CAN Bus protocol is especially critical. Both OEMs and third-party developers need to have a deep understanding of CAN Bus in order to develop applications that meet market demands.
summarize
1.1 Background
The automobile industry is booming, and the number of electronic control units in automobiles is gradually increasing. The signal exchange between the electronic control units leads to an increase in the number of levels of automotive wiring harnesses, complex and thick wiring harnesses and automobiles with limited wiring space between the contradiction is increasingly prominent, a wide range of wiring harnesses lead to the electrical systemReduced reliability, while at the same time increasing the weight.
CAN Bus Connects the various electronic control units within the vehicle to each other into alocal area network, enabling the sharing of information and greatly reducing the car's wiring harness, as shown in the figure below:
CAN Bus It can meet the demand of data transmission of sub-systems and can realize the evolution of in-vehicle interconnection system from the traditional point-to-point interconnection to the bus type system, which greatlyReduces the complexity of wiring electronic systems in automobiles.
1.2 What is CAN Bus
CAN(Control Area Network)Bus The controller LAN bus, a serial communication protocol, enables the reliable and efficient transfer of data between devices. It is widely used in the vehicle sector, connecting the various electronic control units within the vehicle like a nervous system.
CAN Bus Originally developed by German multinational engineering giantBosch(Robert Bosch) designed for automotive applications. It is a multi-master, multi-slave, half-duplex, fault-tolerant protocol that is ideally suited to the needs of the automotive sector. ItSimple, low-cost, reliable and able to operate in harsh environments。CAN Bus Provides a unified access point for all electronic control units in the vehicle for easy connectivity and diagnostics.
1.3 Brief History of CAN Bus
CAN Bus Developed by Bosch in the early 1980s to provide an efficient communication system for automotive applications, the main objective was to simplify the complexity of wiring harnesses inside vehicles.
In 1986, Bosch released the first CAN protocol, which, due to itsdependabilitycap (a poem)robustnessIn 1993, it became the ISO-11898 international standard. The evolution of the protocol is summarized below:
-
Versions prior to CAN: automotive ECUs are complex point-to-point wiring
-
1986: Bosch develops the CAN protocol as a solution 1991: Bosch releases CAN 2.0 (CAN 2.0A: 11 bits, 2.0B: 29 bits)
-
1993: CAN adopted as an international standard (ISO 11898)
-
2003: ISO 11898 becomes a family of standards
-
2012: Bosch releases CAN FD 1.0
-
2015: CAN FD protocol standardization (ISO 11898-1)
-
2016: CAN physical layer with data rates up to 5 Mbit/s, standardized to ISO 11898-2
In addition to the automotive sector, theCAN Bus The protocol is also gradually being used in other industries, such as industrial automation systems (CANopen) and marine electronics (NMEA 2000). Its widespread use is mainly due to its ability to operate stably under harsh conditions and its low implementation costs.
1.4 CAN Bus Advantages
The CAN Bus standard has been widely accepted for use in virtually all vehicles and a wide range of devices. This is mainly due to its many advantages:
-
Simple and low cost: ECUs communicate via a single CAN system instead of direct, complex analog signal lines, reducing errors, weight, wiring and costs.
-
Completely centralized: CAN bus provides "one point of entry" to communicate with all networked ECUs - supports centralized diagnostics, data logging and configuration
-
Extremely robust:The CAN bus is highly resistant to electrical and electromagnetic interference, making it ideal for applications with stringent safety requirements (e.g. vehicles).
-
very efficient: CAN frames are prioritized by ID number. The most prioritized data can access the bus immediately without interrupting other frames.
CAN is an ideal protocol when distributed control of complex systems is required. It reduces heavy wiring, which reduces cost and weight. The cost of the chip is low and CAN is relatively easy to implement due to the simplicity of the protocol design.
How CAN Bus works
2.1 Physical connection and protocol operation
CAN Bus is a distributed communication protocol. Its distributed nature makes it ideally suited for applications with high demands for reliability andtopicalityApplications with high requirements, such as automotive and industrial systems.
existCAN In a network, all the nodes are connected through twisted pair or fiber optics. Each node has its own microcontroller that handles incoming messages and outgoing messages. Data is broadcast by the node on a shared bus and is received by all other nodes.
Several key stages of the communication process include:
-
arbitration: In order to avoid conflicts when multiple nodes send data at the same time, CAN uses an arbitration process based on message priority. The smaller the value of the message's identifier, the higher the priority
-
error detection: Built-in error detection mechanisms ensure the integrity of data in the CAN network. These include cyclic redundancy check (CRC), frame check sequence (FCS), and receive node acknowledgement bits.
-
Failure definition: If a node detects an error or fault during transmission, it enters a "passive error" state until the problem is resolved. This mechanism prevents faults from interfering with the functioning of the entire system.
Together, these features enable the CAN Bus to operate efficiently and ensure reliable communication between components in complex systems such as vehicles or factory automation equipment.
2.2 Message structure
In the CAN Bus system, the message structure is very important for efficient communication between the devices. communication on the CAN bus is accomplished via CAN telegrams.
There are two variants of message length:standard lengthcap (a poem)Extended Length。
The figure below shows a standard frame (CAN 2.0A) with an 11-bit identifier (CAN ID), which is the type used in most cars.
The extended 29-bit identifier (CAN ID) message (CAN 2.0B) is identical except for the longer ID.
It is mainly used in the J1939 protocol for heavy vehicles.
8 telegram fields for CAN Bus
The Arbitration field contains the message identification number and the teleport request bit. The more important the message the lower the ID number.
If multiple nodes transmit at the same time, they initiate simultaneous arbitration. The node with the lowest message ID number gets priority.
Explicit bits override implicit bits on the CAN bus. The length of the message identifier can be 11 bits (standard CAN, 2048 distinct message identifiers) or 29 bits (extended CAN, 537 million distinct message identifiers). The Remote Transmission Request bit is dominant and indicates that data is being transmitted.
In most systems, a logic 1 represents a high level and a logic 0 represents a low level. On the CAN bus, however, the opposite is true. Therefore, CAN transceivers typically use pull-up resistors on the driver inputs and receiver outputs so that the device defaults to an implicit bus state.
2.3 Types of CAN Bus
The ISO 11898 standard defines several versions of CAN. The main types of CAN used in the automotive industry are:
Low-speed CAN
Low-speed CAN, also called fault-tolerant CAN or ISO 11898-3, has a maximum transmission speed of 125 kbps.
It is suitable for less important systems like body control modules, door locks, window controls, etc., which do not require high data transfer speeds. Its main feature is that it continues to work properly even if one of the wires in the bus is broken.
High-speed CAN
High-speed CAN, or ISO 11898-2, with transmission speeds up to 1 Mbps.
Typically used for communication between critical subsystems that require high update rates and high data accuracy (e.g., anti-lock braking systems, electronic stability control, airbags, engine control units, etc.). High-speed CAN is faster than low-speed, however, it does not have the fault tolerance of low-speed networks.
CAN FD
Introduced by Bosch in 2012, CAN FD is an expanded version of the high-speed network with higher data transfer speeds of up to 8 Mbps and backward compatibility with existing high-speed devices.
The main advantage of this technology is that it can transmit larger loads more efficiently than conventional CAN, making it ideally suited to the increasingly complex electronic systems of modern vehicles.
CAN FD It is also backward compatible, supporting the CAN 2.0 communication protocol and special protocols such as SAE J1939, where the CAN output is used as read-only.CAN FD It is essentially an extension of the original CAN standard specified in ISO 11898-1 and is fully compatible with classic CAN systems.
CAN FD is an important step forward as it allows the ECU to dynamically change its transmission rate and select larger or smaller message sizes based on real-time requirements. It is now found in high-performance vehicles, but as ECU performance improves and theCAN FD the declining cost of hardware.CAN FD It's only a matter of time before you get into almost any vehicle.
CAN in Vehicle Development
3.1 Bus protocols in the vehicle
The automotive buses commonly used in cars today areLocal Interconnect Protocol LIN and Controller Area Network CANThe other automotive bus technologies in development areHigh Speed Fault Tolerant Networking Protocol FlexRayand for automotive multimedia and navigationMOST As well as wireless network technologies such as Bluetooth and wireless LAN that are compatible with computer networks.
Notes: * UTP = unshielded twisted pair(unshielded twisted pair)
As with any networking and interoperable system, automotive bus selection is best done with a needs-driven focus on both cost and anticipated industry requirements and trends.
Obviously, automakers will not adopt an old bus in a new design if there is a better bus available with comparable or lower deployment costs.
3.2 Application of CAN Bus in Vehicle Development
As an Android app developer you may ask:CAN Bus belongs to the bottom of the things, we mastered what can be useful?
Actually.CAN telegrams are also relevant for application development, so it is necessary to learn and master the CAN Bus protocol! The following is an example of a car air conditioning application development scenario that explains why application development also requires knowledge of the CAN Bus.
Students who are familiar with mobile app development know that after code development is complete, you need to perform thereal-time commissioning (of a computer)While the debugging environment is actually very simple to build, basically only need to have the corresponding Android version of the project machine can be simulated in front of their own workstation debugging most of the scenarios. If you don't even have a real machine! UseAndroid emulatorIt also covers most debugging scenarios.
However, for in-vehicle application development, trying to debug an in-vehicle system on a real car is actually a luxury.Because there are fewer actual vehicles.So most of the time you can only be at your own workstation next to theAnalog on-board systemsdevelopment and debugging. Whereas analog in-vehicle systems usually onlyhosts、monitorPeripherals such as sensors, antennas, and other various ECUs in automobiles are not available.
Then for vehicle air conditioning application development, its ambient temperature, outlet angle, air speed and other variables can not be dynamically fed back into the vehicle system, which in turn affects the debugging. This is the turn ofCAN Bus Out on the field.
The CAN analyzer can be connected to the on-board system mainframe using theZCANPRO Signal simulation software Read Uplink CAN Signal orAnalog signaling of downward movementThe following is an overview of the CAN signals. Only if you are familiar with the frame structure in CAN signals can you read and simulate the transceiver signals.
VHAL communicates with the vehicle ECU via the CAN bus or other vehicle-specific bus systems. These specialized interconnection networks serve as the backbone for the communication of components within the vehicle.
In order to retrieve vehicle data, such as speed, the in-vehicle infotainment (IVI) ECU interacts with other ECUs and the vehicle HAL carefully stores the extracted information as vehicle attributes.
The Android framework leaves the choice of data transfer protocols and networks, including in-vehicle networks, to the VHAL implementation. This flexibility allows not only CAN bus integration, but also connection to internal networks such as Local Interconnect Networks (LIN) and future in-vehicle communication standards.
CAN Bus protocol provides a stable and efficient communication method for in-vehicle systems. In the development of Android in-vehicle applications, the reasonable use of CAN Bus protocol can not only improve the functionality of the application, but also provide users with a more intelligent driving experience.
"The CAN Bus protocol is not only the communication hub of the car, it is the starting point for intelligent driving."