What is CAN Bus? An Overview
sonnepower Product Page
CAN Bus, short for Controller Area Network Bus, is a widely used communication protocol in the automotive and industrial automation industries. It is a network technology that allows various electronic devices and sensors to communicate with each other efficiently.
Understanding the Basics of CAN Bus
CAN Bus is a robust and reliable communication system that enables real-time data transmission between different components of a system. It was initially developed by Robert Bosch GmbH in the 1980s for in-vehicle communications.
Definition of CAN Bus
CAN Bus is an asynchronous serial communication protocol that uses a differential signalling scheme to transmit data over a twisted pair of wires. It employs a message-based communication model, where individual devices on the network can send and receive messages known as data frames.
History and Development of CAN Bus
The development of CAN Bus technology can be traced back to the 1980s when Robert Bosch GmbH recognized the need for a reliable communication protocol for automotive applications. It was initially used in cars to replace complex wiring harnesses and to provide a more flexible and efficient means of interconnecting various electronic control units (ECUs).
As the automotive industry evolved, the demand for advanced features and functionalities increased. This led to the need for a communication system that could handle the growing complexity of in-vehicle electronics. CAN Bus proved to be the ideal solution, offering a reliable and efficient means of communication.
Over time, the CAN Bus protocol gained popularity due to its reliability and simplicity. It became an international standard (ISO 11898) in 1993 and has since undergone several revisions and updates to enhance its capabilities.
Today, CAN Bus is not only used in automotive applications but also finds applications in various other industries such as industrial automation, aerospace, marine and medical devices.
Key Features of CAN Bus
CAN Bus offers several key features that contribute to its widespread adoption in various industries:
High Reliability: CAN Bus is known for its high level of reliability, making it suitable for critical applications where data integrity is crucial. The differential signalling scheme used in CAN Bus helps to minimize noise and interference, ensuring accurate data transmission.
Multi-Master Operation: CAN Bus allows multiple devices to communicate on the network simultaneously without any central controller, providing a highly flexible and decentralized system architecture. This enables efficient communication between different components of a system, enhancing overall system performance.
Real-Time Communication: CAN Bus supports real-time communication, enabling the timely exchange of data between devices. This is particularly important in applications where quick response times are required, such as in automotive systems where instant feedback is essential for safety and performance.
Robust Error Detection and Correction: CAN Bus uses a robust error detection and correction mechanism to ensure data integrity. It employs a cyclic redundancy check (CRC) algorithm to detect errors during transmission and includes error detection and error confinement mechanisms to handle errors effectively.
Scalability: CAN Bus is a highly scalable communication protocol, allowing for the addition of new devices to the network without significant modifications. This scalability makes it suitable for applications where the number of devices on the network may vary over time.
The Technical Aspects of CAN Bus
To understand how CAN Bus works, it is essential to delve into its technical aspects, including its communication mechanism, protocols, and data frames.
How CAN Bus Works
When a device wants to send a message on the CAN Bus, it checks if the bus is idle. If the bus is idle, the device begins transmitting its message. The message is received by all devices on the network and is processed based on its identifier.
During the transmission, each device compares the bits it sends with the bits it hears. If there is a mismatch, indicating a possible transmission error, the device stops transmitting and retries the message.
This decentralized, peer-to-peer communication scheme ensures that devices can transmit data independently and efficiently, without relying on a central coordinator.
In addition to its robust communication mechanism, CAN Bus also supports various features that enhance its reliability and fault tolerance. For example, it implements error detection and error correction techniques to ensure the accurate transmission of data. This allows devices to detect and correct errors, minimizing the impact of transmission issues.
Furthermore, CAN Bus employs prioritization mechanisms to manage the flow of data on the network. Each message is assigned a priority level, allowing critical messages to be transmitted with higher priority, ensuring timely delivery and reducing latency.
CAN Bus Data Frames
In CAN Bus communications, data is transmitted in frames, which consist of an identifier, a data payload, and various control and error-checking bits. There are two types of frames: data frames and remote frames.
Data frames are used to transmit actual data between devices, while remote frames are used to request data from specific devices on the network.
The structure and format of the frames are defined by the CAN protocol, ensuring compatibility and interoperability between devices from different manufacturers.
Each frame contains a unique identifier, which allows devices to identify and process the messages they receive. The identifier serves as a means of addressing, enabling targeted communication between devices.
In addition to the identifier, the data payload carries the actual information being transmitted. This payload can vary in size, depending on the specific application requirements.
To ensure the integrity of the transmitted data, CAN Bus incorporates various control and error-checking bits. These bits enable error detection and correction, ensuring the accuracy and reliability of the transmitted information.
Overall, the utilization of data frames in CAN Bus communications provides a structured and efficient approach to data transmission, allowing for reliable and secure communication between devices.
Advantages and Disadvantages of CAN Bus
While CAN Bus offers numerous benefits for a wide range of applications, it also has its limitations that need to be considered.
Benefits of Using CAN Bus
Some key advantages of utilizing CAN Bus technology include:
Reliability: CAN Bus is highly reliable, ensuring the integrity of critical data in demanding applications.
Flexibility: The multi-master operation and decentralized architecture of CAN Bus enable easy system expansion and modification.
Real-Time Communication: CAN Bus supports real-time communication, making it suitable for applications that require timely data exchange.
Cost-Effective: With CAN Bus, the need for complex wiring harnesses is reduced, resulting in cost savings during system development and maintenance.
Limitations of CAN Bus
Despite its advantages, CAN Bus does have some limitations:
Bandwidth: CAN Bus has a limited bandwidth, which may pose challenges in applications that require high-speed data transmission.
If you want to learn more, please visit our website understanding canbus.
Cable Length Limitation: The length of the CAN Bus cable is limited, and the length restriction may impose constraints on the system design.
Limited Data Payload: CAN Bus has a limited data payload size, which may restrict the amount of data that can be transmitted in a single frame.
Common uses of CAN Bus in a marine setting include J1939 and NMEA 2000.
In conclusion, CAN Bus is a powerful communication technology that has revolutionized various industries. Its reliability, real-time communication capability, and flexibility make it a preferred choice for automotive, industrial automation, and medical applications. While it offers multiple benefits, it is essential to consider its limitations and design considerations when implementing CAN Bus in a system. By leveraging the strengths of CAN Bus and mitigating its limitations, engineers can create robust and efficient communication networks for their applications.
Share this article
Control Area Network (CAN) bus is a serial communication protocol that allows devices to exchange data in a reliable and efficient way. It is widely used in vehicles, working like a nervous system to connect ECUs in the vehicle.
CAN bus was originally designed for automotive applications by Bosch in the 1980s. It is a multi-master, multi-slave, half-duplex, and fault-tolerant protocol that fits well with the requirements of automotive applications. It is simple, low-cost, and reliable and can be used in harsh environments. The CAN bus provides one point of entry for all the ECUs in the vehicle, which makes it easy to connect and diagnose.
CAN bus data can provide valuable insights into the performance and status of the connected devices. However, collecting and processing CAN bus data can be challenging due to the high data rate, low bandwidth, and variable network conditions.
One possible solution to overcome these challenges is to use MQTT, enabling timely data transmission from cars to cloud even with weak network conditions. EMQX is an open-source MQTT broker that can help you build a reliable and scalable MQTT infrastructure for collecting CAN bus data.
The Controller Area Network (CAN) bus, developed by Bosch, a German multinational engineering and technology company, originated in the early 1980s. Its primary purpose was to establish an effective communication system for automotive applications, specifically to decrease the complexity of wiring harnesses in vehicles.
In 1986, Bosch introduced their initial CAN protocol, which quickly gained momentum among auto makers due to its reliability and robustness. By 1993, it became an international standard under ISO-11898. To summarize the evolution of the protocol:
Apart from automotive applications, other industries have embraced this versatile network protocol over time. Today, it is used in industrial automation systems (CANopen) and marine electronics (NMEA 2000). Its widespread adoption is mainly attributed to its ability to operate reliably even under harsh conditions while maintaining low-cost implementation requirements.
The CAN bus is a decentralized communication protocol. Its decentralized approach makes it ideal for applications in automotive and industrial systems where reliability and real-time performance are essential.
In a CAN network, all nodes are connected via twisted-pair wiring or optical fiber cables. Each node has its own microcontroller responsible for processing incoming messages and sending outgoing ones. Data is broadcasted by a node on the shared bus, allowing all other nodes to receive it. The primary stages of the communication process are:
This combination of features allows CAN buses to maintain high levels of efficiency while ensuring reliable communication between different components in complex systems like vehicles or factory automation equipment.
The message structure in a CAN bus system is crucial for efficient communication between devices. The protocol uses a data frame format that consists of several fields, including an identifier, control field, data field, and error detection mechanism.
Here are the three main types of CAN:
Low-Speed CAN, also known as fault-tolerant or ISO 11898-3, operates at speeds up to 125 kbps. It is designed for less critical systems like body control modules, door locks, window controls, etc., where data transmission speed isn't vital. Its key feature is the ability to continue functioning even when one wire in the bus fails.
High-Speed CAN, or ISO 11898-2, can reach speeds up to 1 Mbps. This type of network is suitable for more time-sensitive applications such as engine management systems and electronic braking systems due to its faster data transfer rates compared to low-speed counterparts. However, it lacks fault tolerance capabilities found in low-speed networks.
CAN FD, introduced by Bosch in 2012, is an extension of high-speed networks with increased data rates—up to 5 Mbps—while maintaining backward compatibility with existing high-speed devices. The primary advantage of this technology lies in its ability to transmit larger payloads more efficiently than traditional CAN, making it ideal for modern vehicles with increasingly complex electronic systems.
The CAN bus data can provide valuable insights into the performance, health, and behavior of a vehicle. Collecting CAN bus data to the cloud is a powerful way to leverage the potential of vehicle data through big data analysis. By applying machine learning, artificial intelligence, or other analytical tools to the collected data from a large number of vehicles, vehicle manufacturers can gain valuable insights and leverage them to optimize vehicle performance.
In the AI era, data is the most valuable property. By collecting data from cars to the cloud and then distributing it to all kinds of data infrastructure like databases, and data lakes, users can leverage the data for nearly all kinds of applications.
Collecting CAN bus data locally on the vehicle is pretty mature. However, it can be challenging to collect and process the CAN bus data and transfer the insight to the cloud in real-time due to the high data rate, low bandwidth, and variable network conditions. Thus, it is impractical to transfer all the CAN bus data to the cloud for processing. Instead, one can collect and process the CAN bus data locally on the edge side to reduce the data volume, and transfer the insight to the cloud in real-time.
We'll need at least two components to build such a solution:
Next, we will illustrate the overall solution combining EMQX and eKuiper.
eKuiper is an open-source edge computing engine that can help you process and analyze CAN bus data in real-time. eKuiper is designed for stream processing on the edge, suitable for the real-time processing of the typical streaming data generated by the CAN bus. eKuiper can address these challenges:
Notice: Some of the features related to the CAN bus described in this document are not open source. You can experiment with these features by utilizing ek-can, which extends CAN bus capabilities on top of eKuiper.
eKuiper uses CAN source plugin to connect to CAN bus and receive CAN frames. It supports two modes to connect to CAN bus as shown in the diagram below.
CAN bus data is in binary form and organized as a frame. The CAN frame is composed of several fields. Various CAN protocols include CAN 2.0A, CAN2.0B, and CANFD. The CAN frame format is slightly different for different protocols. The CAN frame format for CAN 2.0A is shown in the figure below.
Among them, two fields are important for us to decode the CAN bus data:
In the payload, the data is organized as a series of signals. The signal is a named data item with a specific length and a specific position in the payload. DBC file is a text file that contains information for decoding raw CAN bus data to 'physical values'. It defines the signal name, length, position, and the conversion formula to convert the raw data to physical values.
In eKuiper, users can specify the DBC path to use when parsing the CAN bus data. It is pretty flexible and secure to configure the DBC in eKuiper.
After configuring the eKuiper CAN source, users can create a stream to receive the CAN bus data with physical and meaningful signals. For example, the CAN payload 0x0000000000000000
can be parsed to the following signals:
{
"signal1": 0,
"signal2": 0,
"signal3": 0,
"signal4": 0,
"signal5": 0,
"signal6": 0,
"signal7": 0,
"signal8": 0
}
Next, users can leverage the powerful eKuiper stream processing capabilities to flexibly process the parsed data just like receiving from MQTT.
After getting the parsed data, we can do a lot of things with it by eKuiper. In order to reduce the bandwidth to transfer data, we can pick the interested signals only. For example, we can pick the signals signal1
and signal2
only.
{
"signal1": 0,
"signal2": 0
}
The eKuiper SQL to do this is simple:
SELECT signal1, signal2 FROM canStream
Because CAN frame size is limited, there is a good chance that the needed signals spread around multiple CAN frames. In this case, we can flexibly composite the signals from different CAN frames to construct a complete message for applications with various algorithms according to your needs. Check the data merging example for more details. Here, we use signal1 as the main property to pick the data.
SELECT signal1, latest(signal2) as signal2 FROM canStream WHERE isNull(signal1) = false
Another example of processing is to collect the data only when some event happens. This can also significantly reduce the bandwidth. For example, we can collect the data only when the signal1 is higher than 100.
SELECT signal1, signal2 FROM canStream WHERE signal1 > 100
Moreover, these processing rules are flexible and can be changed on the fly. Don't worry if you cannot identify the needed signals at the beginning. You can change the rules to adapt to the requirement changes with hot reload.
The most mature usage is to achieve flexible data collection. Besides that, eKuiper can be used in other scenarios like:
Using an MQTT broker like EMQX for collecting CAN bus data can offer several benefits, such as:
Increased scalability: MQTT can support thousands of concurrent connections and millions of messages per second with a single broker. This can enable large-scale data collection from multiple CAN bus devices without compromising performance or reliability.
Enhanced security: MQTT supports various security mechanisms, such as TLS/SSL encryption, username/password authentication, and access control lists (ACLs), to protect the data from unauthorized access or tampering.
Besides these benefits, EMQX provides more features and together with eKuiper, it can help users save bandwidth, reduce latency, and improve reliability when transferring CAN bus data.
Rev Up Your Connected Vehicles Future with MQTT
The key to building a scalable, secure system for your connected-vehicles business.
Get the Whitepaper →To transfer CAN bus data over MQTT, we usually need to transfer through weak network conditions with limited bandwidth. In this case, we need to reduce the data size as much as possible.
In eKuiper sink, we can use the format
option to specify the data format. The default format is JSON
. We can change it to protobuf
to serialize the data into binary format to reduce the data size significantly. Additionally, we can use the compress
option to compress the data by gzip
or other compression methods. In this way, we can significantly reduce the data size compared to the original JSON data. Especially when sending the data in batch, the data size can be reduced by 90% or more in one of our test cases.
Some of the data is time sensitive for cloud applications. For example, the data to diagnose the vehicle accident is critical. In this case, we need to reduce the latency as much as possible. In eKuiper rule, we can use the MQTT sink to send the data to EMQX.
To save bandwidth in the real-time scenario, we can set the serialization format and compression method as mentioned above in eKuiper MQTT sink. In EMQX side, it provides rule engine which supports decompressing and deserializing the data. Without coding, the data can be consumed by the cloud application in real time.
For data that is not time-sensitive, we can save the data in file or local DB and send it to cloud in batch. It can achieve a higher compression rate to save even more bandwidth. In eKuiper rule, we can use file sink to save and compress data locally. It supports configuring the file rolling policy. For example, we can configure the file rolling policy to roll the file every 10 minutes. In this way, we can save the data in file in batch. EMQX is developing a new feature to support transferring the file. Once completed, the saved file can be transferred by MQTT. Currently, users can use other tools to transfer the file to cloud.
In this blog, we have introduced how to collect, process and transfer CAN bus data from vehicles to the cloud with eKuiper and EMQX. In the next blog post, we will go into more detail about each step.
Related resources
For more information, please visit sonnepowercontrol.com.