Modbus TCP using STM32F446 Nucleo board and ESP8266

rhdehfdl
Posts: 1
Joined: Fri Jul 05, 2024 6:52 am

Modbus TCP using STM32F446 Nucleo board and ESP8266

Postby rhdehfdl » Fri Jul 05, 2024 6:54 am

hello.
This is my first time using TCP communication, my first time using ESP8266, and I am barely able to follow STM32. There's something I want to make, but it doesn't work out, so I'm posting it here.

After configuring the ESP8266 with the AT command (Server), if you request data from the server using the Modbus poll program on your PC, the command will be received successfully.
If you look at the network traffic, it comes in like this:
"ec fa bc 1e fd 74 04 7c 16 a2 d5 c5 08 00 45 00
00 34 4b 33 40 00 80 06 00 00 c0 a8 02 9c c0 a8
02 64 e2 53 01 f6 00 0e 59 85 00 00 19 71 50 18
fa f0 86 77 00 00 00 11 00 00 00 06 01 03 00 00
00 0a"

Looking at RxData in STM32
"0d 0a 2b 49 50 44 2c 30 2c 31 32 3a 02 ef 00 00 00 11 00 00 00 06 01 03 00 00 00 0a"
It comes in like this.
"00 00 00 11 00 00 00 06 01 03 00 00 00 0a" This is Modbus data, and the values ​​in front are written as "\r \n + I P D , 0 , 1 2 : \v ]", but I don't know what they mean.

Anyway, I analyzed Modbus data and created response data.
The value is entered in increments of 1, 1 at address 0, 2... at address 1, and the final data transmitted from STM32 to ESP8266 is "00 00 00 11 00 17 01 03 14 00 01 00 02 00 03 00 04 00 05 00 06 00 07 00 08 00 09 00 0a".

There is no problem when looking at Modbus data alone, but it is not transmitted.
It may be a problem with the ESP8266 settings, but the ESP8266-related settings were set in the order below.
"AT+RST\r\n"
"AT\r\n"
"AT+CWMODE=1\r\n"
"CW MODE---->1\n\n"
"AT+CWJAP=\"%s\",\"%s\"\r\n", SSID, PASSWD
"AT+CIPSTA=\"%d.%d.%d.%d\",\"%d.%d.%d.%d\",\"%d.%d.%d.%d \"\r\n",
ip_addr1, ip_addr2, ip_addr3, ip_addr4,
subnet_mask1, subnet_mask2, subnet_mask3, subnet_mask4,
gateway_addr1, gateway_addr2, gateway_addr3, ateway_addr4)
"AT+CIFSR\r\n"
"AT+CIPMUX=1\r\n"
"AT+CIPSERVER=1,502\r\n"

Having trouble setting up?

I looked at the traffic using Wireshark. When data is sent from Modbus poll, the ESP8266 responds immediately. (A response is sent even if the STM32 is at a breakpoint.) The response is
"04 7c 16 a2 d5 c5 ec fa bc 1e fd 74 08 00 45 00
00 28 00 13 40 00 80 06 74 6c c0 a8 02 64 c0 a8
02 9c 01 f6 e2 53 00 00 19 71 00 0e 59 91 50 10
0a 90 c7 99 00 00 9f ce de b2 f1 50"

And I sent from STM32 to Uart to ESP8266 "00 00 00 11 00 17 01 03 14 00 01 00 02 00 03 00 04 00 05 00 06 00 07 00 08 00 09 00 0a" This data is not visible in wireshark.
What's the problem? I may lack basic knowledge. Please let me know if you have any doubts. Thanks for reading.

User avatar
Inq720
Posts: 35
Joined: Fri Dec 22, 2023 1:36 pm
Location: North Carolina, USA
Contact:

Re: Modbus TCP using STM32F446 Nucleo board and ESP8266

Postby Inq720 » Fri Jul 05, 2024 1:09 pm

Apologies... I'm afraid I have zero knowledge about using ESP8266 with its AT command set even though that was its original purpose and even less about the STM product. I scanned the info on it and it seems its a microcontroller and your merely using the ESP as a dumb communications board. The Arduino crowd did the same thing until they finally discovered the ESP was about 20x more powerful, more memory and more capability than their Arduinos. I have to ask... is there any reason why you need that STM board? The ESP8266 is nearly as CPU powerful as the STM and if you need more, you can always go up to an ESP32-S3. You wouldn't have to deal with all this binary AT intercommunications. Just simply write your C++ code to the ESP to do both the communications and your core project on the ESP and punt the STM. From what little I can see, it doesn't offer any additional capability and certainly adding another layer of complexity to your project. ... but then, you may have a very specific requirement that the ESP can't provide. I'm curious what that might be to drive your design choices.

Who is online

Users browsing this forum: No registered users and 23 guests