写一个usart串口小程序,如下。编译成功,下载到
STM32107vc
芯片的板子后, 打开串口调试助手没有任何输出,求分析原因
#include "stm32f10x.h"
#include <stdio.h>
void RCC_Configura
tion(void);
void GPIO_Configuration(void);
void USART_Configuration(void);
void delay(__IO uint32_t nCount)
{
for (; nCount != 0; nCount--);
}
int main(void)
{
u8 i;
u8 t[]={"welcome to be here"};
RCC_Configuration(); GPIO_Configuration();
USART_Configuration();
while(1)
{
for(i=0;i<18;i++)
{
USART_SendData(USART2,t
);
printf("hdfjhsodjojdos");
delay(80000);
}
}
}
void RCC_Configuration(void)
{
/* 使能LED对应GPIO的Clock时钟 *///---打开相应外设时钟-------
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
}
void USART_Configuration()
{
USART_InitTypeDef USART_InitStructure;
USART_InitStructure.USART_BaudRate = 9600;
USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_Init(USART1,&USART_InitStructure);
USART_Cmd(USART1,ENABLE);
}
void GPIO_Configuration()
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //输出模式设置为复用推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure);
}
-
设置是指奇偶校验波特率停止位那些么?
一周热门 更多>