初级会员

- 积分
- 105
- 金钱
- 105
- 注册时间
- 2017-11-9
- 在线时间
- 18 小时
|
本帖最后由 路过世界 于 2019-11-4 14:43 编辑
最近我学习串口,按照配置完成了如下:,函数编译通过,并成功下载到MCU中了,但是打印出来的却不是我想要的,哪位大神可以指点一下吗?
void USART2_Init(uint32_t Fre)
{
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
USART_InitTypeDef USART_InitStruct;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2 , ENABLE);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource2,GPIO_AF_1);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource3,GPIO_AF_1);
//PA2 tx
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; //¸´ÓÃ
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //ÍÆÍì
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//RX
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_Init(GPIOA, &GPIO_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
USART_InitStruct.USART_BaudRate = Frequency;
USART_InitStruct.USART_WordLength = USART_WordLength_8b;
USART_InitStruct.USART_StopBits = USART_StopBits_1;
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(USART2, &USART_InitStruct);
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
USART_Cmd(USART2, ENABLE);
}
//发送一个字节
void Usart_SendByre(USART_TypeDef*pUARTx, uint8_t Data)
{
USART_SendData(pUARTx, Data);
while(USART_GetFlagStatus(pUARTx, USART_FLAG_TXE) == RESET);
}
主函数:
int main(void)
{
USART2_Init(115200);
Usart_SendByre(USART2, 100);
while(1)
{
}
}
|
|