<var id="qkar7"></var>


            上海皕科電子有限公司

            Shanghai Bitconn Electronic Co.,Ltd.

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

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

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

            W5500S2E-S1是一款工業級串口轉以太網模塊,支持TCP Server,TCP Client和UDP三種工作模式,串口波特率最高可達1.152Mbps,并提供配套的上位機配置軟件,也可通過網頁或AT命令等方式輕松配置。

            W5500S2E-S1模塊集成了全硬件TCP / IP協議棧以太網接口芯片W5500,網絡通信更加快速,穩定,安全。用戶只需根據手冊中推薦的參考設計原理圖,即可快速完成硬件電路的設計,降低開發難度,節省開發時間。

            今天我們就實際的來了解一下W5500S2E-S1基于UDP工作模式的具體操作流程是什么樣的,下面我們就來看看吧:

            • 具體操作流程

            (1),接線方式:

            (2)、例程說明:

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

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

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

            01 /****************************************************

            02 函數名:              UDP_Mode

            03 形參:                       無

            04 返回值:              無

            05 函數功能:    配置S2E為UDP模式

            06 ****************************************************/

            07 volatile uint8_t SendFlag=0;

            08

            09 void UDP_Mode(void)

            10 {

            11   uint8_t RecvFlag=1;

            12      char *state;

            13

            14   switch(SendFlag)

            15      {

            16        case 0:

            17              {

            18                     Usart_Send(USART2,AT\r\n);

            19                     //終端檢測命令

            20                while(RecvFlag)

            21          {

            22                       if(RX2_Point & FRAME_LEN)

            23                       //如果接收到數據

            24         {

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

            26            if(state!=NULL)

            27                                     {

            28               RX2_Point=0;

            29               //接收標志位置零

            30                                   RecvFlag=0;

            31                                   //狀態標志位置零

            32                                              SendFlag=1;

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

            34                             memset(RecvBuff,0,RECV_LEN);

            35                                     }

            36                                     else{

            37                                             SendFlag=100;

            38                                             RecvFlag=0;

            39                                     }

            40            }

            41          }

            42        }break;

            43       case 1:

            44              {

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

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

            47       RecvFlag=1;

            48                while(RecvFlag)

            49          {

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

            51         {

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

            53            if(state!=NULL)

            54                                     {

            55               RX2_Point=0;

            56                                   RecvFlag=0;

            57                                              SendFlag=2;

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

            59                             memset(RecvBuff,0,RECV_LEN);

            60                                     }

            61            else{

            62                                             SendFlag=100;

            63                                             RecvFlag=0;

            64                                     }

            65            }

            66          }

            67        }break;

            68       case 2:

            69              {

            70                     Usart_Send(USART2,AT+C1_OP=2\r\n);

            71                     //配置為UDP模式命令

            72                RecvFlag=1;

            73                while(RecvFlag)

            74          {

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

            76         {

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

            78                                    if(state!=NULL)

            79                                    {

            80              RX2_Point=0;

            81                                  RecvFlag=0;

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

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

            84                            memset(RecvBuff,0,RECV_LEN);

            85              }

            86                               else{

            87                                             SendFlag=100;

            88                                             RecvFlag=0;

            89                                     }

            90                              }

            91          }

            92        }break;

            93       case 3:

            94              {

            95                     Usart_Send(USART2,AT+IP_MODE=1\r\n);

            96                     //配置為DHCP模式

            97                      RecvFlag=1;

            98                while(RecvFlag)

            99          {

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

            101         {

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

            103                                   if(state!=NULL)

            104                                   {

            105              RX2_Point=0;

            106                                 RecvFlag=0;

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

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

            109                           memset(RecvBuff,0,RECV_LEN);

            110             }

            111                              else{

            112                                            SendFlag=100;

            113                                            RecvFlag=0;

            114                                    }

            115                             }

            116         }

            117       }break;

            118      case 4:

            119             {

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

            121                    //配置本地端口號

            122                    RecvFlag=1;

            123               while(RecvFlag)

            124         {

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

            126         {

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

            128                                    if(state!=NULL)

            129                                   {

            130              RX2_Point=0;

            131                                 RecvFlag=0;

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

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

            134                                   memset(RecvBuff,0,RECV_LEN);

            135   }

            136                              else{

            137                                            SendFlag=100;

            138                                            RecvFlag=0;

            139                                    }

            140                             }

            141         }

            142       }break;

            143      case 5:

            144             {

            145                    Usart_Send(USART2,AT+C1_CLI_IP1=192.168.1.100\r\n);

            146                    //配置遠端主機IP地址

            147                    RecvFlag=1;

            148               while(RecvFlag)

            149         {

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

            151         {

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

            153                                   if(state!=NULL)

            154                                   {

            155              RX2_Point=0;

            156                                 RecvFlag=0;

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

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

            159                           memset(RecvBuff,0,RECV_LEN);

            160             }

            161                              else{

            162                                            SendFlag=100;

            163                                            RecvFlag=0;

            164                                    }

            165                             }

            166         }

            167       }break;

            168      case 6:

            169             {

            170                    Usart_Send(USART2,AT+C1_CLI_PP1=5000\r\n);

            171                     //配置本地遠端端口號

            172                    RecvFlag=1;

            173               while(RecvFlag)

            174         {

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

            176         {

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

            178                                   if(state!=NULL)

            179                                   {

            180              RX2_Point=0;

            181                                 RecvFlag=0;

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

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

            184                           memset(RecvBuff,0,RECV_LEN);

            185             }

            186                              else{

            187                                            SendFlag=100;

            188                                            RecvFlag=0;

            189                                    }

            190                             }

            191         }

            192       }break;

            193      case 7:

            194             {

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

            196                    //配置啟動模式(0AT模式,1數據模式)

            197                    RecvFlag=1;

            198               while(RecvFlag)

            199         {

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

            201 {

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

            203                                   if(state!=NULL)

            204                                   {

            205              RX2_Point=0;

            206                                 RecvFlag=0;

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

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

            209                           memset(RecvBuff,0,RECV_LEN);

            210             }

            211                              else{

            212                                            SendFlag=100;

            213                                      RecvFlag=0;

            214                                    }

            215                             }

            216         }

            217       }break;

            218      case 8:

            219             {

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

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

            222               RecvFlag=1;

            223               while(RecvFlag)

            224         {

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

            226         {

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

            228                                   if(state!=NULL)

            229                                   {

            230              RX2_Point=0;

            231                                 RecvFlag=0;

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

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

            234                           memset(RecvBuff,0,RECV_LEN);

            235                                   }

            236           else{

            237                                            SendFlag=100;

            238              RecvFlag=0;

            239                                    }

            240                             }

            241           }

            242         }break;

            243      case 99:

            244       {

            245                    printf(“UDP Config Success!\r\n);

            246                    Config_OK=1;

            247       }

            248             default:

            249                    RecvFlag=100;break;

            250      case 100:

            251             {

            252                printf(“UDP Config Fail!\r\n);

            253                     Config_OK=1;

            254             }break;

            255       }

            256  }

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

                <var id="qkar7"></var>