27、控制器局域网(CAN)与通用串行总线(USB)通信技术解析

控制器局域网(CAN)与通用串行总线(USB)通信技术解析

1. 控制器局域网(CAN)概述

CAN是一种广泛应用于汽车、工业自动化等领域的串行通信协议。在使用CAN模块时,为了避免影响 HAL_Delay 函数的精度,建议降低CAN中断优先级,因为 HAL 函数使用 SysTick 中断来创建精确的1ms滴答,而 SysTick 中断在所有外设中优先级最高。

2. CAN模块的设置
2.1 通过C++语言设置

可以借助Mbed平台及其提供的函数来调整CAN模块的属性。具体步骤如下:
1. 使用 CAN 类调整Tx和Rx引脚,需向该类提供Tx和Rx引脚名称。
2. 初始化后配置频率参数。
3. 可设置回调函数,以便在中断发生时调用。

示例代码片段如下:

CAN can(TX_PIN, RX_PIN);
can.frequency(1000000); // 设置频率为1MHz
2.2 通过MicroPython设置

MicroPython提供了 CAN 类来处理CAN操作。创建CAN模块的步骤如下:
1. 使用 pyb.CAN(bus) 函数创建CAN模块,其中 bus 表示CAN模块编号,如CAN1和CAN2。

相关推荐

汽车诊断协议核心:ISO-15031与ISO-15765的分工、协作与实战解析

在汽车电子和嵌入式系统领域,控制器局域网(CAN)总线是车载网络通信的基石,它定义了电子控制单元(ECU)间可靠、实时的数据交换机制。基于此,统一诊断服务(UDS)协议构建了一套标准化的车辆诊断语言,用于实现故障码读取、参数刷写等关键功能。其技术价值在于为复杂的汽车电子系统提供了统一的“对话”接口,极大提升了整车下线检测、售后维修和软件远程升级(OTA)的效率与可靠性。在工程实践中,UDS的诊断服务内容需要依赖ISO-15031系列标准进行具体定义,而其长报文在CAN总线上的可靠传输,则必须通过ISO-15

weixin_33721427的博客 431

27、控制器局域网与通用串行总线通信技术解析

本文详细解析了控制器局域网(CAN)和通用串行总线(USB)通信技术的基本原理、设置方法和使用方式。针对CAN,介绍了中断优先级配置、模块设置以及在STM32F4微控制器中使用不同语言(C语言、C++和MicroPython)实现CAN通信的具体方法。对于USB,探讨了其工作原理、数据传输结构,并结合STM32F4展示了USB的硬件连接和软件配置。此外,还对CAN与USB在应用场景、数据传输特性以及开发难度方面进行了对比分析。文章旨在帮助电子工程师和开发者深入了解并灵活运用这两种重要的通信技术。

grafana8visual的博客 76

27、控制器局域网(CAN)与通用串行总线(USB)通信技术详解

本文详细解析了控制器局域网(CAN)和通用串行总线(USB)两种通信技术的核心原理及应用场景。内容涵盖CAN通信的中断优先级设置、模块配置与使用(支持C/C++及MicroPython语言)、STM32F4微控制器中的CAN模块操作实例;以及USB的工作原理、数据传输模式、分层结构和典型应用场景。同时,对两种技术的特点进行了对比总结,并提供了开发建议,适用于汽车电子、工业自动化、计算机外设等领域的嵌入式系统开发。

agile9scrum的博客 93

27、控制器局域网与通用串行总线的技术解析

本文详细解析了控制器局域网(CAN)和通用串行总线(USB)的技术特点与应用场景。内容涵盖CAN模块的中断优先级设置、模块配置及在STM32F4微控制器中的使用,包括C语言、C++和MicroPython的代码示例。同时,深入探讨了USB的工作原理、通信结构、传输类型及开发步骤。最后,对CAN和USB进行了对比分析,并指出了它们在不同领域的适用场景。通过本文,读者可以全面掌握这两种通信技术的核心知识和实际应用方法。

zz67890的博客 81

27、控制器局域网与通用串行总线通信详解

本文详细介绍了控制器局域网(CAN)与通用串行总线(USB)的通信原理及在STM32F4微控制器上的实现方法。涵盖CAN中断优先级设置、过滤器配置、消息收发,以及USB的分层结构、传输类型和通信流程。通过C、C++和MicroPython的示例代码,展示了CAN模块的实际应用,并解析了USB的工作机制与开发步骤,帮助开发者掌握两种重要通信方式的核心技术与实践技巧。

p4q5r6s7t的博客 104

汽车CAN、LIN汇总

本文系统介绍汽车CAN与LIN总线协议原理、AutoSAR软件架构标准,涵盖CAN报文基础、帧种类、总线仲裁、位时序等核心技术,并提供实际测试案例与波形解析。

让你爱上电路设计 2771

死磕GMSSL通信-java/Netty系列(二)

Netty-tcnative再linux编译比较好编译,但是再window编译,我尝试了各种办法,总是编译失败,所以我采用半自动的方式进行编译,Netty-tcnative会生成临时文件,直接用vs打开,设置openssl的头文件和静态库路径,然后生成静态库,静态库改个名字放到jar包里边,其实自动编译也是这个原理哈哈O(∩_∩)O。直接传输五个证书的路径吗,之前有的是说要转成x509之类的,转来转去的有点麻烦,这个是直接传输证书路径,由底层gmssl去解析,格式必须是pem格式。然而,若项目已依赖于。

qq_36577699的博客 3024

CSV文件输入到simulink中

将示波器波形和数据CSV文件保存下来进行数据分析。将波形绘制到simulink中

yay0923的博客 5325

WRF进阶:定制Vtable文件解析非标准气象数据源——以ERA5-Land土壤湿度为例

本文详细介绍了如何为WRF模式定制Vtable文件,以解析非标准气象数据源ERA5-Land的土壤湿度数据。通过剖析GRIB文件结构、详解Vtable编写逻辑与语法,并提供了从数据验证到metgrid配置的完整实战流程,帮助用户突破标准数据源限制,实现高精度陆面过程模拟。

o4p5q6r7s的博客 390

在trae CN中使用conda环境(已解决)

Trae CN 是字节跳动于 2025 年 3 月 3 日发布的国内首个 AI 原生集成开发环境(AI IDE)123。

zwzscnds的博客 6933

ArcGIS中如何计算多个点到特定线的最短距离

现有一个点图层和一个面图层,怎么来计算这些点到这个面图层,两个面的公共边的最短直线距离呢? 1.首先得将两个图层都转为 投影坐标系 打开工具箱-数据管理工具-要素-面转线 ​ ​ 2.将面图层设为输入要素 注意要将“识别和存储面邻域信息”勾选 ​ 3.面转线成功后 打开线属性表,线图层拥有了 LEFT_FID和RIGHT_FID两个字段 ​ 4.按属性选择,表达式中输入 “LEFT_FID”<>-1 即可选出两个面的公共边 ​再将选...

GIS蒲公英的博客 6715

用PyCharm+Scrapy打造你的第一个爬虫:从安装到实战(附完整代码)

本文详细介绍了如何使用PyCharm和Scrapy框架从零开始构建高效网络爬虫。通过环境配置、项目创建、核心爬虫逻辑编写到数据处理与存储的完整流程,帮助Python开发者快速掌握爬虫开发技巧,并附有实战代码示例。特别适合想要学习Scrapy框架和提升爬虫技能的开发者。

weixin_29038345的博客 867

【Office激活】学校正版Office已激活成功仍弹出激活窗口

学校正版Office激活问题:已激活成功仍弹出激活窗口

ESCM_的博客 1万+

基于深度学习YOLOv10的障碍物检测系统

为了方便用户使用,我们将开发一个图形用户界面(GUI),允许用户上传图像或视频流并查看检测结果。我们使用PySide6开发GUI界面,它是Qt框架的Python绑定,适用于开发跨平台的桌面应用程序。本文详细介绍了如何基于YOLOv10模型构建一个障碍物检测系统,包括数据集准备、模型训练和推理到图形用户界面的开发。通过这一系统,用户可以方便地上传图像或视频流并进行障碍物检测,广泛应用于自动驾驶、机器人导航等领域。

斌擎科技 1051

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

上一篇: 23、编程开发综合指南
下一篇: 7、工业4.0与网络物理系统在制造业中的应用与发展
吃瓜不吐籽595
博客等级 码龄4年 46粉丝 1200原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值