include "usart.h"int fputc(int ch, FILE *f)
{
Serial_SendByte(ch); void USART2_Init(u32 bound) { GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOD,ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE); GPIO_InitStructure.GPIO_Pin=GPIO_Pin_2;//TX GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP; GPIO_Init(GPIOA,&GPIO_InitStructure); GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING; GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Pin=GPIO_Pin_3;//RX GPIO_Init(GPIOA,&GPIO_InitStructure); USART_InitStructure.USART_BaudRate = bound; 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(USART2, &USART_InitStructure); USART_Cmd(USART2, ENABLE); } void Serial_SendByte(uint8_t Byte) { USART_SendData(USART2, Byte); while (USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET); } 同样的代码换成USART1就可以正常使用,请问是什么原因 |
收到STM32C542RC开发板
STM32L562DK探索板——串口通讯重定向出错
Keil平台下载时出错该如何解决?
Error[Lp015]: section placement failure内容占用溢出
STM32与JTAG电平不匹配
STM32F7由USB FS读写QSPI flash
STM8L050J3使用SWIM下载方式,无法下载,总是报错
谁知道STM32用STLINK下载的时候,不连接3V3不能下载
用SDRAM刷ltdc有白线会出现是啥情况
STM32L562DK探索板——再试Audio Play仍不成功
微信公众号
手机版
检查UART2所用到GPIO的时钟是否开启;
检查UART2的外设时钟开启没有,别配错了,UART2挂在APB1总线上;
检查UART2的波特率配置跟串口终端配置的是否一致,UART1可以,UART2的参数应该调整下,它的外设时钟跟UART1刚好差一倍;
检查是否用涉及管脚重映射的操作,记得使能AFIO时钟,HAL库是这样的: __HAL_RCC_AFIO_CLK_ENABLE();
若使用标准库,操作是这样的:RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);