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


            上海皕科電子有限公司

            Shanghai Bitconn Electronic Co.,Ltd.

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

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

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

            在上兩篇文章中分別講述了通過MCU配置S2E為UDP、TCP Server的工作模式”,相信小伙伴們已經對S2E的基本功能了解了一些,現在就讓我們再接再厲、更上一層樓吧:

            首先我們先了解一下MCU與S2E的接線方式:

             

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

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

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

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

            02 函數名:TCP_Client_Mode

            03 形參:無

            04 返回值:無

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

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

            07 volatile uint8_t SendFlag=0;

            08

            09 void TCP_Client_Mode(void)

            10 {

            11     uint8_t RecvFlag=1;

            12     char *state;

            13     switch (SendFlag) {

            14     case 0: {

            15         Usart_Send(USART2,”AT\r\n”);                                                                 //終端檢測命令

            16         while (RecvFlag) {

            17             if (RX2_Point & FRAME_LEN) {

            18                 //如果接收到數據

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

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

            21                 if (state!=NULL) {                                                                                            //有

            22                     RX2_Point=0;

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

            24                     RecvFlag=0;

            25                              //接收標致位置零

            26                     SendFlag=1;                                                                                                //發送標志位置零

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

            28                     memset(RecvBuff,0,RECV_LEN);

            29                            //接收緩存清零

            30                 } else {                                                                                                                            //無

            31                     SendFlag=100;                                                                                              //配置失敗

            32                     RecvFlag=0;

            33                 }

            34             }

            35         }

            36     }

            37     break;

            38     case 1: {

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

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

            41         RecvFlag=1;

            42         while (RecvFlag) {

            43             if (RX2_Point & FRAME_LEN) {

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

            45                 if (state!=NULL) {

            46                     RX2_Point=0;

            47                     RecvFlag=0;

            48                     SendFlag=2;

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

            50                     memset(RecvBuff,0,RECV_LEN);

            51                 } else {

            52                     SendFlag=100;

            53                     RecvFlag=0;

            54                 }

            55             }

            56         }

            57     }

            58     break;

            59     case 2: {

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

            61                    Client模式命令

            62         RecvFlag=1;

            63         while (RecvFlag) {

            64             if (RX2_Point & FRAME_LEN) {

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

            66                 if (state!=NULL) {

            67                     RX2_Point=0;

            68                     RecvFlag=0;

            69                     SendFlag=3;

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

            71                     memset(RecvBuff,0,RECV_LEN);

            72                 } else {

            73                     SendFlag=100;

            74                     RecvFlag=0;

            75                 }

            76             }

            77         }

            78     }

            79     break;

            80     case 3: {

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

            82                    //配置DHCP模式命令

            83         RecvFlag=1;

            84         while (RecvFlag) {

            85             if (RX2_Point & FRAME_LEN) {

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

            87                 if (state!=NULL) {

            88                     RX2_Point=0;

            89                     RecvFlag=0;

            90                     SendFlag=4;

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

            92                     memset(RecvBuff,0,RECV_LEN);

            93                 } else {

            94                     SendFlag=100;

            95                     RecvFlag=0;

            96                 }

            97             }

            98         }

            99     }

            100     break;

            101     case 4: {

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

            103                    //配置S2E的本地端口號

            104         RecvFlag=1;

            105         while (RecvFlag) {

            106             if (RX2_Point & FRAME_LEN) {

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

            108                 if (state!=NULL) {

            109                     RX2_Point=0;

            110                     RecvFlag=0;

            111                     SendFlag=5;

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

            113                     memset(RecvBuff,0,RECV_LEN);

            114                 } else {

            115                     SendFlag=100;

            116                     RecvFlag=0;

            117                 }

            118             }

            119         }

            120     }

            121     break;

            122     case 5: {

            123         Usart_Send(USART2,”AT+C1_CLI_IP1=192.168.1.109\r\n”);

            124                    //配置遠程服務器的IP地址

            125         RecvFlag=1;

            126         while (RecvFlag) {

            127             if (RX2_Point & FRAME_LEN) {

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

            129                 if (state!=NULL) {

            130                     RX2_Point=0;

            131                     RecvFlag=0;

            132                     SendFlag=6;

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

            134                     memset(RecvBuff,0,RECV_LEN);

            135                 } else {

            136                     SendFlag=100;

            137                     RecvFlag=0;

            138                 }

            139             }

            140         }

            141     }

            142     break;

            143     case 6: {

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

            145                    //配置遠程服務器的端口號

            146         RecvFlag=1;

            147         while (RecvFlag) {

            148             if (RX2_Point & FRAME_LEN) {

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

            150                 if (state!=NULL) {

            151                     RX2_Point=0;

            152                     RecvFlag=0;

            153                     SendFlag=7;

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

            155                     memset(RecvBuff,0,RECV_LEN);

            156                 } else {

            157                     SendFlag=100;

            158                     RecvFlag=0;

            159                 }

            160             }

            161         }

            162     }

            163     break;

            164     case 7: {

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

            166         //配置下次上電啟動模式(0-AT模式,1-

            167         數據模式)

            168         RecvFlag=1;

            169         while (RecvFlag) {

            170             if (RX2_Point & FRAME_LEN) {

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

            172                 if (state!=NULL) {

            173                     RX2_Point=0;

            174                     RecvFlag=0;

            175                     SendFlag=8;

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

            177                     memset(RecvBuff,0,RECV_LEN);

            178                 } else {

            179                     SendFlag=100;

            180                     RecvFlag=0;

            181                 }

            182             }

            183         }

            184     }

            185     break;

            186     case 8: {

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

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

            189         RecvFlag=1;

            190         while (RecvFlag) {

            191             if (RX2_Point & FRAME_LEN) {

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

            193                 if (state!=NULL) {

            194                     RX2_Point=0;

            195                     RecvFlag=0;

            196                     SendFlag=99;

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

            198                     memset(RecvBuff,0,RECV_LEN);

            199                 } else {

            200                     SendFlag=100;

            201                     RecvFlag=0;

            202                 }

            203             }

            204         }

            205     }

            206     break;

            207     case 99: {                                                                                                                                          //配置成功!

            208         printf(“TCP Client Config Success!\r\n”);

            209         Config_OK=1;

            210     }

            211     default:

            212         RecvFlag=100;

            213         break;

            214     case 100: {                                                                                                                                         //配置失??!

            215         printf(“TCP Client Config Fail!\r\n”);

            216         Config_OK=1;

            217     }

            218     break;

            219     }

            220 }

            221

            • W5500S2E-S1是一款工業級串口轉以太網模塊,支持多種波特率,從1.2Kbps至1.152Mbps。采用了WIZnet公司的硬件TCP/IP協議以太網芯片W5500。這是更快、更穩定、更安全的以太網解決方案。
            文章評論
            發表評論:(匿名發表無需登錄,已登錄用戶可直接發表。) 登錄狀態: 未登錄,點擊登錄
            上海皕科電子有限公司 版權所有
            地址:上海市閔行區都園路4288號D區220室
            電話:021-54852770
            郵件:sales@bitconn.com
             
            中文字幕久久精品波多野结百度|精品无码一区二区|亚洲永久精品ww47cos|国产精品久久久久精品三级卜

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