CAN BUS

news2024/11/15 4:52:36

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 DHT11


struct 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 DHT11


void setup() 

{

  while (!Serial);

  Serial.begin(9600);

  

  SPI.begin();               //Begins SPI communication

  dht.begin();               //Begins to read temperature & humidity sesnor value

  

  mcp2515.reset();

  mcp2515.setBitrate(CAN_500KBPS,MCP_8MHZ); //Sets CAN at speed 500KBPS and Clock 8MHz

  mcp2515.setNormalMode();

}


void loop() 

{

  int h = dht.readHumidity();       //Gets Humidity value

  int t = dht.readTemperature();    //Gets Temperature value


  canMsg.can_id  = 0x036;           //CAN id as 0x036

  canMsg.can_dlc = 8;               //CAN data length as 8

  canMsg.data[0] = h;               //Update humidity value in [0]

  canMsg.data[1] = t;               //Update temperature value in [1]

  canMsg.data[2] = 0x00;            //Rest all with 0

  canMsg.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 message

  delay(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 display


const 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,D7


struct can_frame canMsg; 

MCP2515 mcp2515(10);                 // SPI CS Pin 10 

 

void setup() {

  lcd.begin(16,2);                   //Sets LCD as 16x2 type

  lcd.setCursor(0,0);                //Display Welcome Message

  lcd.print("CIRCUIT DIGEST");

  lcd.setCursor(0,1);

  lcd.print("CAN ARDUINO");

  delay(3000);

  lcd.clear();

  

  SPI.begin();                       //Begins SPI communication

  

  Serial.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 LCD

      lcd.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.coloradmin.cn/o/2138400.html

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

相关文章

MySQL:视图【详解】

1、视图 1.1 视图的定义 视图是在数据库中定义的虚拟表。它是一个基于一个或多个实际表的查询结果集&#xff0c;可以像实际表一样被查询和操作。视图可以看作是一个动态生成的数据表&#xff0c;其内容是从其他表中选择、过滤和计算得到的。 视图通过使用SQL查询语句来定义…

Framebuffer应用编程

目录 前言 LCD操作原理 涉及的 API 函数 open函数 ioctl 函数 mmap 函数 Framebuffer程序分析 源码 1.打开设备 2.获取LCD参数 3.映射Framebuffer 4.描点函数 5.随便画几个点 上机实验 前言 本文介绍LCD的操作原理和涉及到的API函数&#xff0c;分析Framebuffer…

配置全新服务器深度学习一套流程

目录 1.安装anaconda2.配置cuda3.配置cudnn4.配置新的pytorch环境5.安装rdkit包6.小问题记录 1.安装anaconda 直接参考视频 总结&#xff1a; 1.下载anaconda安装包&#xff0c;尽量不下载最新的版本 2.bash 对应安装包&#xff0c;一直回车&#xff0c;yes 3.配置环境vim ~/.…

点餐小程序实战教程10权限验证

目录 1 创建员工的全局变量2 创建员工首页3 跳转到员工首页4 给全局变量赋值5 验证权限6 登录的完整代码总结 我们已经实现了员工的注册及登录功能&#xff0c;登录成功后需要跳转到我们的员工首页。在首页加载的时候我们需要去验证当前用户是否已经登录&#xff0c;未登录我就…

深入理解数据分析的使用流程:从数据准备到洞察挖掘

数据分析是企业和技术团队实现价值的核心。 5 秒内你能否让数据帮你做出决策&#xff1f; 通过本文&#xff0c;我们将深入探讨如何将原始数据转化为有意义的洞察&#xff0c;帮助你快速掌握数据分析的关键流程。 目录 数据分析的五个核心步骤1. 数据获取常用数据获取方式 2. 数…

synchronized的详解、锁的升级过程和优缺点比较

本文 详细介绍Java中为了减少获得锁和释放锁带来的性能消耗而引入的偏向锁和轻量级 锁、重量级锁&#xff0c;以及锁升级过程。 Java中每一个对象都可以作为锁。具体表现形式为以下三种形式&#xff1a; 对于普通的同步方法&#xff0c;锁是当前的实例对象对于静态同步方法&a…

攻防世界--->秘密-银河-300

做题笔记。 适用于reverse的隐写术。。。。啊哈哈哈哈 下载 查壳。(用的WSL->Debian) 64ida打开。 运行程序如下&#xff1a; 反汇编看不出来什么名堂&#xff0c;那就去看汇编代码。 下个断点。 东看看西看看 这是我们程序打印代码 往下翻&#xff1a; SECRET 秘密。 我…

路径规划 | 基于A*算法的往返式全覆盖路径规划的改进算法(Matlab)

目录 效果一览基本介绍程序设计参考文献 效果一览 基本介绍 基于A*算法的往返式全覆盖路径规划的改进算法 matlab实现代码 往返式全覆盖路径规划&#xff0c;通过建立二维栅格地图&#xff0c;设置障碍物&#xff0c;以及起始点根据定义往返式路径规划的定义的优先级运动规则从…

网页本地存储

网页本地存储 <html> <script>//添加数据function add(){var text;textdocument.getElementById(text).value;indexlocalStorage.length1;localStorage.setItem(index,text);}//显示localStorage所有内容function showall(){storagelocalStorage;var length stor…

209.长度最小的子数组(滑动窗口类)

文章目录 209.长度最小的子数组滑动窗口904. 水果成篮76. 最小覆盖子串 209.长度最小的子数组 209.长度最小的子数组 给定一个含有 n 个正整数的数组和一个正整数 s &#xff0c;找出该数组中满足其和 ≥ s 的长度最小的 连续 子数组&#xff0c;并返回其长度。如果不存在符合…

2020ICPC上海 D - Walker M - Gitignore

D: 首先显然要二分,判断当前二分的mid时间下是否能满足走满0~n 枚举所有情况,这里按照左,右起点p1,p2分别讨论 p1向左 p2向左(以下向左和向右都代表向左或者向右到墙,而不代表初速度方向)&#xff0c;只需要计算p1或者p2反弹之后还能走距离n就是合法 p1向左 p2向右&#xff…

C++在Linux实现多线程和多进程的TCP服务器和客户端通信

多进程版本 服务器 #include <arpa/inet.h> #include <stdlib.h> #include <stdio.h> #include <string.h> #include <unistd.h> #include <sys/socket.h> #include <sys/wait.h> #include <signal.h> #include <string&…

软件设计师——程序设计语言

目录 低级语言和高级语言 编译程序和解释程序 正规式&#xff0c;词法分析的一个工具 有限自动机 ​编辑 上下文无关法 ​编辑 中后缀表示法 杂题 ​编辑 低级语言和高级语言 编译程序和解释程序 计算机只能理解由0、1序列构成的机器语言&#xff0c;因此高级程序设计…

CAD_Electrical 2022使用记录

一、CAD软件实用调整 1、如何调节窗口背景颜色 例如&#xff1a;将图中白色的背景色调节为黑色。 步骤&#xff1a;在CAD空白区域点击右键 -> 点击选项 -> 在显示中点击颜色(窗口元素) -> 将二维模型空间统一背景的颜色修改成需要的颜色 2、如何调节关标大小 例如&a…

IP纯净度对跨境电商有哪些影响

在全球化贸易的浪潮中&#xff0c;跨境电商凭借其打破地理界限的能力&#xff0c;成为推动国际贸易的重要力量。然而&#xff0c;跨境电商的运营并非没有挑战&#xff0c;其中IP纯净度是影响其成功的关键因素之一。本文将探讨IP纯净度对跨境电商运营的多方面影响&#xff0c;并…

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

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

2024/9/15 408“回头看”之应用层小总结(下)

域名系统DNS: 本地域名服务器 本地域名服务器起着代理的作用&#xff0c;会将报文转发到根域名服务器、顶级域名服务器、权限域名服务器。 递归查询&#xff1a; 迭代查询&#xff1a; 文件传送协议FTP: FTP客户和FTP服务器之间使用的是tcp连接。 控制连接使用21端口&…

长业务事务的离线并发问题

事务指代一组操作同时成功或同时失败&#xff0c;事务可分为两类&#xff1a; 系统事务&#xff1a;即关系数据库事务&#xff0c;一次数据库连接中由start transaction或begin开启&#xff0c;commit表示提交&#xff0c;rollback表示回滚&#xff1b;业务事务&#xff1a;完…

海外VS国内:网安上市公司人均创收对比

二级市场分析章节中分析了中国网络网络安全上市公司人均创收63.2万、人均毛利37.6万&#xff0c;人均创利-1.6万。 有网友问了&#xff1a;海外网络安全公司的人均情况如何&#xff1f;那么让我们一起看看吧。 我们统计了在海外上市的28家主要网络安全公司的2023年的人均情况&…

Python互相关统计学 地震学 心理学 数学物理和算法模型及数据科学应用

&#x1f3af;要点 同步时间序列数据地震时频域信息绘制地震噪声干涉图和频谱计算光变曲线和时滞互相关光变曲线并计算峰值和质心图像几何对应关系算法气候相关矩阵图测量麦克风间距离图像相似性量化及显着性统计测试个体同步性量化分析计算绘制有无泊松噪声的光曲线地震幅度和…