使用中断方法实现UART不定长数据接收

详解STM32CubeIDE 中 HAL库的串口中断接收函数 HAL_UART_Receive_IT MX串口配置方法见:CubeIDE 利用自带HAL库 串口收发 一、代码自动生成以后的项目及代码结构: main.c中,调用了串口初始化 串口初始化函数赋值了串口的参数 相当于底层的初始化,配置引脚、并开启中断。 至此串口1配置完毕 二、库文件stm32f1xx_hal_uart.c内的秘密 2.1初始化 1.usart.c中,MX_USART1_U... 阅读详情
AI摘要

本文介绍如何使用STM32F411RE通过UART2实现不定长数据的中断接收方法。文中详细解释了HAL库中UART模块的配置过程及关键函数HAL_UART_Receive_IT的工作原理,并提供了一个具体的代码实例。

使用中断方法实现UART不定长数据接收


硬件平台:NUCLEO-STM32F411RE

基础知识

嵌入式开发中,UART串口通信协议是我们常用的通信协议之一,全称叫做通用异步收发传输器(Universal Asynchronous Receiver/Transmitter)。
基本原理:
在这里插入图片描述
常见数据结构:
在这里插入图片描述

CubeMx配置

硬件平台:STM32F411RE-NUCLEO
UART参数:
在这里插入图片描述
这里是用UART2进行数据接受发送
打开UART并设置波特率等:
在这里插入图片描述
打开中断:
在这里插入图片描述

函数说明

1、HAL_UART_Receive_IT和HAL_UART_Receive的区别就是:中断接收是有数据到了才去读;直接接收是直接读取,如果超时就返回

2、HAL_UART_Receive_IT配置后,有数据来,计数会在调用中断函数之后自动减1。只有到计数为0时,才会关闭中断并调用回调函数。至此有数据来不再调用中断函数,因为中断已经失效。

HAL_UART_Transmit
Function name

HAL_StatusTypeDef HAL_UART_Transmit (UART_HandleTypeDef * huart, uint8_t * pData, uint16_t Size, uint32_t Timeout)

Function description:
Sends an amount of data in blocking mode.

Parameters:
• huart: Pointer to a UART_HandleTypeDef structure that contains the configuration information for the specified UART module.
• pData: Pointer to data buffer (u8 or u16 data elements).
• Size: Amount of data elements (u8 or u16) to be sent
• Timeout: Timeout duration

Return values
• HAL: status

Notes
• When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01), the sent data is handled as a set of u16. In this case, Size must indicate the number of u16 provided through pData.

HAL_UART_Receive

HAL库中断方式进行串口通信 文章目录前言一、通过CubeMX配置项目1.设置RCC2.设置SYS3.设置USART4.设置NVIC5.创建项目二、在keil配置代码1.打开通过CubeMX生成的项目2.在main函数前定义全局变量3.在main函数中设置接收中断4.main函数中的while循环里面添加传输代码5.在main函数下面重写中断处理函数6.main函数全部代码7.编译并烧录三、效果四、参考 前言 软件版本: STM32CubeMX:6.30 KEIl:5.31 FlyMcu:0.188 SSCOM 阅读详情

相关推荐

单片机HAL库使用HAL_UART_Receive_IT

前言 由于本人第一次尝试开发单片机,要实现的功能是信息转发,需要调用HAL库方法,中断接受信息转发给FPGA,这里没有用到DMA方式所以不做赘述,特此记录分享希望帮到你们。 发送信息和中断接受流程 发送 轮询等待方式发送消息Timeout超时返回,调用的这个方法发送数据发现只能发送一个字节8位的数据,发送大于一个字节数数组时会产生问题,拿示波器抓也只有第一个字节有效,其余都是错的,着实被这个浪费了很多时间,后来选择了第二种发送方式 HAL_StatusTypeDef HAL_UART_Tra

sunxiaoyan的博客 1万+

STM32CubeMX笔记(8)--使用DMA+IDLE串口空闲中断接收不定长度的数据(UART1接收数据)+数据解析

使用DMA+IDLE串口空闲中断接收不定长度的数据(串口1)1、STM32CubeMX引脚设置和代码生成2、编写相关中断的C文件1、在uart.c,增加相关代码2、在uart.h,增加相关代码3、在stmf1xx_it.c,增加相关代码4、在main.c,增加相关代码3、编译工程文件,使用ST-Link烧录,测试串口数据DMA+IDLE空闲中断的接收 1、STM32CubeMX引脚设置和代码生成 该次实验的引脚设置与 《STM32CubeMX笔记(7)–使用DMA串口发送数据,UART1发送数据》的引脚设

杰尼君的博客 1242

STM32CubeMX实战:串口空闲中断与DMA接收的高效数据通信方案

本文详细介绍了在STM32项目中,如何利用STM32CubeMX高效配置串口空闲中断与DMA接收的组合方案。该方案通过DMA自动搬运数据,仅在检测到串口总线空闲时触发一次中断通知CPU,实现了“CPU零打扰”的高效数据通信,特别适合处理传感器数据包等不定长数据帧,能显著降低CPU负载并提升系统响应能力。

weixin_29179311的博客 624

JAVA审批流程,一个简单表结构设计方案By OU

一、表结构设计1.流程表(process)用于存储审批流程的基本信息。字段名类型描述idBIGINT主键,流程IDname流程名称TEXT流程描述DATETIME创建时间DATETIME更新时间statusTINYINT(1)流程状态(0: 停用, 1: 启用)2.节点表(process_node)用于管理流程中的每个审批节点。字段名类型描述idBIGINT主键,节点IDprocess_idBIGINT流程ID,外键关联process.id。

1906

SAP高级外币评估_FINS_FXV_S4 2022 OP

摘要:S/4HANA 2022 On-Premise中的高级外币评估(FINS_FXV)取代了经典外币估值(FAGL_FCV),提供更优化的财务结算功能。主要创新包括:增量发布逻辑、简化账户配置、行项目级估值可见性等。该功能支持IFRS9等会计准则,通过会计原则(Accounting Principle)进行配置,需完成财务报表版本定义、语义标记分配等必要设置。系统演示展示了从汇率维护(FB60/MIRO)、测试运行到最终过账(FB03)的完整流程,能自动计算并过账汇率差异。高级外币评估简化了期末结算操作,

yanzibing99的博客 1276

DEM边界数值爆炸?用ArcGIS空间分析工具链搞定异常值过滤全流程

本文针对DEM数据处理中常见的边界数值爆炸问题,提供了一套完整的ArcGIS空间分析解决方案。文章深入剖析了异常值产生的根源,并详细介绍了从诊断、定位到使用栅格计算器、重分类等工具进行精准过滤与修复的全流程工作流,帮助用户彻底解决由插值误差、数据拼接及坐标系转换引发的数值异常。

weixin_29269441的博客 151

10BASE-T1S协议中的PLCA机制:实现无碰撞网络传输的关键

本文深入解析了10BASE-T1S协议中的PLCA(物理层冲突避免)机制。作为IEEE 802.3cg标准的关键部分,PLCA通过循环调度与机会传递,从根源上避免了网络碰撞,为工业与汽车等场景提供了确定性的低延迟传输保障,是实现可靠实时通信的核心技术。

weixin_29250403的博客 221

沧小海深入剖析xilinx的GTP/GTX核,掌握高速串行收发机制——第六章 接收端结构及功能说明

总目录在这哦~ https://blog.csdn.net/z123canghai/article/details/107700878 第六章 接收端结构及功能说明 子目录 6.1 RX的模拟前端 6.2 RX的OOB信号 6.3 RX的均衡器 6.4 RX的CDR 时钟数据恢复 6.5 RX时钟输出结构 6.6 RX 的极性控制 6.7 RX 的PRBS 6.8 Rx字节、字的对齐功能 6.9 Rx接收弹性缓冲区 6.10 Rx的时钟纠正 6.11 Rx接收通道绑定 6...

滄海的博客 1万+

【护网行动-红蓝攻防】第一章-红蓝对抗基础 认识红蓝紫

军事上的演练,是除了实战以外最能检验军队战斗力的一种考核方式,他可以模拟面对外部势力的攻击时候,如何更好的去维护国家和主权的安全。同样的,在网络上面,真实环境下的网络攻防演练也是检验一个单位,企业网络防御能力,发现潜在危险最好的方法。1.政策要求2安全威胁驱动当前,我国关键信息基础设施面临的网络安全形势严峻复杂,网站平台大规模数据泄露事件频发,生产业务系统安全隐患突出,甚至有的系统长期被控面对高级持续性的网络攻击,防护能力十分欠缺。目前,我国面临的网络安全威胁主要有以下几点。

wxh的博客 1586

5G R18标准:AI/ML如何重塑空口优化与网络架构

人工智能与机器学习正逐步成为通信网络优化的核心技术。其核心原理在于通过数据驱动模型,从海量网络数据中学习信道变化、用户行为等统计规律,替代传统的基于固定规则的优化方法。这一技术范式能显著提升网络性能与效率,尤其在空口资源管理、干扰协调和能耗控制等场景中价值突出。在5G Advanced(R18)标准化框架下,AI/ML被系统性地引入空口设计,聚焦于信道状态信息反馈增强、波束管理与预测等关键用例。通过定义网络侧AI、终端侧AI及联合学习的标准化接口与流程,R18旨在实现跨厂商设备的智能协同,推动无线网络向自适

weixin_35671843的博客 258

【YOLOv11改进- 主干网络】YOLOv11+WTConv(ECCV2024): 基于YOLOv11的主干网络改进,大感受野的小波卷积

论文提出了WTConv,这是一个使用级联小波分解的层,并执行一组小卷积核的卷积,每个卷积专注于输入的不同频率带,并具有越来越大的感受野。这个过程能够在输入中对低频信息给予更多重视,同时仅增加少量可训练参数。实际上,对于一个  的感受野,可训练参数数量只随着  的增长而呈对数增长。而WTConv与常规方法的参数平方增长形成对比,能够获得有效的卷积神经网络(CNN),其有效感受野(ERF)大小前所未有。

qq_41304809的博客 1427

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

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

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

上一篇: 【已解决】STM32进入UART串口中断出不来
下一篇: STM32通过I2C控制LCD1602显示
Ceder1c
博客等级 码龄7年 268粉丝 44原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址