如下是STM32F4调试的串口程序: #include "usart2.h" void MyUartInit(void ) { //NVIC_Config(); STM_EVAL_COMInit(); USART_Configuration(115200); // USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); } void STM_EVAL_COMInit(void) { GPIO_InitTypeDef GPIO_InitStructure; /* Enable GPIO clock */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE); /* Enable UART clock */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); /* Connect PXx to USARTx_Tx*/ GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_USART1); /* Connect PXx to USARTx_Rx*/ GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_USART1); /* Configure USART Tx as alternate function */ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOB, &GPIO_InitStructure); /* Configure USART Rx as alternate function */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; GPIO_Init(GPIOB, &GPIO_InitStructure); } void USART_Configuration(int BaudRate) { USART_InitTypeDef USART_InitStructure; USART_InitStructure.USART_BaudRate = BaudRate; 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(USART1, &USART_InitStructure); /* Configure USART1 basic and asynchronous paramters */ USART_Cmd(USART1, ENABLE); /* Enable USART1 */ } void NVIC_Config(void) { NVIC_InitTypeDef NVIC_InitStructure; /* Enable the USARTx Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); } int fputc(int ch, FILE *f) { /* Place your implementation of fputc here */ /* e.g. write a character to the USART */ USART_SendData(USART1, (u8) ch); /* Loop until the end of transmission */ while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET) { } return ch; } int fgetc(FILE *f) { while (USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == RESET); return (int)USART_ReceiveData(USART2); } void USART1_IRQHandler(void) { char c; if(USART_GetFlagStatus(USART1,USART_FLAG_RXNE)==SET) { c = USART_ReceiveData(USART1); USART_SendData(USART1,c); USART_ClearITPendingBit(USART1,USART_IT_RXNE); // GPIO_ToggleBits(GPIOD,GPIO_Pin_14); } } void Usart_Test(void) { int i=0; for(i=0 ; i |
STM32F407 定时器触发DMA 求助大神
【MCU实战经验】基于STM32F407的音频播放器设计
盘古UE-STM32F407工控板原理图
【STM32F429心得\疑问】+STM32F4之FSMC和FMC
STM32F429读取IO口传输的数据速率
STM32F407ZGT6 手摸芯片背部重启
STM32F4 SPI 动作时,软件片选信号被拉高,IO口程序逻辑失控
STM32F401RE NUCLEO求助,串口一直不能进中断
读取STM32F407内部温度传感器值错误
STM32F429多路内部ADC独立采集的办法
那你外部需要有串口转换芯片了,和普通串口的功能一样
楼主不是有回复,在外部加了转换芯片
回复:STM32F4_Disvcovery 之串口调试!
RE:STM32F4_Disvcovery 之串口调试!
RE:STM32F4_Disvcovery 之串口调试!
回复:STM32F4_Disvcovery 之串口调试!
RE:STM32F4_Disvcovery 之串口调试!
RE:STM32F4_Disvcovery 之串口调试!
RE:STM32F4_Disvcovery 之串口调试!
RE:STM32F4_Disvcovery 之串口调试!