单片机学习小组
直播中

周杰

8年用户 253经验值
私信 关注

STM32F107 5个串口同时使用程序

如题,亲测成功!
单片机源程序如下:
  • #include "STM32f10x.h"
  • #include "delay.h"
  • #include "HX711.h"
  • #include "usart.h"
  • #include "usart2.h"
  • #include "usart3.h"
  • #include "usart4.h"
  • #include "usart5.h"
  • int main(void)
  • {
  •         u8 i;
  •         u8 len1;
  •         u8 len2;
  •         u8 len3;
  •         u8 len4;
  •   u8 len5;
  •         u16 times=0;
  •         delay_init();
  •         NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
  •         uart1_init(115200);
  •         uart2_init(115200);
  •         uart3_init(115200);
  •         uart4_init(115200);
  •         uart5_init(115200);
  •         while(1)
  •         {
  •                 if(USART1_RX_STA&0x8000)
  •                 {
  •                         len1=USART1_RX_STA&0x3fff;
  •                         for(i=0;i                        {
  •                                 USART_SendData(USART1, USART1_RX_BUF);
  •                                 while(USART_GetFlagStatus(USART1,USART_FLAG_TC)!=SET);
  •                         }
  •                         USART1_RX_STA=0;
  •                 }else
  •                 {
  •                         if(times%200==0)
  •                         {
  •                                 u1_printf("This is u1n");
  •                         }
  •                 }
  •                 if(USART2_RX_STA&0x8000)
  •                 {
  •                         len2=USART2_RX_STA&0x3fff;
  •                         for(i=0;i
  •                         {
  •                                 USART_SendData(USART2, USART2_RX_BUF);
  •                                 while(USART_GetFlagStatus(USART2,USART_FLAG_TC)!=SET);
  •                         }
  •                         USART2_RX_STA=0;
  •                 }else
  •                 {
  •                         if(times%200==0)
  •                         {
  •                                 u2_printf("This is u2n");
  •                         }
  •                 }
  •                 if(USART3_RX_STA&0x8000)
  •                 {
  •                         len3 = USART3_RX_STA&0x3fff;
  •                         for(i = 0;i < len3;i++)
  •                         {
  •                                 USART_SendData(USART3, USART3_RX_BUF);
  •                                 while(USART_GetFlagStatus(USART3,USART_FLAG_TC)!=SET);
  •                         }
  •                         USART3_RX_STA=0;
  •                 }else
  •                 {
  •                         if(times%200==0)
  •                         {
  •                                 u3_printf("This is u3n");
  •                         }
  •                 }
  •                 if(USART4_RX_STA&0x8000)
  •                 {
  •                         len4 = USART4_RX_STA&0x3fff;
  •                         for(i = 0;i < len4;i++)
  •                         {
  •                                 USART_SendData(UART4, USART4_RX_BUF);
  •                                 while(USART_GetFlagStatus(UART4,USART_FLAG_TC)!=SET);
  •                         }
  •                         USART4_RX_STA=0;
  •                 }else
  •                 {
  •                         if(times%200==0)
  •                         {
  •                                 u4_printf("This is u4n");
  •                         }
  •                 }
  •                 if(USART5_RX_STA&0x8000)
  •                 {
  •                         len5 = USART5_RX_STA&0x3fff;
  •                         for(i = 0;i < len5;i++)
  •                         {
  •                                 USART_SendData(UART5, USART5_RX_BUF);
  •                                 while(USART_GetFlagStatus(UART5,USART_FLAG_TC)!=SET);
  •                         }
  •                         USART5_RX_STA=0;
  •                 }else
  •                 {
  •                         if(times%200==0)
  •                         {
  •                                 u5_printf("This is u5n");
  •                         }
  •                 }
  •                 times++;
  •                 delay_ms(10);
  •         }
  • }




所有资料提供下载:
    5个串口同时工作.rar  



更多回帖

发帖
×
20
完善资料,
赚取积分