这是我的源代码,V3.5的库函数;不知道哪里出了问题,串口助手打印出来的都是乱码。求指教
#include"stm32f10x.h"
#include"stdio.h"
GPIO_InitTypeDef GPIO_InitStruct;
USART_InitTypeDef USART_InitStruct;
USART_ClockInitTypeDef USART_ClockInitStruct;
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
int main()
{
GPIO_DeInit(GPIOA);
USART_DeInit(USART1);
//Pin9 发送
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA,&GPIO_InitStruct);
//Pin10 接收
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA,&GPIO_InitStruct);
USART_InitStruct.USART_BaudRate = 115200;
USART_InitStruct.USART_WordLength = USART_WordLength_8b;
USART_InitStruct.USART_StopBits = USART_StopBits_1;
USART_InitStruct.USART_Parity = USART_Parity_No ;
USART_InitStruct.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_Init(USART1, &USART_InitStruct);
USART_ClockInitStruct.USART_Clock = USART_Clock_Disable;
USART_ClockInitStruct.USART_CPOL = USART_CPOL_Low;
USART_ClockInitStruct.USART_CPHA = USART_CPHA_1Edge;
USART_ClockInitStruct.USART_LastBit = USART_LastBit_Disable;
USART_ClockInit(USART1,&USART_ClockInitStruct);
USART_Cmd(USART1,ENABLE);
while(1)
{
printf("\n\r USART\n\r");
}
}
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;
}
|