历史上的今天
今天是:2024年09月05日(星期四)
2019年09月05日 | STM32F103程序设计-8-USB转TTL串口(printf)
2019-09-05 来源:eefocus
USB转TTL串口(printf)
单片机的串口可以转为TTL电平,可以转232,可以转485。本篇讲的是通过CH340G转TTL电平与PC的USB通信。单片机串口发送数据到电脑的USB,printf作用:做项目时,单片机通过串口往电脑发数据。程序的修改分为四步,具体如下。
Step1:初始化串口
void USART1_Init(void)
{
/* USARTx configured as follow:
- BaudRate = 115200 baud
- Word Length = 8 Bits
- One Stop Bit
- No parity
- Hardware flow control disabled (RTS and CTS signals)
- Receive and transmit enabled
*/
USART_InitStructure.USART_BaudRate = 115200;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
/* Enable GPIO clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE);
/* Enable UART clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
/* Configure USART Tx as alternate function push-pull */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Configure USART Rx as input floating */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* USART configuration */
USART_Init(USART1, &USART_InitStructure);
/* Enable USART */
USART_Cmd(USART1, ENABLE);
注意两点:1.一些宏定义的替换2.增加stm32f10x_usart.c文件
Step2:引用头文件stdio.h
Step3:定义PUTCHAR_PROTOTYPE
Step4:勾选MicroLIB
史海拾趣
|
将RVDS中的工程移植到RealView MDK说明文档 请点击链接:http://arm.embedinfo.com/BBS/dispbbs.asp?boardid=3&Id=219… 查看全部问答> |
|
本帖最后由 paulhyde 于 2014-9-15 03:51 编辑 这是《大学生智能汽车设计》整本书的课件,内容很全面,希望对大家有所帮助~~~以下是目录 第1章 智能汽车设计导论 1.1 智能汽车 1.1.1 智能汽车设计的意义及研究内容 1.1.2 智能汽车设计的技术关 ...… 查看全部问答> |
|
Crossing clock domains - Signal A signal to another clock domain Let\'s say a signal from clkA domain is needed in clkB domain. It needs to be \"synchronized\" to clkB domain, so we want to build a \"synchronizer\" design, which takes a signal from clkA domain, ...… 查看全部问答> |
|
基于DS18B20和四位LED的温度自动控制系统 1:采用DS18B20采集温度,精度在0.1度。 2:采用89S52芯片。 3:采用四位共阳LED数码显示,亮度高。 4:可以设定控制温度,达到设定值继电器A工作,低于设定值继电器A断开。 5:超温报警,超过设定温 ...… 查看全部问答> |
|
用ATMEGA16控制NRF905进行简单的收发,调了一周了,希望哪位大侠能帮俺播开云雾!! 发送段代码: #include <iom16v.h>#include <macros.h>#define uint unsigned int#define uchar unsigned char#define Low_TX_EN PORTD&=~(1 << PD7)#define High ...… 查看全部问答> |
|
有10年没有怎么摸这个东西了,最近公司突然有了一个产品需要用到这个东西,硬件CPU是AT89C52,我手里有个10年前买的Insignt ME-52,但找不到运行环境的软件了.恳求专家指点,那里能够下载到这个软件?… 查看全部问答> |




