这是一个串口通信程序,编译通过了,但在串口调试助手中毫无显示,求各位大神帮忙之指点一下!!
#include "stm32f10x.h"
#include <stdio.h>
#define unsigned uint32_t vu32;
GPIO_InitTypeDef GPIO_InitSructure;
USART_InitTypeDef USART_InitStructure;
void Delay (vu32 ncount);
uint8_t GetKey(void);
void OutputString(uint8_t *buffp);
void PutChar(uint8_t c);
uint32_t SerialKeyPressed(uint8_t *key);
#ifdef __GNUC__
/* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
set to 'Yes') calls __io_putchar() */
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */
void Delay (vu32 nCount)
{
for(; nCount != 0;nCount--);
}
int main (void)
{
uint8_t inputstr[128];
/****************配置GPIO使能LED********************/
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB,ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2|GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure);
GPIO_Init(GPIOB,&GPIO_InitStructure);/*GPIO配置完成*/
/*****************关闭所有LED灯*******************/
GPIO_SetBits(GPIOA,GPIO_Pin_2|GPIO_Pin_3);
GPIO_SetBits(GPIOB,GPIO_Pin_2);
/**********************USART配置************************/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);/*使能USART时钟*/
/*******************配置的具体参数**********************/
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_Tx|USART_Mode_Rx;
USART_Init(USART1,&USART_InitStructure); /*USART配置完成*/
USART_Cmd(USART1,ENABLE);/*使能USART1*/
printf("\n Yo!Yo!Check Now!\n");
printf("\n This is Zhou Qu Speaking!\n");
printf("\n STM32 is ready to recieve:\n") ;
while (1)
{
GPIO_SetBits(GPIOA,GPIO_Pin_2|GPIO_Pin_3);
GPIO_SetBits(GPIOB,GPIO_Pin_2);/*关闭所有LED指示灯*/
OutputString(inputstr);
printf("\nYour input is:\n%s\n",inputstr);
GPIO_ResetBits(GPIOA,GPIO_Pin_2|GPIO_Pin_3);
GPIO_ResetBits(GPIOB,GPIO_Pin_2);/* 打开所有LED指示灯*/
Delay (0x2FFFF);
GPIO_SetBits(GPIOA,GPIO_Pin_2|GPIO_Pin_3);
GPIO_SetBits(GPIOB,GPIO_Pin_2);/*再次关闭所有LED指示灯*/
}
}
PUTCHAR_PROTOTYPE
{
/* Place your implementation of fputc here */
/* e.g. write a character to the USART */
USART_SendData(USART1, (uint8_t) ch);
/* Loop until the end of transmission */
while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET)
{
}
return ch;
}
/***********************************子函数*****************************************/
void OutputString (uint8_t *buffp)
{
uint8_t c = 0;
uint16_t read_bytes = 0;
do
{
c=GetKey();
if(c=='\r'){break;}
if(c=='\b')
{
if(read_bytes>0)
{
printf("\b \b");
read_bytes--;
}
continue;
}
if(read_bytes >= 128)
{
printf("data overflow!\n");
continue;
}
if(c>=0x20 && c<=0x7E)
{
buffp[read_bytes++]=c;
  utChar(c);
}
}
while(1);
printf("\n\r");
buffp[read_bytes] = '\0';
}
uint8_t GetKey(void)
{
uint8_t key=0;
while(1)
{
if(SerialKeyPressed((uint8_t*)&key)) break;
}
return key;
}
uint32_t SerialKeyPressed(uint8_t *key)
{
if(USART_GetFlagStatus(USART1,USART_FLAG_RXNE)!=RESET)
{
*key = (uint8_t)USART1->DR;
return 1;
}
else {
return 0;
}
}
void PutChar(uint8_t c)
{
USART_SendData(USART1,c);
while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET)
{
}
} |