找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 6928|回复: 9
收起左侧

STM32F103 5个串口同时使用程序 测试成功!

  [复制链接]
ID:232860 发表于 2017-9-13 13:53 | 显示全部楼层 |阅读模式
如题,亲测成功!
单片机源程序如下:
  1. #include "stm32f10x.h"
  2. #include "delay.h"
  3. #include "HX711.h"
  4. #include "usart.h"
  5. #include "usart2.h"
  6. #include "usart3.h"
  7. #include "usart4.h"
  8. #include "usart5.h"

  9. int main(void)
  10. {
  11.         u8 i;
  12.         u8 len1;
  13.         u8 len2;
  14.         u8 len3;
  15.         u8 len4;
  16.   u8 len5;

  17.         u16 times=0;

  18.         delay_init();

  19.         NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
  20.         uart1_init(115200);
  21.         uart2_init(115200);
  22.         uart3_init(115200);
  23.         uart4_init(115200);
  24.         uart5_init(115200);

  25.         while(1)
  26.         {
  27.                 if(USART1_RX_STA&0x8000)
  28.                 {
  29.                         len1=USART1_RX_STA&0x3fff;
  30.                         for(i=0;i<len1;i++)
  31.                         {
  32.                                 USART_SendData(USART1, USART1_RX_BUF[i]);
  33.                                 while(USART_GetFlagStatus(USART1,USART_FLAG_TC)!=SET);
  34.                         }
  35.                         USART1_RX_STA=0;
  36.                 }else
  37.                 {

  38.                         if(times%200==0)
  39.                         {
  40.                                 u1_printf("This is u1\n");
  41.                         }


  42.                 }

  43.                 if(USART2_RX_STA&0x8000)
  44.                 {
  45.                         len2=USART2_RX_STA&0x3fff;
  46.                         for(i=0;i<len2;i++)
  47.                         {
  48.                                 USART_SendData(USART2, USART2_RX_BUF[i]);
  49.                                 while(USART_GetFlagStatus(USART2,USART_FLAG_TC)!=SET);
  50.                         }
  51.                         USART2_RX_STA=0;
  52.                 }else
  53.                 {

  54.                         if(times%200==0)
  55.                         {
  56.                                 u2_printf("This is u2\n");
  57.                         }
  58.                 }

  59.                 if(USART3_RX_STA&0x8000)
  60.                 {
  61.                         len3 = USART3_RX_STA&0x3fff;
  62.                         for(i = 0;i < len3;i++)
  63.                         {
  64.                                 USART_SendData(USART3, USART3_RX_BUF[i]);
  65.                                 while(USART_GetFlagStatus(USART3,USART_FLAG_TC)!=SET);
  66.                         }
  67.                         USART3_RX_STA=0;
  68.                 }else
  69.                 {
  70.                         if(times%200==0)
  71.                         {
  72.                                 u3_printf("This is u3\n");
  73.                         }
  74.                 }

  75.                 if(USART4_RX_STA&0x8000)
  76.                 {
  77.                         len4 = USART4_RX_STA&0x3fff;
  78.                         for(i = 0;i < len4;i++)
  79.                         {
  80.                                 USART_SendData(UART4, USART4_RX_BUF[i]);
  81.                                 while(USART_GetFlagStatus(UART4,USART_FLAG_TC)!=SET);
  82.                         }
  83.                         USART4_RX_STA=0;
  84.                 }else
  85.                 {
  86.                         if(times%200==0)
  87.                         {
  88.                                 u4_printf("This is u4\n");
  89.                         }
  90.                 }

  91.                 if(USART5_RX_STA&0x8000)
  92.                 {
  93.                         len5 = USART5_RX_STA&0x3fff;
  94.                         for(i = 0;i < len5;i++)
  95.                         {
  96.                                 USART_SendData(UART5, USART5_RX_BUF[i]);
  97.                                 while(USART_GetFlagStatus(UART5,USART_FLAG_TC)!=SET);
  98.                         }
  99.                         USART5_RX_STA=0;
  100.                 }else
  101.                 {
  102.                         if(times%200==0)
  103.                         {
  104.                                 u5_printf("This is u5\n");
  105.                         }
  106.                 }

  107.                 times++;
  108.                 delay_ms(10);
  109.         }
  110. }
复制代码

所有资料51hei提供下载:
5个串口同时工作.rar (309.69 KB, 下载次数: 187)

评分

参与人数 2黑币 +55 收起 理由
linuxcso + 5 赞一个!
admin + 50 共享资料的黑币奖励!

查看全部评分

回复

使用道具 举报

ID:244321 发表于 2017-10-30 19:38 | 显示全部楼层
不是写的F107嘛,为啥我打开是103啊
回复

使用道具 举报

ID:104982 发表于 2018-5-5 09:28 | 显示全部楼层
想看看中断怎么写的
回复

使用道具 举报

ID:104982 发表于 2018-5-5 10:01 | 显示全部楼层
追评一下,目前找的多路串口程序中最有用的,请问大神测试过多路同时收发会不会有丢包?
回复

使用道具 举报

ID:375028 发表于 2018-7-29 16:29 | 显示全部楼层
ok,学习了。
回复

使用道具 举报

ID:380691 发表于 2018-7-30 09:17 | 显示全部楼层
我用103写的串口程序,结果打印出来是乱码,
不知道咋回事
回复

使用道具 举报

ID:219315 发表于 2020-5-29 15:13 | 显示全部楼层
这个范例很实用,收下了!!!
回复

使用道具 举报

ID:570410 发表于 2020-9-21 00:04 | 显示全部楼层
F103 还是 F107?
回复

使用道具 举报

ID:750420 发表于 2021-8-17 15:05 | 显示全部楼层
103的,浪费我五个黑币
回复

使用道具 举报

ID:697494 发表于 2021-8-26 09:11 | 显示全部楼层
有参考价值,不错。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表