57 lines
2.0 KiB
C
Raw Normal View History

2021-10-24 10:19:26 +08:00
/***********************************************
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>c<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD>޸<EFBFBD><EFBFBD><EFBFBD> <EFBFBD>޸<EFBFBD><EFBFBD><EFBFBD>Ϣ
--20210409 Magnin <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸<EFBFBD>
************************************************/
/**************<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>***************
UART1 TX -------------------------- PA9
UART1 RX -------------------------- PA10
***********************************************/
#include "uart.h"
#include "share.h"
#include "cm32m101a_conf.h"
#include <stdio.h>
static USART_InitType USART_InitStructure;
void Usart1_Init(void)
{
GPIO_InitType GPIO_InitStructure;
//<2F><><EFBFBD><EFBFBD>GPIO<49><4F>ʱ<EFBFBD><CAB1>
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE);
//<2F><><EFBFBD><EFBFBD>USARTʱ<54><CAB1>
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_USART1, ENABLE);
// <20><>ʼ<EFBFBD><CABC>GPIO<49>
GPIO_InitStruct(&GPIO_InitStructure);
//<2F><><EFBFBD><EFBFBD> USARTx Tx
GPIO_InitStructure.Pin = GPIO_PIN_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Alternate = GPIO_AF4_USART1; //<2F><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>
GPIO_InitPeripheral(GPIOA, &GPIO_InitStructure);
//<2F><><EFBFBD><EFBFBD> USARTx Rx
GPIO_InitStructure.Pin = GPIO_PIN_10;
GPIO_InitStructure.GPIO_Pull = GPIO_Pull_Up;
GPIO_InitStructure.GPIO_Alternate = GPIO_AF4_USART1; //<2F><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>
GPIO_InitPeripheral(GPIOA, &GPIO_InitStructure);
//<2F><><EFBFBD>ô<EFBFBD><C3B4>ڲ<EFBFBD><DAB2><EFBFBD>
USART_InitStructure.BaudRate = USART1_BANDRATE; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
USART_InitStructure.WordLength = USART_WL_8B; //<2F><><EFBFBD><EFBFBD>λ
USART_InitStructure.StopBits = USART_STPB_1; //ֹͣλ
USART_InitStructure.Parity = USART_PE_NO; //У<><D0A3>λ
USART_InitStructure.HardwareFlowControl = USART_HFCTRL_NONE; //<2F>ر<EFBFBD>Ӳ<EFBFBD><D3B2><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>
USART_InitStructure.Mode = USART_MODE_RX | USART_MODE_TX; //<2F><><EFBFBD>ͽ<EFBFBD><CDBD><EFBFBD>ģʽ
//<2F><>ʼ<EFBFBD><CABC>USART1
USART_Init(USART1, &USART_InitStructure);
//ʹ<><CAB9>USART1
USART_Enable(USART1, ENABLE);
}
//<2F>ض<EFBFBD><D8B6><EFBFBD>fputc
int fputc(int ch, FILE* f)
{
USART_SendData(USART1, (uint8_t)ch); //<2F><>USART1<54><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
while (USART_GetFlagStatus(USART1, USART_FLAG_TXDE) == RESET) ; //<2F>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
return (ch);
}