发布网友 发布时间:2022-05-13 08:17
共1个回答
热心网友 时间:2024-02-22 02:34
摘要void USART1_IRQHandler(void) //串口1 中断服务程序{undefined unsigned int i; if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) //判断读寄存器是否非空 { RxBuffer1[RxCounter1++] = USART_ReceiveData(USART1); //将读寄存器的数据缓存到接收缓冲区里if(RxBuffer1[RxCounter1-2]==0x0d&&RxBuffer1[RxCounter1-1]==0x0a) //判断结束标志是否是0x0d 0x0a {undefined for(i=0; i< RxCounter1; i++) TxBuffer1[i] = RxBuffer1[i]; //将接收缓冲器的数据转到发送缓冲区,准备转发 rec_f=1; //接收成功标志 TxBuffer1[RxCounter1]=0; //发送缓冲区结束符 RxCounter1=0;} }if(USART_GetITStatus(USART1, USART_IT_TXE) != RESET) //这段是为了避免STM32 USART 第一个字节发不出去的BUG {undefined USART_ITConfig(USART1, USART_IT_TXE, DISABLE); //禁止发缓冲器空中断, } }————————————————版权声明:本文为CSDN博主「opy12」的原创文章,遵咨询记录 · 回答于2021-12-17编制一个使用STM32的USART2与PC机实现串行通信,串口使用1位起始位、8位数据您具体是要问什么呢答案oid USART_Config(USART_TypeDef* USARTx){undefined USART_InitStructure.USART_BaudRate = 9600; //速率9600bps USART_InitStructure.USART_WordLength = USART_WordLength_8b; //数据位8位 USART_InitStructure.USART_StopBits = USART_StopBits_1; //停止位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; //收发模式 /* Configure USART1 */ USART_Init(USARTx, &USART_InitStructure); //配置串口参数函数 /* Enable USART1 Receive and Transmit interrupts */ USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); //使能接收中断 USART_ITConfig(USART1, USART_IT_TXE, ENABLE); //使能发送缓冲空中断 /* Enable the USART1 */ USART_Cmd(USART1, ENABLE);}void USART1_IRQHandler(void) //串口1 中断服务程序{undefined unsigned int i; if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) //判断读寄存器是否非空 { RxBuffer1[RxCounter1++] = USART_ReceiveData(USART1); //将读寄存器的数据缓存到接收缓冲区里if(RxBuffer1[RxCounter1-2]==0x0d&&RxBuffer1[RxCounter1-1]==0x0a) //判断结束标志是否是0x0d 0x0a {undefined for(i=0; i< RxCounter1; i++) TxBuffer1[i] = RxBuffer1[i]; //将接收缓冲器的数据转到发送缓冲区,准备转发 rec_f=1; //接收成功标志 TxBuffer1[RxCounter1]=0; //发送缓冲区结束符 RxCounter1=0;} }if(USART_GetITStatus(USART1, USART_IT_TXE) != RESET) //这段是为了避免STM32 USART 第一个字节发不出去的BUG {undefined USART_ITConfig(USART1, USART_IT_TXE, DISABLE); //禁止发缓冲器空中断, } }————————————————版权声明:本文为CSDN博主「opy12」的原创文章,遵