中级会员
 
- 积分
- 214
- 金钱
- 214
- 注册时间
- 2014-4-30
- 在线时间
- 26 小时
|

楼主 |
发表于 2014-5-19 15:52:21
|
显示全部楼层
在开发板上试过了,能行,但是到自己做的板子上就不行了、、、
引脚、串口配置如下:
#include "usart.h"
#ifdef __GNUC__
#define  UTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define  UTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */
void USART_RCC_Configuration(void)
{
// RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);//开复用时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_USART1,ENABLE);
}
void USART_GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_10;
GPIO_Init(GPIOA, &GPIO_InitStruct);
}
void USART_Configuration(void)
{
USART_InitTypeDef USART_InitStruct;
USART_RCC_Configuration();
USART_InitStruct.USART_BaudRate =115200;
USART_InitStruct.USART_StopBits = USART_StopBits_1;
USART_InitStruct.USART_WordLength = USART_WordLength_8b;
USART_InitStruct.USART_Parity = USART_Parity_No;
USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStruct.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
USART_Init(USART1, &USART_InitStruct);
// USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);//使能接收中断
USART_Cmd(USART1, ENABLE);//使能串口1
USART_GPIO_Configuration();
}
//不使用半主机模式
#if 1 //如果没有这段,则需要在target选项中选择使用USE microLIB
#pragma import(__use_no_semihosting)
struct __FILE
{
int handle;
};
FILE __stdout;
_sys_exit(int x)
{
x = x;
}
#endif
PUTCHAR_PROTOTYPE
{
USART_SendData(USART1,(u8)ch);
while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
return ch;
}
/**
* @}
*/
/*********************************END OF FILE**********************************/ |
|