初级会员

- 积分
- 57
- 金钱
- 57
- 注册时间
- 2015-12-22
- 在线时间
- 4 小时
|

楼主 |
发表于 2015-12-22 15:58:15
|
显示全部楼层
代码
/**************************************
* ????????Key_Rcc_Config
* ?è?? ??????°??ürcc
* ???? ????
* ???? ????
**************************************/
void Usart_Port_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
/* USART3 Clock Config */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
//USART_DeInit(USART3);
/* USART3 Gpio Config */
/* Config USART3 Tx(PB10) as alternate function  ush-Pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Config USART3 Rx(PB11) as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
//GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* USART3 Mode Config */
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;
USART_Init(USART3, &USART_InitStructure);
USART_Cmd(USART3, ENABLE);
//USART_ClearFlag(USART3, USART_FLAG_TXE);
}
/**************************************
* ????????fputc
* ?è?? ??????fputc?????????¨?ò??????3
* ???? ????
* ???? ????
**************************************/
int fputc(int ch, FILE *f)
{
/* ??Printf????·????????? */
USART_SendData(USART3, (unsigned char)ch);
while(USART_GetFlagStatus(USART3, USART_FLAG_TC) != SET);
return (ch);
} |
|