怎样在TI stellaris lm3sxxx 程序中使用C语言printf()函数进行串口输出

PRINTF函数通过UART串口输出显示 printf函数是一个格式化输出函数,可以通过输出流(如文件、屏幕或串口)将格式化的输出发送到指定的目标。在此情况下,你可以使用printf函数通过串口输出信息,方法是指定串口为输出流,然后调用printf函数。 例如,在C语言中,可以使用以下代码将信息输出到串口: #include <stdio.h> int main(void) { // 打开串口 FILE *s... 阅读详情

如题,C语言printf()函数因其丰富的格式成为很多入门者使用频率最高的一个function。
在使用单片机进行串口调试的时,很多人希望可以使用printf()函数,要在单片机使用printf()函数很简单,步奏如下:

1、在要使用的 xxx.c(或者main.c)文件中添加如下代码:

int fputc(int ch, FILE *f)
{
  /* Place your implementation of fputc here */
  /* e.g. write a character to the USART */
  UARTCharPut(UART1_BASE, (char)ch);

  return ch;
}
2、并在文件开始包含头文件。

#include <stdio.h>

这样一来,便可以调用printf函数,进行各种想要的格式输出,缩短开发调试时间。
避开STM32中断优先级配置的坑:HAL_NVIC_SetPriority()参数你真的用对了吗? 本文深入解析STM32中断优先级配置中的关键问题,重点剖析HAL_NVIC_SetPriority()函数的正确使用方法。通过实际案例揭示优先级分组设置、抢占优先级与子优先级的区别,提供多中断系统中的优化策略和调试技巧,帮助开发者避免常见配置错误,提升系统稳定性。 阅读详情

相关推荐

DSP:重新定向 printf 输出到串口

近期调试24GHz毫米波雷达,处理器为DSP,边学习边写代码,网上也摘录些小笔记,以便理解跟巩固。 from TI中文社区:http://processors.wiki.ti.com/index.php/Tips_for_using_printf Using printf() to output to a user-defined device You can install a user-...

Jason-bit的博客 5451

Veeam Backup Replication Console 13 备份 PVE

本文介绍了如何通过Veeam Backup & Replication控制台配置与Proxmox VE(PVE)服务器的连接,包括主机地址、用户名密码和SSH信任设置。随后详细说明了部署备份Worker虚拟机的步骤,涵盖网络配置和VM创建。接着指导用户创建PVE虚拟机备份任务,包括命名、选择备份对象、存储位置、备份类型设置,以及配置备份计划任务。最后描述了备份测试执行过程,从启动备份到完成状态通知的完整流程。整个操作涉及服务器连接、Worker部署、备份配置和任务执行四个主要环节。

极致,细节 1605

stm32c语言串口输出,printf()函数重定向到STM32串口输出

最近遇到需要MCU输出数字的问题,而STM32的串口输出的是字符型,最先想到的方法是将整型数据转换为字符型输出,C库函数中提供了相关的函数参考:http://www.cnblogs.com/processakai/archive/2011/06/24/2089348.htmlhttp://c.biancheng.net/cpp/html/1573.htmlC语言中使用printf()函数输出是非常...

weixin_42523985的博客 1060

智能车竞赛蚂蚁搬家组:NXP-MicroPython与STC单片机协同搬运策略解析

本文深入解析智能车竞赛蚂蚁搬家组中NXP-MicroPython与STC单片机的协同搬运策略。通过硬件选型、通信架构设计、效率优化及实战经验分享,展示了如何利用NXP-MicroPython的实时控制与STC单片机的感知导航优势,实现高效多智能体协同作业,为参赛团队提供实用技术参考。

motor的博客 1080

避坑指南:Qgis等时圈分析中ORS插件Key申请与参数设置的常见错误

本文详细解析了QGIS等时圈分析中ORS插件从API密钥申请到参数优化的全流程避坑指南。针对密钥激活、出行模式选择、时空参数设置等七个高频故障点,提供了实用的调试方案和优化技巧,帮助用户高效完成空间可达性分析。

weixin_42546508的博客 304

利用C标准库函数vsprintf()实现多路串口使用“printf()”输出

在集成开发环境MDK下进行裸机开发,总避免不了使用printf()函数,通过串口打印数据,进行通讯或者进行程序的可视化调试(通过串口,将调试信息打印到电脑端,进行分析),通常,会对printf()函数进行输出重定向。其中printf是c标准的库函数,包含在<stdio>文件里边,具体怎么实现我们不去深究,只要了解printf()主要是通过调用fputc()函数进行数据的输出,所以可以重写fputc()函数,重定向输出接口,例如,原子的例程如下: int fputc(int ch, FILE*

XL的博客 2919

pytorch图像分类篇: 花分类数据集下载和AlexNet网络搭建训练

一、花分类数据集下载 data_setdata_set该文件夹是用来存放训练数据的目录 使用步骤如下: (1)在data_set文件夹下创建新文件夹"flower_data" (2)点击链接下载花分类数据集 (3)解压数据集到flower_data文件夹下 (4)执行"flower_data.py"脚本自动将数据集划分成训练集train和验证集val ├── flower_data ├── flower_photos(解压的数据集文件夹,3670个样本) ...

橙子的博客 8219

TI2541使用IAR编译器的printf输出来调试

1.头文件包含#include <stdio.h> 2.代码里面使用printf函数输出调试信息,支持可变参数。 3.IAR在调试状态,点击菜单栏的View->Terminal I/O。 4.跑程序,观察输出。

FF的专栏 498

OpenEuler内核编译及替换

一、内核源码下载 在gitee上下载OpenEuler内核源码 下载地址 选择需要的内核版本源码压缩包进行下载 二、内核编译 1.解压缩 将下载好的源码进行解压 tar xvf openeuler-kernel-4.19.90-2107.1.0.tar.gz 2.清理源代码树 解压后得到一个名为kernel的内核源码文件夹,进入后执行命令 make mrproper 清理过去内核编译产生的config,第一次编译时可不执行此命令 3.生成内核配置文件.config 先将将系统原配置文件拷贝过来,原

m0_56602092的博客 2万+

Authentication Assertion Tickets,SAP 系统到系统单点登录里的短命凭证

SAP 系统间的身份传递机制存在 Authentication Assertion Ticket 和 SAP Logon Ticket 两种易混淆的凭证。前者用于系统间短时身份委托(有效期2分钟,通过HTTP头传输),后者用于浏览器SSO(可配置有效期,通过Cookie传输)。Assertion Ticket依赖签发系统的数字签名和严格的时间同步,适用于ABAP/Java系统间的后台作业调用。现代SAP架构已转向OAuth 2.0等标准协议,但老系统中仍需注意两种票据的关键差异:传输方式、有效期、接收方限制

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 602

c++ printf头文件_使用printf函数输出串口调试信息

C语言中的标准库中所用的标准输出函数,默认的输出设备是显示器,要实现串口或LCD的输出,必须重新定义标准库函数里与输出函数相关的函数。例如:printf输出到串口,需要将fputc里面的输出指向串口(重定向),方法如下,只要自己添加一个int fputc(int ch, FILE *f)函数,能够输出字符就可以了。1,使用STM32CubeMX软件配置系统时钟和芯片外设双击打开S...

weixin_39757893的博客 1783

华为昇腾(Ascend)开发考试原题目解析 (2024) (题库一)——HCIP-AI-Ascend Developer——第一部分

给出一段代码如下,以下哪个选项描述错误?...A.中的语句由 MindSpore 接管,有语法限制B. 算子在中定义,并用来建立网络C.__init__()中的语句由 Python 解析执行D. 网络定义必须继承基类nn.Cell正确答案: B__init__()用于定义算子和网络层。所有需要用到的层(如卷积层、全连接层等)都应该在这里进行实例化。这部分代码由Python解释器执行。用于构建前向计算图。它调用在__init__()中定义好的算子和层来描述数据的流向。

qq_38334677的博客 1054

ARM Cortex-M3嵌入式开发实战:从DK-LM3S316开箱到外设编程全解析

嵌入式系统是连接物理世界与数字世界的桥梁,其核心在于微控制器通过外设与传感器、执行器交互。以经典的ARM Cortex-M3架构为例,它通过GPIO、ADC、PWM、UART等标准接口实现感知与控制。理解这些外设的工作原理是嵌入式开发的基础,例如ADC将模拟信号转换为数字量,PWM通过调节占空比控制功率输出,UART则实现设备间的串行通信。这些技术共同构成了物联网节点、智能硬件等应用的核心。本文以德州仪器Stellaris DK-LM3S316开发板为平台,详细演示了从硬件上电、ADC采样光敏电阻、PWM驱

weixin_30457465的博客 284

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

串口调试值printk.c

原创博客:欢迎转载,转载请注明出处 http://www.cnblogs.com/veryStrong/p/6218383.html 1、简介(基于s3c2440 linux) 在内核调试技术之中,最简单的就是printk的使用了,它的用法和C语言应用程序中的printf使用类似,在应用程序中依靠的是stdio.h中的库,而在linux内核中没有这个库,所以在linux内核中,使用这个

WXXGoodJob的博客 935

深度学习工具包 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&#39;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(&#39;DeepLearnToolbox&#39;));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(&#39;state&#39;,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&#39;); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand(&#39;state&#39;,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 = &#39;sigm&#39;;%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, &#39;Too big error&#39;);```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(&#39;state&#39;,0)sae = saesetup([784 100]);sae.ae{1}.activation_function = &#39;sigm&#39;;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)&#39;)% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;;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, &#39;Too big error&#39;);```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x&#39;,28,28,60000))/255;test_x = double(reshape(test_x&#39;,28,28,10000))/255;train_y = double(train_y&#39;);test_y = double(test_y&#39;);%% 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&#39;ll get around 1.2% errorrand(&#39;state&#39;,0)cnn.layers = { struct(&#39;type&#39;, &#39;i&#39;) %input layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 6, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %sub sampling layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 12, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 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, &#39;Too big error&#39;);```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(&#39;state&#39;,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, &#39;Too big error&#39;);%% ex2 neural net with L2 weight decayrand(&#39;state&#39;,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, &#39;Too big error&#39;);%% ex3 neural net with dropoutrand(&#39;state&#39;,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, &#39;Too big error&#39;);%% ex4 neural net with sigmoid activation functionrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;; % 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, &#39;Too big error&#39;);%% ex5 plotting functionalityrand(&#39;state&#39;,0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = &#39;softmax&#39;; % 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, &#39;Too big error&#39;);%% 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(&#39;state&#39;,0)nn = nnsetup([784 20 10]); nn.output = &#39;softmax&#39;; % 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, &#39;Too big error&#39;);```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

stm32c语言串口输出,STM32F103程序串口调用printf打印数据

程序开发过程中调试必不可少,一种简单直接的调试方式是使用串口发送数据,并使用串口助手进行观测。以前使用MSP430做项目时也同样使用printf打印数据,所以现在想在stm32 上实现。通常串口发送单字节库函数:USART_SendData(USART1, (uint8_t) ch);对显示小数等数据比较复杂,如果能够直接使用C语言 stdio.h中的printf直接输出就可以省去大部分格式输出转...

weixin_39830020的博客 1130

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

c语言调用串口输出数据类型,如何通过串口来读写数据,请教达人

该楼层疑似违规已被系统折叠隐藏此楼查看此楼如何通过终端读取并显示串口连接的某硬件的数据通过一程序来代替hexdump从而进行输入输出用C语言实现下面一程序为i/o输入输出,请教达人,怎样才能输入输出串口的硬件数据#include#include#include#include#include#include#include#includevoidstripcrlf(char*temp);i...

weixin_36245958的博客 273

Keil MDK 中利用串口及c标准库函数printf为cortex-m3做调试输出(lpc1788)

摘要: c标准库的printf是输出给显示器的,将printf函数进行修改,使其输出重定向至串口,就能实现目的。printf函数调用fputc函数完成实质输出单一字符的工作,因此将fputc函数修改使之完成串口单字符发送工作即可。 注: 本文方法性内容主要来自《Keil MDK环境下使用printf函数的解决方法》与《STM32串口使用Printf()函数问题》。除使用c标准库外,还可以使用...

weixin_30354675的博客 717

编程示例:用C语言进行串口操作

* Disnable 漀?串口一 为 /dev/ttyS0,串口二 为 /dev/ttyS1。B38400, B19200,漀?/* 设置为奇效验*//*设置为19200Bps*/#include <unistd.h> /*Unix 标准函数定义*/#include <stdio.h> /*标准输入输出定义*/#include <stdlib.h> /*标准函数库定义*/#include <fcntl.h> /*文件控制定义*/

红孩儿编程大师 5736

用printf()函数格式化串口输出

1、printf()函数在C语言中表示的意思是将要输出的字符数据等输出显示到显示屏上,而在单片机上没有显示屏只有串口输出,这时就需要重新定义一下printf()函数,printf()函数里面是调用fputc()函数,所以需要重新定义fputc()函数;(1)fputc()函数可以在工程中的任意文件定义,比如在main.c中;(2)使用printf()函数需要调用头文件stdio.h;

jacklood的博客 1196

STC15-串口通信打印输出数据printf函数与sprintf函数

本文主要比较了printf和sprintf函数在STC15单片机串口通信中的应用差异。printf直接将格式化数据输出到屏幕,而sprintf将数据存入指定缓冲区。文章详细介绍了STC15串口1的初始化配置,包括波特率设置、中断处理和数据发送函数实现,并解析了相关寄存器(SCON、PCON、SBUF等)的功能。示例代码展示了如何使用sprintf格式化字符串并通过printf输出,为单片机串口通信开发提供了实用参考。

weixin_41226265的博客 1916

串口利用printf函数打印信息

串口利用printf函数打印信息

weixin_63568691的博客 2368

printf重定向

C语言中printf默认输出设备是显示器,当开发板没有时我们就用串口来打印数据 int fputc(int ch,FILE *p) { USART_SendData(USART1,ch); //如果用串口2打印,和换成USART2 while(USART_GetFlagStatus(USART1,USART_FLAG_TXE)!=1);...

weixin_43554366的博客 7091

写一段C语言用通过UART串口printf输出变量内容

可以使用标准 C 库函数 printf,并在 UART 串口上输出。 举个例子,假设有一个整型变量 a,要在 UART 串口上输出它的值,可以使用以下代码: #include <stdio.h> int main() { int a = 123; printf("a = %d\n", a); return 0; } 在这段代码中,%d 是用来格式化输出整型变...

weixin_35756373的博客 923

Linux C语言串口输出

#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include "string.h" #include <fcntl.h> #include <termio

qq_45613171的博客 561

使用C语言操作串口

其实这并不是一件很难的事,在自己动手实验之前,我自然是知道现代操作系统都将设备看成文件来处理,这无疑降低了程序员操作硬件的难度,使用标准IO就可以操作硬件。我上网查了一下“windows C语言 串口”,希望能得到一些示例,但是没有成功,我得到的不是用CreateFile就是用这个模块那个模块,甚至扯上了用BIOS等恐龙时代的东东。无语,还是自己试一下的好。#include int mai

codexy的专栏 2万+
上一篇: Stellaris LM3Sxxx------双定时器设置
下一篇: 在stm32 单片机程序中使用printf()进行串口调试
Fortware
博客等级 码龄14年 61粉丝 28原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值