使用stm32cubeMX进行串口DMA收发

【STM32+cubemx】0006 HAL库开发:uart串口和DMA传输 上一节我们使用中断结合环形fifo,实现了比较方便、高效地串口收发,这个方法在几乎所有的单片机上都可以使用,就连最基础的51单片机也能支持。而到了stm32这款强大的单片机,有更多的用法可以实现高效的串口收发,本节我们就介绍使用DMA传输串口数据。 先简单介绍一下DMA,DMA全称为:Direct Memory Access,即直接存储器访问。它可以独立地将数据从一个地址空间复制到另外一个地址空间,而不占用CPU的资源。 DMA尤其在高速、大容量的数据传输时特别有用:如果使用中断传输,CPU会在传输 阅读详情

一、DMA的基本介绍

DMA,全称Direct Memory Access,即直接存储器访问。
DMA用来提供在外设和存储器之间或者存储器和存储器之间的高速数据传输。无须CPU的干预,通过DMA数据可以快速地移动。这就节省了CPU的资源来做其他操作。
具体关于DMA的介绍请看参考博客内容;

二、使用cubeMX创建DMA

1)创建工程

首先打开stm32cubeMX,点击新建工程,选择好芯片,我这里选择的是stm32f103c8,选择好后双击打开即可;
①时钟设置
点击RCC,设置高速外部时钟HSE 选择外部时钟源;
在这里插入图片描述
②设置串口
点击 Connectivity选择USART1串口,将Mode设置为异步通信,可见波特率为115200Bit/s,数据长度为8Bits等参数,以及芯片上的GPIO端口也设置成了对应的形式;
在这里插入图片描述
接下来还需要对NVIC Settings设置中断,如下:

STM32CubeMX配置串口DMA传输实现不定长数据收发 STM32通过串口的IDLE空闲中断来实现串口的不定长数据收发。 阅读详情

相关推荐

【基于STM32CUBEMX STM32F411CEY6TR单片机实现串口DMA的收发】

如果你想学习如何使用Markdown编辑器, 可以仔细阅读这篇文章,了解一下Markdown的基本语法知识。主要是重写了一个回调函数 USAR_UART_IDLECallback,新增一个函数处理接收到的数据。声明回调函数和发送函数,并将接收数据的数组外接出来。

weixin_46146080的博客 981

STM32CubeMX HAL库串口+DMA数据发送不定长度数据接收,解决第一笔数据无法收发问题

STM32 实现使用Command自动进入USB DFU的功能 目的: 为了实现方便的进入DFU模式,快速更新固件,所以想使用备份区域的寄存器作为标志来判断是否要进行DFU模式. 使用工具: STM32CubeMX 6.01 生成代码 DfuSe V3.0.6 DFU驱动 STM32虚拟COM端口驱动程序 在App端需要用到USB虚拟串口来发送进入DFU的指令 编译工具可以使用IAR或KEIL,依照个人习惯,本文使用KEIL 5 DFU代码生成: STM32CubeMX部分: 打开STM32C

开发 3536

STM32 cubemx配置USART DMA传输

本篇文章来讲解DMA的概念,并使用DMA来进行串口的数据收发。下面我们来看到DMA的两种模式,一种是循环模式,一种是内存到内存的模式。在循环模式下,DMA传输的数据可以在源和目的地之间循环传输,以连续地进行数据传输操作。这种模式下,一旦DMA传输完成,它会自动重新开始下一轮传输,而无需软件干预。循环模式对于需要在连续数据块之间进行重复传输的应用非常有用,如音频、视频流等。它可以在不中断DMA传输的情况下循环传输数据,大大提高了数据传输效率和系统性能。

m0_49476241的博客 7738

STM32L0xx基于CubeMX的UART+DMA高效数据接收实战

/ 清零DMA_CCR_EN | // 使能通道DMA_CCR_DIR_0 | // 方向:外设 → 内存DMA_CCR_MINC | // 内存地址递增DMA_CCR_PSIZE_0 | // 外设数据宽度:8位DMA_CCR_MSIZE_0 | // 内存数据宽度:8位DMA_CCR_TCIE | // 使能传输完成中断// 使能半传输中断逐行解析:DMA_CCR_EN:启动DMA通道,必须最后设置。DIR=01表示外设为源,内存为目标。DMA_MINC。

weixin_42160645的博客 1152

MATLAB Appdesigner开发独立桌面App全流程(一):以打开串口功能为例介绍Appdesigner的基本使用

本文详细介绍了Appdesigner的基本使用,以串口功能为例介绍按钮回调函数的实现以及控件之间通信的问题

Zhuwany的博客 3万+

51单片机也能玩转信号发生器?手把手教你用DAC0832和LM358输出四种标准波形

本文详细介绍了如何使用51单片机和DAC0832芯片搭配LM358运放,自制低成本信号发生器,实现正弦波、矩形波、三角波和锯齿波四种标准波形的输出。从硬件选型、电路设计到编程实现,手把手教你完成这一实用电子项目,总成本不到50元,适合电子爱好者和学生实践。

weixin_30530939的博客 548

6.4 实战项目:基于Agent内核构建Code Review智能体

本文介绍了一个基于Agent内核构建的智能Code Review系统实战项目。系统采用多Agent协作架构,包含代码质量分析、安全漏洞识别、性能优化建议等核心功能模块。文章详细展示了系统架构设计,采用协调器Agent管理多个专业Agent协同工作,并提供了基础Agent框架和协调器Agent的TypeScript实现代码。项目结合了AI Agent核心原理和多Agent协作机制,实现了自动化的代码审查流程,能够生成详细的审查报告,帮助开发者提升代码质量和安全性。

yonggeit的博客 3091

作物生长模型Oryza V3实战10:运行文件参数详解

运行文件(.rer)用于批量模拟农业场景,包含多组参数集(Rerunset),每组设定独立的时间范围、灌溉施肥方案等,支持测试不同农艺措施效果。该文件可实现参数自动校准,通过多组参数组合迭代寻找最优值。模拟结果文件(res.dat)会记录全部测试时间段的数据,便于用户对比产量、水分利用率等指标,筛选最优方案或分析气候适应性策略。

205

Qt视频播放器项目(打开文件,视频的播放与停止,进度条与视频进度绑定,调整音量,设置按钮图标,将槽函数与按钮绑定等功能)完整代码地址在末尾

【代码】Qt视频播放器项目。

分享计算机视觉,C++,网络摄像头研发,音视频开发,嵌入式等知识。 742

9.9华为OD机试真题 新系统 - 受限任务分配 (Java/Py/C/C++/Js/Go)

华为OD机试真题 新系统【受限任务分配】,提供C语言、Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解,以及在线OJ模拟做题。华为OD机试真题 【受限任务分配】多语言题解。

qq_45776114的博客 695

磁环电感参数计算

电感饱和是指当电感中的电流超过一定阈值时,电感中的磁场无法继续增加,而是达到一个饱和状态,导致电感的感应电动势减小或消失。电感通常由线圈组成,当通过线圈的电流不断增加时,线圈内部的磁场也随之增加。然而,当电流达到一定程度时,线圈的铁芯磁化达到饱和,无法进一步增加磁场强度。电感饱和的阈值取决于电感的结构、材料和尺寸等因素。通常情况下,电感的额定电流会标明其饱和电流值。一旦电感中的电流超过了饱和电流,电感将饱和并出现异常行为。当我们谈论电感饱和的时候,实际上是在谈论磁芯饱和——空心的电感永远不会饱和。

小幽余生不加糖 4020

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

深度学习工具包 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")

上一篇: STM32CubeMX使用串口中断方式实现串口通信
下一篇: 点阵汉字的字模读取与显示
奔赴美好未来
博客等级 码龄5年 59粉丝 21原创
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值