当前位置:网站首页>教你如何通过MCU配置S2E为TCP Server的工作模式
教你如何通过MCU配置S2E为TCP Server的工作模式
2022-07-25 10:49:00 【WIZnet】
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 }
246
W5500S2E-S1是一款工业级串口转以太网模块,支持多种波特率,从1.2Kbps至1.152Mbps。采用了WIZnet公司的硬件TCP/IP协议以太网芯片W5500。这是更快、更稳定、更安全的以太网解决方案。
在下一篇“教你如何通过MCU将S2E配置为TCP Client的工作模式”中,我将继续与大家分享WIZnet W5500S2E-S1的功能,请大家敬请期待吧!
WIZnet官方网站:http://www.iwiznet.cn/
WIZnet官方技术服务QQ群:595547972
更多物联网应用,关注WIZnet官方微信号:

边栏推荐
- 基于MATLAB的常见线性调制方法
- SQL injection LESS18 (header injection + error injection)
- 苹果美国宣布符合销售免税假期的各州产品清单细节
- 模型部署简述
- Definition of information entropy
- Information management system for typical works of urban sculpture (picture sharing system SSM)
- Learn Luzhi PHP -- tp5.0 uses Chinese as an alias and reports "unsupported data expression"
- BeautifulSoup的一些用法
- Shell - Chapter 6 exercise
- 信息熵的定义
猜你喜欢

Nowcodertop12-16 - continuous updating

如何判断静态代码质量分析工具的性能?这五大因素必须考虑

A troubleshooting record of DirectShow playback problems

SQL注入 Less17(报错注入+子查询)

小区蔬菜配送的小程序

Game backpack system, "inventory Pro plug-in", research and learning ----- mom doesn't have to worry that I won't make a backpack anymore (unity3d)

Hacker introductory tutorial (very detailed) from zero basic introduction to proficiency, it is enough to read this one.

Implementation of recommendation system collaborative filtering in spark

Common web attacks and defense

Breadth first traversal (problems related to sequence traversal of graphs and binary trees)
随机推荐
谣言检测文献阅读十一—Preventing rumor spread with deep learning
ESP8266 使用 DRV8833驱动板驱动N20电机
Information management system for typical works of urban sculpture (picture sharing system SSM)
【mysql学习08】
Only know that the preform is used to generate objects? See how I use unity to generate UI prefabs
Leetcode sword finger offer 27. image of binary tree
Stm32cubemx learning record -- installation, configuration and use
flinksql client 连接kafka select * from table没有数据报错,如何解决?
小区蔬菜配送的小程序
Breadth first traversal (problems related to sequence traversal of graphs and binary trees)
SQL injection less23 (filter comment)
让运动自然发生,FITURE打造全新生活方式
Hacker introductory tutorial (very detailed) from zero basic introduction to proficiency, it is enough to read this one.
JVM性能调优方法
Syncronized lock upgrade process
2022 年中回顾|一文看懂预训练模型最新进展
Summary of combination problems of Li Kou brush questions (backtracking)
SQL injection less17 (error injection + subquery)
Small and micro enterprise smart business card management applet
SQL language (III)