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就可以正常使用,请问是什么原因 |
简单平稳过度-回顾2025&说说我心中的ST中文论坛
STM8L的bootload中断向量表重映射
stm32f746g-disco开发板的串口通讯连接方式
在学习stm32,有哪些视频教程呢?想系统研究研究
DMA传输完成后,串口与DMA一直处于忙状态
STM32G474VET6如何配置HRTIM的中心对齐模式
请问怎么使用stm32+spi实现bissc通信?有大佬弄过吗?
Error in final launch sequence: Failed to execute MI command: target remote localhost:61234
请问设备剧烈运动后静置数据无法归零,必须重启设备才能归零,是什么原因呢,如何处理,谢谢各位有偿咨询各位
STM32CubeID V1.19.0 无法识别串口设备
微信公众号
手机版
检查UART2所用到GPIO的时钟是否开启;
检查UART2的外设时钟开启没有,别配错了,UART2挂在APB1总线上;
检查UART2的波特率配置跟串口终端配置的是否一致,UART1可以,UART2的参数应该调整下,它的外设时钟跟UART1刚好差一倍;
检查是否用涉及管脚重映射的操作,记得使能AFIO时钟,HAL库是这样的: __HAL_RCC_AFIO_CLK_ENABLE();
若使用标准库,操作是这样的:RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);