cubemx快速使用串口

STM32CubeMX学习笔记2——串口 文章目录一、打开Cube,建立工程二、系统配置三、配置串口四、在 Clock Configuration中:五、工程输出配置六、代码部分处理 MCU:STM32F103ZET6 IDE: MDK-ARM V5 +STM32CubeMX5.2.1 一、打开Cube,建立工程 图片: 点击ACCESS project from MCU 然后选择芯片类型 图片: 二、系统配置 在 Pinout&amp... 阅读详情

前言

助力于快速使用串口功能,如果想了解串口协议等知识点等请自行搜索,
这里注明串口下功能实现常用的fputc、字符串发送函数、fgetc函数等函数写法。
实验了三个例子来展示printf函数、串口中断使用、串口基本使用。

一、使用cubemx进行串口基本配置

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

二、说明

一般配置好串口我们就可以实验使用串口向上位机发送内容了,即使用板子与PC端串口调试助手或者其他设备进行信息收发。

而进行信息发送一般使用HAL库自带的发送函数HAL_UART_Transmit
另一种方法便是调用C库中的printf打印函数,而该函数是依照fputc实现的,因此需要重写该函数才可以使用printf函数。而scanf函数是依靠fgetc完成的

下面常用函数详细说明这里不做赘述,喜欢自行查阅资料
重写fputc代码

int fputc(int ch,FILE * fp)
{
   
   
 HAL_UART_Transmit(&huart1,(uint8_t * )&ch,1,0xffff);
 return ch;
}
**重写fgetc实现程序可调用scanf及getchar等函数**
int fgetc(FILE *f)
{
   
   
int ch;
/* 等待串口输入数据 */
while (__HAL_UART_GET_FLAG(&huart1, UART_FLAG_RXNE) == RESET);
HAL_UART_Receive(&huart1, (uint8_t *)&ch, 1, 0xFFFF);
return (ch)
使用cubemx快速建立一个串口通信程序 使用cubemx快速建立一个串口通信工程序言建立工程配置cubemx添加串口部分代码添加printf打印代码添加接收代码附件---》下载 序言 st官方已经停止更新标准库了,而且新出的一些芯片用到的基本也都是HAL库,因为原来在学校接触的都是标准库,直到工作以后才接触的HAL库,才知道有cubemx这个神器存在。用它建立工程简直不要太爽。接下来给大家分享一个串口通信的工程。 不解的是,我见过很多的工程师都不用cubemx的,(理由是cubemx建立的工程代码太臃肿)。也许是原来的项目用的是标准库新项目对接用 阅读详情

相关推荐

STM32CubeMX实战:快速实现USB CDC虚拟串口通信

本文详细介绍了如何使用STM32CubeMX快速配置USB CDC虚拟串口通信(Virtual Port Com),包括工程创建、USB中间件设置、代码生成与功能实现。通过实战案例和调试技巧,帮助开发者高效解决常见问题,优化性能,并扩展多虚拟串口等高级应用。

weixin_29169899的博客 345

别光看手册了!用CubeMX+Hal库快速搞定STM32F103的USB CDC虚拟串口

本文详细介绍了如何利用STM32CubeMX和HAL库快速实现STM32F103的USB CDC虚拟串口功能。通过图形化配置工具简化了传统复杂的USB协议栈开发流程,提供了从环境准备到数据收发的完整实现方案,并分享了调试优化技巧,帮助开发者高效完成嵌入式USB通信项目。

weixin_27869497的博客 399

CH438Q串口扩展芯片实战:如何用STM32CubeMX快速配置8路UART(附避坑指南)

本文详细介绍了如何使用STM32CubeMX快速配置CH438Q串口扩展芯片,实现STM32微控制器的8路UART扩展。内容涵盖硬件连接、FSMC配置、地址映射、底层驱动编写,并重点剖析了波特率配置中的常见陷阱(如“500bps幽灵”问题)以及中断处理、FIFO优化等实战技巧,旨在帮助开发者高效、稳定地集成CH438Q,解决多串口通信需求。

2y3u4i5o6p的博客 1235

别光看手册了!用CubeMX快速配置STM32F103的USB CDC虚拟串口(含代码解析)

本文详细介绍了如何使用STM32CubeMX工具快速配置STM32F103的USB CDC虚拟串口开发,包括环境搭建、关键代码解析、驱动安装与调试、性能优化及跨平台兼容性处理。通过图形化工具和代码示例,帮助开发者高效实现USB通信功能,提升开发效率。

weixin_42653691的博客 244

快速理解STM32F4 USB虚拟串口的STM32CubeMX教程流程

通过stm32cubemx教程配置STM32F4的USB虚拟串口功能,简化开发流程,提升嵌入式项目调试效率,适合初学者快速上手实战应用。

weixin_35755188的博客 589

STM32CubeMX UART串口通信详解

本文将详细介绍如何使用STM32CubeMX进行UART串口通信的配置,并提供相应的源代码示例。UART串口通信是一种异步的、基于字节的通信协议,它使用两根信号线进行数据传输:一根是用于发送数据的线路(TX),另一根是用于接收数据的线路(RX)。通过以上步骤,你可以使用STM32CubeMX轻松配置和生成UART串口通信的代码,并根据需要进行发送和接收数据的操作。注意,在实际使用中,你可能需要根据具体的需求进行一些额外的配置和调整。完成上述步骤后,你将得到一个包含串口通信配置代码的工程。

QoyOle的博客 680

STM32CubeMX(四)串口配置

摘要:本文详细介绍了USART串口通信的基础配置与实现方法。首先解析了8种通信模式(异步/同步/单线半双工等)及其适用场景,以及4种硬件流控制模式的选择策略。随后给出了具体配置步骤:设置异步模式并禁用硬件流控制,配置波特率115200/8位数据/无校验/1位停止位等通信参数,最后说明中断使能与优先级设置要点。全文为STM32串口开发提供了完整的配置参考,特别强调了不同模式的应用场景选择与中断管理的注意事项。

qq_1033275663的博客 1951

产品经理如何运用AI提升工作效率

AI技术的应用为产品经理的工作流程带来了显著的效率提升。从需求收集到产品上线,AI可以在多个阶段提供智能化支持,帮助产品经理更好地理解用户需求、优化产品设计、提高开发和测试效率。在未来,随着AI技术的不断发展,产品经理将能够更加高效地管理产品生命周期,为用户提供更优质的产品体验。应用 | AI + 千行百业欢迎关注我的后续博文,我将分享更多关于人工智能、自然语言处理和计算机视觉的精彩内容。

不想宅的冷同学 1343

Z-Image Turbo LoRA训练全流程:从数据标注到模型部署的保姆级指南(附ai-toolkit配置)

本文提供了一份详尽的Z-Image Turbo LoRA模型训练全流程指南,涵盖从数据准备、智能标注、参数调优到最终模型部署与Z-Image集成的每个环节。重点解析了使用ai-toolkit训练整合包进行高效训练的核心技巧与避坑方法,旨在帮助用户稳定训练出高质量的专属角色模型。

weixin_29088655的博客 977

告别OLE!Delphi操作Excel的3种轻量级方案横向评测(FlexCel/XLSReadWriteII/LibXL)

本文深入评测了Delphi操作Excel的三种轻量级方案:FlexCel、XLSReadWriteII和LibXL。通过技术架构、API设计、性能测试和实战案例的全面对比,帮助开发者选择最适合的工具,提升Excel文件处理效率,告别传统OLE方案的依赖和性能问题。

onion的博客 936

BES2700的PMU

BES2700ZP-BES2700芯片的PMU架构分析摘要:本文档分析了BES2700芯片的电源管理单元(PMU)架构。实际应用中仅需为VBAT引脚供电,其余电源均由芯片内部PMU提供。文档包含架构示意图、问题列表和参考链接,涉及PMU工作原理、外部供电要求等关键技术点。待解决问题包括具体供电参数和内部电源转换机制等。通过添加日志信息和代码片段,为开发人员提供了调试PMU功能的实用方法。

云淡风轻 121

学Simulink——四开关 Buck‑Boost(FSBB)变换器的无缝模式切换仿真

本文详细介绍了使用Simulink实现四开关Buck-Boost(FSBB)变换器无缝模式切换的仿真方法。FSBB变换器因其输入输出同极性、单电感和双向能量流特性,广泛应用于光伏储能、USB-PD和车载电源等场景。文章重点解决了模式切换中的直通风险和占空比跳变问题,通过统一电压PI控制、Stateflow模式仲裁和200ns死区设计,实现了Buck(26V→24V)、Pass-Through(24V±1V)和Boost(22V)三种工作模式的无缝过渡。仿真结果显示输出电压稳定在12V±0.15V,切换过程无

amy_mhd的博客 69

目标跟踪与视频时序分析基础

两帧均有目标,却因快速移动导致检测框无重叠,仅靠交并比(IoU)无法维持身份关联。本文通过手算与纯Python实现最小跟踪流程,揭示IoU仅为位置线索,不能应对快速位移或遮挡。实验表明,即使目标真实存在,低重叠也会触发新编号。强调跟踪需结合运动预测、外观特征与阈值验证,避免误判。

Mr数据杨 2339

15、Qt开发中的停靠窗口、工具栏与多文档界面实现

本文详细介绍了Qt开发中停靠窗口、工具栏与多文档界面(MDI)的实现方法。通过QDockWidget和QToolBar构建灵活的用户界面,并利用QMainWindow的saveState和restoreState功能实现布局持久化;使用QMdiArea和QMdiSubWindow实现多文档管理,结合MainWindow与Editor类完成文件操作与窗口控制。文章包含完整代码示例、流程图与表格总结,适用于开发集成环境、文本编辑器等复杂桌面应用。

snow3的博客 164

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

vb 6.0并口开发操作实例

vb6并口开发,简体中文,试例内有inpout32.dll动态链接库

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

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

上一篇: STM32 调试debug 常规使用
下一篇: 关于C语言字符串结束符使用注意事项
弦续北上i
博客等级 码龄7年 32粉丝 25原创
评论 3
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址