CAN BUS

CAN BUS 原理 网上资料非常丰富,是车载系统主要BUS之一。

我们关注如下方面

  • can bus 是什么
  • 网络结构
  • CAN BUS 协议
  • ECU node
  • 实现
  • 其他

What is CAN Bus?

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.

Message Structure in the CAN Protocol

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.

  • Identifier: This unique value determines the priority of each message on the network. In standard 11-bit identifiers (CAN 2.0A), there are up to 2048 different priorities available. Extended 29-bit identifiers (CAN 2.0B) provide even more options with over half a billion distinct values.
  • Data Length Code (DLC): Located within the control field, this code specifies how many bytes are present in the data field - ranging from zero to eight bytes.
  • Data Field: Contains actual information being transmitted across nodes in byte-sized segments.
  • Cyclic Redundancy Check (CRC): A built-in error detection mechanism that ensures reliable communication by detecting transmission errors and requesting retransmission if necessary.
  • Acknowledgment Slot: A single bit used by receiving nodes to acknowledge successful receipt of messages or indicate errors requiring retransmission.
  • Error Frame: An optional part of CAN messaging that allows nodes to signal when they detect an issue with their own transmissions or received messages from other devices on the network.

Types of CAN

Here are the three main types of CAN:

Low-Speed 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

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 (Flexible Data Rate)

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.

ps:CAN Bus: How It Works, Pros and Cons, and Fast Local Processing Tutorial - DEV Community

ECU:

(收发器与控制器) 

Node design

  • Microcontroller
    • process information such as sensor inputs or outputs to turn on lights or an actuator
    • can also process information to control a dashboard or another kind of communication
  • CAN controller
    • converts digital information to messages on the bus
  • Transceiver
  • Connection to a sensor / actuator / display

对比:

ParameterSPII2CCAN
Speed3Mbps to 10MbpsStandard: 100Kbps10KBps to 1MBps Also depends upon length of wire used
Fast: 400 Kbps
Highspeed:3.4Mbps
TypeSynchronousSynchronousAsynchronous
Number of Wires3+ (MISO, MOSI, SCK, SS1, SS2…SS(n))2 wires (SDA, SCL)2 wires (CAN_H, CAN_L)
DuplexFull DuplexHalf DuplexHalf Duplex


CAN Protocol Applications

ardunio: 后续高档的板子 内置了can controller,但是否内置了tranceiver,我还要查一下:没内置can bus 部件的板子,需要外接如MCP2515 CAN Module

when the Arduino doesn’t contain any inbuilt CAN port, a CAN module called MCP2515 is used. This CAN module is interfaced with Arduino by using the SPI communication. Let’s see about more about MCP2515 in detail and how it is interfaced with Arduino.

MCP2515 CAN Module:

MCP2515 CAN Module

MCP2515 Module has a CAN controller MCP2515 which is high speed CAN transceiver. The connection between MCP2515 and MCU is through SPI. So, it is easy to interface with any microcontroller having SPI interface.

For beginners who want to learn CAN Bus, this module will act as a good start. This CAN SPI board is ideal for industrial automation, home automation and other automotive embedded projects.

Features and Specification of MCP2515:

  • Uses High-speed CAN transceiver TJA1050
  • Dimension: 40×28mm
  • SPI control for expand Multi CAN bus interface
  • 8MHZ crystal oscillator
  • 120Ω terminal resistance
  • Has independent key, LED indicator, Power indicator
  • Supports 1 Mb/s CAN operation
  • Low current standby operation
  • Up to 112 nodes can be connected

let’s see how to send humidity & temperature (DHT11) sensor data from Arduino Nano to Arduino Uno via CAN bus module MCP2515.Components Required

  • Arduino UNO
  • Arduino NANO
  • DHT11
  • 16x2 LCD Display
  • MCP2515 CAN Module – 2
  • 10k Potentiometer
  • Breadboard
  • Connecting Wires

MCP2515 Arduino Circuit Diagram:

code:

CAN Transmitter Code (Arduino Nano):#include <SPI.h>          //Library for using SPI Communication #include <mcp2515.h>      //Library for using CAN Communication#include <DHT.h>          //Library for using DHT sensor #define DHTPIN A0       #define DHTTYPE DHT11struct can_frame canMsg;MCP2515 mcp2515(10);DHT dht(DHTPIN, DHTTYPE);     //initilize object dht for class DHT with DHT pin with STM32 and DHT type as DHT11void setup() {while (!Serial);Serial.begin(9600);SPI.begin();               //Begins SPI communicationdht.begin();               //Begins to read temperature & humidity sesnor valuemcp2515.reset();mcp2515.setBitrate(CAN_500KBPS,MCP_8MHZ); //Sets CAN at speed 500KBPS and Clock 8MHzmcp2515.setNormalMode();}void loop() {int h = dht.readHumidity();       //Gets Humidity valueint t = dht.readTemperature();    //Gets Temperature valuecanMsg.can_id  = 0x036;           //CAN id as 0x036canMsg.can_dlc = 8;               //CAN data length as 8canMsg.data[0] = h;               //Update humidity value in [0]canMsg.data[1] = t;               //Update temperature value in [1]canMsg.data[2] = 0x00;            //Rest all with 0canMsg.data[3] = 0x00;canMsg.data[4] = 0x00;canMsg.data[5] = 0x00;canMsg.data[6] = 0x00;canMsg.data[7] = 0x00;mcp2515.sendMessage(&canMsg);     //Sends the CAN messagedelay(1000);}CAN Receiver Code (Arduino UNO):#include <SPI.h>              //Library for using SPI Communication #include <mcp2515.h>          //Library for using CAN Communication#include <LiquidCrystal.h>    //Library for using LCD displayconst int rs = 3, en = 4, d4 = 5, d5 = 6, d6 = 7, d7 = 8;  LiquidCrystal lcd(rs, en, d4, d5, d6, d7);  //Define LCD display pins RS,E,D4,D5,D6,D7struct can_frame canMsg; MCP2515 mcp2515(10);                 // SPI CS Pin 10 void setup() {lcd.begin(16,2);                   //Sets LCD as 16x2 typelcd.setCursor(0,0);                //Display Welcome Messagelcd.print("CIRCUIT DIGEST");lcd.setCursor(0,1);lcd.print("CAN ARDUINO");delay(3000);lcd.clear();SPI.begin();                       //Begins SPI communicationSerial.begin(9600);                //Begins Serial Communication at 9600 baudrate mcp2515.reset();                          mcp2515.setBitrate(CAN_500KBPS,MCP_8MHZ); //Sets CAN at speed 500KBPS and Clock 8MHz mcp2515.setNormalMode();                  //Sets CAN at normal mode}void loop() {if (mcp2515.readMessage(&canMsg) == MCP2515::ERROR_OK) // To receive data (Poll Read){int x = canMsg.data[0];         int y = canMsg.data[1];       lcd.setCursor(0,0);          //Display Temp & Humidity value received at 16x2 LCDlcd.print("Humidity : ");lcd.print(x);lcd.setCursor(0,1);lcd.print("Temp : ");lcd.print(y);delay(1000);lcd.clear();}}

ps:Arduino CAN Tutorial - Interfacing MCP2515 CAN BUS Module with Arduino

Arduino DUE开发板:

它内置can bus controller,但是 没有内置收发器,因此,需要连接收发器:

参见:

https://openinverter.org/wiki/CAN_bus_with_Arduino_DueCAN bus with Arduino Due - openinverter.org wiki

CAN Protocol in STM32:

ps:How to use CAN Protocol in STM32

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.xdnf.cn/news/1535977.html

如若内容造成侵权/违法违规/事实不符,请联系一条长河网进行投诉反馈,一经查实,立即删除!

相关文章

JavaScript web API part3

web API DOM 日期对象 > 得到当前系统的时间 new这个操作就是实例化 语法 const date new Date() or const date new Date(2004-11-3 08:00:00) 可以指定时间 > 可应用于通过系统时间和指定时间实现倒计时的操作 //得到当前时间const date new Date()console.lo…

HTML贪吃蛇游戏

文章目录 贪吃蛇游戏 运行效果代码 贪吃蛇游戏 贪吃蛇是一款经典的休闲益智游戏。本文将通过HTML5和JavaScript详细解析如何实现一个简易版的贪吃蛇游戏。游戏的主要逻辑包括蛇的移动、碰撞检测、食物生成等功能。以下是游戏的完整代码及注释解析。&#xff08;纯属好玩&#…

【PyQt6 应用程序】应用程序携带数据源文件一并打包

在开发好应用程序打包之后给到其他用户会发现数据文件比如封面图片不见了。 例如这样,很影响用户使用。 这里介绍一个非常简单的打包方法,不光要在打包命令的时候添加对应数据文件,在源码中也要进行一些简单的修改。 修改需要添加打包文件的地方。首先需要添加一个绝对路径…

九九乘法表-while-python

i 1 while i < 9:#j 1&#xff0c;条件为j < ij 1while j < i:print(f"{j}*{i}{i*j}\t",end)#先输出jj 1print()i 1运行结果截图&#xff1a;

超分辨率技术之插值算法

&#x1f31e;欢迎莅临我的个人主页&#x1f448;&#x1f3fb;这里是我专注于深度学习领域、用心分享知识精粹与智慧火花的独特角落&#xff01;&#x1f349; &#x1f308;如果大家喜欢文章&#xff0c;欢迎&#xff1a;关注&#x1f377;点赞&#x1f44d;&#x1f3fb;评论…

单机软件在Linux上的安装

mysql安装 5.7版本 mysql的程序在centos官方的库中是没有的&#xff0c;需要切换到淘宝的镜像&#xff0c;这个前面有教程或者配置mysql的源 yum -y install rpm rpm --import https://repo.mysql.Com/RPM-GPG-KEY-mysqL-2022 rpm -Uvh http://repo.mysql.com//mysql57-commun…

Linux基础---08软件的安装

安装方式优缺点编译安装自由定制&#xff0c;但较为繁琐rmp安装安装简单&#xff0c;但需要自己解决依赖&#xff0c;不支持定制yum安装自动解决rmp依赖&#xff0c;但不支持定制&#xff08;用的更多&#xff09; 下面就具体介绍三大安装方式&#xff1a; 一.编译安装 用Li…

IBM撤出中国区相关研发工作 裁员规模超千人

经济观察网 记者 钱玉娟 8月26日上午10点半&#xff0c;IBM中国举行了一场只有3分钟的全员会。IBM全球企业系统开发部副总裁Jack Hergenrother在会上宣布&#xff0c;IBM基础设施决定撤出IBM中国系统中心&#xff08;CSL&#xff09;与IBM中国开发中心&#xff08;CDL&#xff…

热门数据恢复软件大盘点

现在大家的数据都喜欢存放在一些电子设备里保存吧。这样既方便存放&#xff0c;也方便我们查找。但是这些设备可能因为病毒、误删除等原因造成数据的丢失。这篇文章我将介绍几款类似易我数据恢复软件的数据恢复工具&#xff0c;减少为数据丢失给我们造成损失。 1.FOXIT数据恢复…

3. Python计算水仙花数

Python计算水仙花数 一、什么是水仙花数&#xff1f; 百度答案 二、怎样使用Python计算水仙花数&#xff1f; 这里需要for循环&#xff0c;if判断&#xff0c;需要range()函数&#xff0c;需要知道怎么求个位数&#xff0c;十位数&#xff0c;百位数… 1. For循环 语句结…

通信工程学习:什么是SNI业务节点接口

SNI&#xff1a;业务节点接口 SNI业务节点接口&#xff0c;全称Service Node Interface&#xff0c;是接入网&#xff08;AN&#xff09;和一个业务节点&#xff08;SN&#xff09;之间的接口&#xff0c;位于接入网的业务侧。这一接口在通信网络中扮演着重要的角色&#xff0c…

智慧农业数据集(一)

目录 葡萄叶片病虫害害数据集 茄子果实病虫害数据集 81类水果数据集 小麦叶片病虫害数据集 番茄叶片病害数据集 草莓叶片病虫害数据集 水稻叶片病虫害数据集 菠萝成熟度数据集 10类水果数据集 棉花叶片病虫害数据集 棉花成熟度数据集 柑橘叶片病虫害数据集 苹果新…

离谱碾压!奇安信中标:高出第二名近70分!

2024年08月09日&#xff0c;广东省政务服务和数据管理局&#xff0c;近日发布了网络安全第三方服务&#xff08;2024年&#xff09;项目之关基检查及重要政务应用安全检查服务招标公告&#xff01; 预算金额&#xff1a;2,896,200.00元&#xff0c;其中安全检查服务包&#xf…

网络原理2-网络层与数据链路层

目录 网络层数据链路层 网络层 网络层做的工作&#xff1a; 1、地址管理–>IP地址 2、路由选择–>数据包传输的路径规划 网络层主要的协议就是IP协议 IP协议的报头结构&#xff1a; 4位版本&#xff1a; 有两个取值&#xff0c;4表示IPv4&#xff0c;6表示IPv6&am…

【DVWA】——File Upload(文件上传)

&#x1f4d6; 前言&#xff1a;文件上传漏洞是由于对上传文件未作过滤或过滤机制不严&#xff08;文件后缀或类型&#xff09;&#xff0c;导致恶意用户可以上传脚本文件&#xff0c;通过上传文件可达到控制网站权限的目的。 目录 &#x1f552; 1. Low&#x1f552; 2. Mediu…

嵌入式单片机程序运行基本机理

1. 程序各种要素说明 大家好,今天用一个最简单的程序跟大家讲清楚程序的构成。 1.1. 概述 硬件首先要知道硬件的组成。 在前面章节我们说过,芯片包含Flash和RAM。 他们虽然不是相同的东西,但是都属于同一个地址空间,32位芯片的地址空间大小是4G。 比如ST32,FLASH通常从…

[云服务器10]使用alist搭建云盘系统

hello大家好啊&#xff0c;今天为大家带来的是使用alist搭建一个网盘系统&#xff01; 首先我们得明确&#xff0c;人家阿里云盘&#xff0c;百度云盘都是存了PB级的数据&#xff0c;然后我大概算了一下&#xff0c;成本约为 2 554 880 2\space554\space880 2 554 880RMB每个月…

3.1 通信协议

通信协议 通信的目的&#xff1a;将一个设备的数据传送到另一个设备&#xff0c;扩展硬件系统 通信协议&#xff1a;制定通信的规则&#xff0c;通信双方按照协议规则进行数据收发 全双工&#xff1a;发送与接收互不影响 (如串口通信有两根数据线 tx,rx) 半双工 &#xff1…

155K Star,Python 入门到进阶最佳学习资源

Hi&#xff0c;骚年&#xff0c;我是大 G&#xff0c;公众号「GitHub 指北」会推荐 GitHub 上有趣有用的项目&#xff0c;一分钟 get 一个优秀的开源项目&#xff0c;挖掘开源的价值&#xff0c;欢迎关注。 导语 如果你正在寻找一个全面、系统、深入的 Python 学习项目&#…

CSP-CCF★★★201903-2二十四点★★★

目录 一、问题描述 二、解答 方法一&#xff1a;穷举法&#xff08;只列举了一部分&#xff09; 方法二&#xff1a;中缀表达式直接求值&#xff0c;两个栈&#xff0c;一个存放数值&#xff0c;一个存放符号 方法三&#xff1a;将中缀表达式转换为后缀来计算注意&#xff…