
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就可以正常使用,请问是什么原因 |
如何鉴别芯片的进口版本和国产版本
cudeide执行run是烧录还是只是执行呢
使用stm32F407连接PHY芯片进行以太网通讯,一插网线就会进入错误中断。
cubeIDE在run后出现错误
求助 nucleo STM32F303re上电后led1和led3亮,但cubepogrammer显示无3.3v电压是怎么回事?
nucleo STM32F303re上电后led1和led3亮,但cubepogrammer显示无3.3v电压是怎么回事?
求助,使用51单片机和VL6180X传感器测距,结果一直是0是什么原因,能读到ID为0xB4
STM32H7双核调试问题:CM7能成功调试但CM4始终报"Failed to read ROM table via AP 3"错误
stm32G474的flash模式如何判定?single bank 和dual bank
F103RCT6芯片对AFIO->MAPR寄存器写入时出错
检查UART2所用到GPIO的时钟是否开启;
检查UART2的外设时钟开启没有,别配错了,UART2挂在APB1总线上;
检查UART2的波特率配置跟串口终端配置的是否一致,UART1可以,UART2的参数应该调整下,它的外设时钟跟UART1刚好差一倍;
检查是否用涉及管脚重映射的操作,记得使能AFIO时钟,HAL库是这样的: __HAL_RCC_AFIO_CLK_ENABLE();
若使用标准库,操作是这样的:RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);