<delect id="zp2xl"></delect>
  • 
    

    1. <var id="zp2xl"></var>


      上海皕科電子有限公司

      Shanghai Bitconn Electronic Co.,Ltd.

      公司介紹
      上海皕科電子有限公司是一家專業的芯片代理商和方案提供商??偛吭O在上海,是一家專業為中國電子企業提供單片機,無線RF,以太網IC及外圍器件、開發工具和相關應用解決方案的高新技術企業。公司的主要代理品牌有Digi、Wiznet、Xinnova,以及華虹MCU等。
        公司擁有優秀的銷售團隊和專業的研發部門,不但在品牌、價格、供貨、服務等方面領先業界,而且可為客戶提供及時、可行的技術支持和整體設計服務,滿足不同客戶多層次需求。

      教你如何通過MCU配置S2E為TCP Server的工作模式

      發表時間:2019/05/04 00:00:00  瀏覽次數:3079  
      字體大小: 【小】 【中】 【大】

      在上一篇文章中講了“如何通過MCU配置S2E為UDP模式”,相信小伙伴們已經了解了S2E的基本功能,在這一篇中,我們再接再厲,繼續學習一下“如何通過MCU配置S2E為TCP Server的工作模式”,無論是配置UDP模式還是配置TCP模式,都是通過串口轉以太網的方式實現的:

      1、接線方式

      2、例程說明

      打開“通過MCU配置S2E為TCP Server例程”,主程序中第一部分TIM3_Init();是設定一個幀中斷的時間定時器,這是因為該例程MCU的串口是通過幀中斷來接收AT命令配置S2E后返回的數據的。

      第二部分USARTX_Init();初始化MCU用到的串口,這里用USART1_Config();是printf功能,用于查看調試信息。USART2_Config();用于配置S2E,需要注意的是該串口的配置參數需要同S2E的串口配置參數一致,否則配置失敗。

      第三部分主循環中的TCP_Server_Mode();用于配置S2E為TCP Server模式。S2E的AT命令列表詳見各個S2E型號的用戶手冊AT命令章節介紹。配置成功,串口打印“TCP Server Config Success!”,配置失敗串口打印“TCP Server Config Fail!”。

      1 /****************************************************

      2 函數名:    TCP_Server_Mode

      3 形參:     無

      4 返回值:    無

      5 函數功能: 通過串口發送AT命令配置S2E模塊

      6 ****************************************************/

      7 volatile uint8_t SendFlag=0;

      8

      9 void TCP_Server_Mode(void)

      10 {

      11     uint8_t RecvFlag=1;

      12     char *state;

      13

      14     switch (SendFlag) {

      15     case 0: {

      16         Usart_Send(USART2,”AT\r\n”);

      17                    //終端檢測命令

      18         while (RecvFlag) {

      19             if (RX2_Point & FRAME_LEN) {

      20                 //如果接收到數據

      21                 state=strstr((char *)RecvBuff,”OK”);

      22                       //判斷回復的數據中是否有“OK”

      23                 if (state!=NULL) {

      24                     //有

      25                     RX2_Point=0;

      26                               //接收緩沖區指針置零

      27                     RecvFlag=0;

      28                              //接收標致位置零

      29                     SendFlag=1;

      30                              //發送標志位置零

      31                     printf(“Recv:%s\r\n”,RecvBuff);

      32                     memset(RecvBuff,0,RECV_LEN);

      33                            //接收緩存清零

      34                 } else {                                      //無

      35                     SendFlag=100;

      36                              //配置失敗

      37                     RecvFlag=0;

      38                 }

      39             }

      40         }

      41     }

      42     break;

      43     case 1: {

      44         Usart_Send(USART2,”AT+ECHO=0\r\n”);

      45                    //開啟(1)/關閉(0)回顯命令

      46         RecvFlag=1;

      47         while (RecvFlag) {

      48             if (RX2_Point & FRAME_LEN) { //如果接收到數據

      49                 state=strstr((char *)RecvBuff,”OK”);

      50                 if (state!=NULL) {

      51                     RX2_Point=0;

      52                     RecvFlag=0;

      53                     SendFlag=2;

      54                     printf(“Recv:%s\r\n”,RecvBuff);

      55                     memset(RecvBuff,0,RECV_LEN);

      56                 } else {

      57                     SendFlag=100;

      58                     RecvFlag=0;

      59                 }

      60             }

      61         }

      62     }

      63     break;

      64     case 2: {

      65         Usart_Send(USART2,”AT+C1_OP=0\r\n”);//配置為TCP

      66                    Server模式命令

      67         RecvFlag=1;

      68         while (RecvFlag) {

      69             if (RX2_Point & FRAME_LEN) { //如果接收到數據

      70                 state=strstr((char *)RecvBuff,”OK”);

      71                 if (state!=NULL) {

      72                     RX2_Point=0;

      73                     RecvFlag=0;

      74                     SendFlag=3;     //狀態標志位置零

      75                     printf(“Recv:%s\r\n”,RecvBuff);

      76                     memset(RecvBuff,0,RECV_LEN);

      77                 } else {

      78                     SendFlag=100;

      79                     RecvFlag=0;

      80                 }

      81             }

      82         }

      83     }

      84     break;

      85     case 3: {

      86         Usart_Send(USART2,”AT+IP_MODE=0\r\n”);

      87                    //配置為靜態IP模式

      88         RecvFlag=1;

      89         while (RecvFlag) {

      90             if (RX2_Point & FRAME_LEN) { //如果接收到數據

      91                 state=strstr((char *)RecvBuff,”OK”);

      92                 if (state!=NULL) {

      93                     RX2_Point=0;

      94                     RecvFlag=0;

      95                     SendFlag=4;     //狀態標志位置零

      96                     printf(“Recv:%s\r\n”,RecvBuff);

      97                     memset(RecvBuff,0,RECV_LEN);

      98                 } else {

      99                     SendFlag=100;

      100                     RecvFlag=0;

      101                 }

      102             }

      103         }

      104     }

      105     break;

      106     case 4: {

      107         Usart_Send(USART2,”AT+IP=192.168.1.88\r\n”);  //配置本地IP

      108         RecvFlag=1;

      109         while (RecvFlag) {

      110             if (RX2_Point & FRAME_LEN) { //如果接收到數據

      111                 state=strstr((char *)RecvBuff,”OK”);

      112                 if (state!=NULL) {

      113                     RX2_Point=0;

      114                     RecvFlag=0;

      115                     SendFlag=5;     //狀態標志位置零

      116                     printf(“Recv:%s\r\n”,RecvBuff);

      117                     memset(RecvBuff,0,RECV_LEN);

      118                 } else {

      119                     SendFlag=100;

      120                     RecvFlag=0;

      121                 }

      122             }

      123         }

      124     }

      125     break;

      126     case 5: {

      127         Usart_Send(USART2,”AT+MARK=255.255.255.0\r\n”);

      128                    //配置本地IP

      129         RecvFlag=1;

      130         while (RecvFlag) {

      131             if (RX2_Point & FRAME_LEN) { //如果接收到數據

      132                 state=strstr((char *)RecvBuff,”OK”);

      133                 if (state!=NULL) {

      134                     RX2_Point=0;

      135                     RecvFlag=0;

      136                     SendFlag=6;     //狀態標志位置零

      137                     printf(“Recv:%s\r\n”,RecvBuff);

      138                     memset(RecvBuff,0,RECV_LEN);

      139                 } else {

      140                     SendFlag=100;

      141                     RecvFlag=0;

      142                 }

      143             }

      144         }

      145     }

      146     break;

      147     case 6: {

      148         Usart_Send(USART2,”AT+GATEWAY=192.168.1.1\r\n”);

      149                    //配置本地IP

      150         RecvFlag=1;

      151         while (RecvFlag) {

      152             if (RX2_Point & FRAME_LEN) { //如果接收到數據

      153                 state=strstr((char *)RecvBuff,”OK”);

      154                 if (state!=NULL) {

      155                     RX2_Point=0;

      156                     RecvFlag=0;

      157                     SendFlag=7;     //狀態標志位置零

      158                     printf(“Recv:%s\r\n”,RecvBuff);

      159                     memset(RecvBuff,0,RECV_LEN);

      160                 } else {

      161                     SendFlag=100;

      162                     RecvFlag=0;

      163                 }

      164             }

      165         }

      166     }

      167     break;

      168     case 7: {

      169         Usart_Send(USART2,”AT+C1_PORT=5000\r\n”);

      170                    //配置本地端口號

      171         RecvFlag=1;

      172         while (RecvFlag) {

      173             if (RX2_Point & FRAME_LEN) { //如果接收到數據

      174                 state=strstr((char *)RecvBuff,”OK”);

      175                 if (state!=NULL) {

      176                     RX2_Point=0;

      177                     RecvFlag=0;

      178                     SendFlag=8;     //狀態標志位置零

      179                     printf(“Recv:%s\r\n”,RecvBuff);

      180                     memset(RecvBuff,0,RECV_LEN);

      181                 } else {

      182                     SendFlag=100;

      183                     RecvFlag=0;

      184                 }

      185             }

      186         }

      187     }

      188     break;

      189     case 8: {

      190         Usart_Send(USART2,”AT+START_MODE=0\r\n”);

      191                    //配置啟動模式(0–AT模式,1–

      192                    數據模式)

      193         RecvFlag=1;

      194         while (RecvFlag) {

      195             if (RX2_Point & FRAME_LEN) { //如果接收到數據

      196                 state=strstr((char *)RecvBuff,”OK”);

      197                 if (state!=NULL) {

      198                     RX2_Point=0;

      199                     RecvFlag=0;

      200                     SendFlag=9;     //狀態標志位置零

      201                     printf(“Recv:%s\r\n”,RecvBuff);

      202                     memset(RecvBuff,0,RECV_LEN);

      203                 } else {

      204                     SendFlag=100;

      205                     RecvFlag=0;

      206                 }

      207             }

      208         }

      209     }

      210     break;

      211     case 9: {

      212         Usart_Send(USART2,”AT+EXIT\r\n”);

      213                    //保存配置并進入數據模式

      214         RecvFlag=1;

      215         while (RecvFlag) {

      216             if (RX2_Point & FRAME_LEN) { //如果接收到數據

      217                 state=strstr((char *)RecvBuff,”OK”);

      218                 if (state!=NULL) {

      219                     RX2_Point=0;

      220                     RecvFlag=0;

      221                     SendFlag=99;     //狀態標志位置零

      222                     printf(“Recv:%s\r\n”,RecvBuff);

      223                     memset(RecvBuff,0,RECV_LEN);

      224                 } else {

      225                     SendFlag=100;

      226                     RecvFlag=0;

      227                 }

      228             }

      229         }

      230     }

      231     break;

      232     case 99: {

      233         printf(“TCP Server Config Success!\r\n”);

      234         Config_OK=1;

      235     }

      236     default:

      237         RecvFlag=100;

      238         break;

      239     case 100: {

      240         printf(“TCP Server Config Fail!\r\n”);

      241         Config_OK=1;

      242     }

      243     break;

      244     }

      245 }

      W5500S2E-S1是一款工業級串口轉以太網模塊,支持多種波特率,從1.2Kbps至1.152Mbps。采用了WIZnet公司的硬件TCP/IP協議以太網芯片W5500。這是更快、更穩定、更安全的以太網解決方案。

      文章評論
      發表評論:(匿名發表無需登錄,已登錄用戶可直接發表。) 登錄狀態: 未登錄,點擊登錄
      上海皕科電子有限公司 版權所有
      地址:上海市閔行區都園路4288號D區220室
      電話:021-54852770
      郵件:sales@bitconn.com
       
      中文字幕久久精品波多野结百度|精品无码一区二区|亚洲永久精品ww47cos|国产精品久久久久精品三级卜

      <delect id="zp2xl"></delect>
    2. 
      

      1. <var id="zp2xl"></var>