Skip to content

Commit fcd5cac

Browse files
committed
Readme, ethernet SW reset
1 parent fc4ad86 commit fcd5cac

File tree

5 files changed

+71
-15
lines changed

5 files changed

+71
-15
lines changed

Ethernet_SW_Reset.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Limitations and Known Issues
2+
3+
## Issue
4+
5+
Sometimes Arduino is running fine for days but after power-up or brief loss of power (caused for example by undervoltage), ethernet connection is lost. Ethernet connection is restored only after you press the RST button on the ethernet shield. The issue has been identified and described in detail by the community for example [here](https://chrisramsay.co.uk/posts/2015/08/some-fun-with-a-cloned-arduino-and-w5100-ethernet-shield/), [here](https://www.youtube.com/watch?v=9ZBeprOqC3w), [here](http://tigawd.blogspot.com/2015/05/arduino-uno-clone-and-w5100-ethernet.html) and also [here](https://www.hobbyist.co.nz/?q=ethernet-shield-w5100).
6+
7+
## Cause
8+
9+
Arduino ethernet shields use HW method to reset / initialize the W5x00 chip. They have the W5x00's RST pin hard wired to Arduino's RST pin. If Arduino is reset, the W5x00 should be reset also. However, normal reset time of the Arduino is too short. The Arduino microcontroller has a 65 millisecond powerup/reset delay (the longest available to be set by the fuses and bootloader) but the W5x00 chip expects longer pull-down of the RST pin. As a result, the W5x00 chip fails to reset (and initialize) properly.
10+
11+
The problem is poor ethernet shield design. This issue is not specific to cheap ethernet shields (clones), but exists in all variant of the Arduino Ethernet shields.
12+
13+
## Solution
14+
15+
You can find different solutions on the internet - most of them require soldering additional capacitor (and resistor) to the Arduino Ethernet shield. However, there is much easier and more elegant solution: use SW method to reset / initialize the W5x00 chip.
16+
17+
#### 1. Cut the connection between W5x00's RST pin and Arduino's RST pin.
18+
19+
Keep in mind that there are actually 2 connections between W5x00's RST pin and Arduino's RST pin. You need to cut both of them, simply by bending appropriate pins:
20+
21+
- **Bend the RESET pin on the Ethernet shield.**
22+
- **Bend one pin within the ICSP connector on the Arduino board** (see below)
23+
24+
<img src="pics/reset_bridges_Ethernet.jpg" alt="HW" style="zoom:100%;" />
25+
26+
#### 2. Connect W5x00's RST pin to an unused Arduino pin 7
27+
28+
Attach the ethernet shield to the Arduino board. Use wire (male/male jumper wire) to connect RESET pin and pin 7 on the Ethernet shield.
29+
30+
#### 3. Reset the W5x00 chip programmatically
31+
32+
Within your Arduino sketch, pull down pin 7 to reset (initialize) the W5x00 chip. Since the HW method to reset the W5x00 chip will no longer work (W5x00 will not reset/initialize automatically after power up), you **++must++** pull down pin 7 before calling Ethernet.begin().
33+
34+
If you are using one of my Arduino projects ([Modbus RTU ⇒ Modbus TCP/UDP Gateway](https://github.com/budulinek/arduino-modbus-rtu-tcp-gateway), [Arduino Sensors UDP Gateway](https://github.com/budulinek/arduino-sensors-udp-gateway) or [Arduino Altherma UDP Controller](https://github.com/budulinek/arduino-altherma-controller)), the software method to reset (initialize) the W5x00 chip is already implemented within my code.
35+
36+
If you want to reset the W5x00 chip programmatically in your own sketch, use this code to pull down pin 7 before calling Ethernet.begin(). This is the code which works for me:
37+
38+
```
39+
pinMode(7, OUTPUT);
40+
digitalWrite(7, LOW);
41+
delay(25);
42+
digitalWrite(7, HIGH);
43+
delay(500);
44+
```

README.md

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Modbus RTU ⇒ Modbus TCP/UDP Gateway
2-
Arduino-based Modbus RTU to Modbus TCP/UDP gateway with web interface. Build your own Modbus gateway from off-the-shelf components (Arduino + ethernet shield + TTL to RS485 module). The gateway allows you to connect Modbus RTU slaves (sensors, energy meters, HVAC devices, etc.) to Modbus TCP/UDP masters (such as home automation systems). Once you have your Modbus gateway up and running, you can adjust its settings through web interface.
2+
Arduino-based Modbus RTU to Modbus TCP/UDP gateway with a web interface. Build your own Modbus gateway from off-the-shelf components (Arduino + ethernet shield + TTL to RS485 module). The gateway allows you to connect Modbus RTU slaves (sensors, energy meters, HVAC devices, etc.) to Modbus TCP/UDP masters (such as home automation systems). Once your Modbus gateway is up and running, you can adjust its settings through the web interface.
33

44
* [What is it good for?](#what-is-it-good-for)
55
* [Technical specifications](#technical-specifications)
@@ -27,30 +27,30 @@ Allows you to connect your Modbus devices (sensors, energy meters, HVAC devices,
2727

2828
# Technical specifications
2929

30-
* slaves are connected via RS485 interface:
30+
* slaves are connected via the RS485 interface:
3131
- up to 247 Modbus RTU slaves
32-
* master(s) are connected via ethernet interface:
32+
* master(s) are connected via the ethernet interface:
3333
- up to 6 Modbus TCP masters (depending on hardware)
3434
- unlimited number of Modbus UDP masters
3535
* RS485 interface protocols:
3636
- Modbus RTU
37-
* ethernet interface protocols:
37+
* Ethernet interface protocols:
3838
- Modbus TCP
3939
- Modbus UDP
4040
- Modbus RTU over TCP
4141
- Modbus RTU over UDP
42-
* supports broadcast (slave address 0x00)
42+
* Modbus broadcast (slave address 0x00)
4343
* supports all Modbus function codes
4444
* supports error codes:
4545
- codes 1~8 are forwarded from slaves
4646
- codes 10, 11 are generated by the gateway
47-
* diagnostics via web interface:
48-
- send Modbus request and recieve Modbus response
49-
- scan Modbus slaves on RS485 interface
47+
* diagnostics via the Web interface:
48+
- send Modbus requests and receive Modbus response
49+
- scan Modbus slaves on the RS485 interface
5050
- queue (buffer) status
5151
- counters ("RTU Data", "Ethernet Data", "Modbus Statistics") are periodically saved to EEPROM (every 6 hours)
52-
- unsigned longs are used, rollover of counters is synchronized
53-
- content of the Modbus Status page is updated in the background (fetch API), javascript alert is shown if connection is lost
52+
- unsigned longs are used, counter rollovers are synchronized
53+
- the Modbus Status page updates dynamically in the background (fetch API), a javascript alert is shown if the connection is lost
5454
* optimized TCP socket management (web interface and Modbus TCP):
5555
- gateway always listens for new web and Modbus TCP connections
5656
- existing connections are kept alive (persistent), unless the gateway runs out of available sockets
@@ -73,7 +73,7 @@ Get the hardware and connect together:
7373

7474
* **Arduino Nano, Uno or Mega** (and possibly other boards with ATmega chips).<br>On Mega you have to configure Serial in advanced settings in the sketch.
7575
* **Ethernet shield with WIZnet chip (W5100, W5200 or W5500)**.<br>The ubiquitous W5100 shield for Uno/Mega is sufficient. If available, I recommend W5500 Ethernet Shield. You can also use combo board MCU + ethernet (such as ATmega328 + W5500 board from Keyestudio).<br>ATTENTION: Ethernet shields with ENC28J60 chip will not work !!!
76-
* **TTL to RS485 module with an automatic flow direction control**.<br>You can buy cheap modules with MAX485, MAX3485, MAX13487, SP485 or SP3485 chips (some of these modules are branded as "XY-017", "XY-485", "XY-G485", etc.) from Aliexpress and other marketplaces.<br>ATTENTION: Some TTL module manufacturers invert TX and RX !!! If you experience problems, try to swap TXD and RXD.<br>ATTENTION: Avoid those ubiquitous MAX485 modules with manual direction control (DE and RE pins). They will work (use Arduino pin 6 for DE+RE), but are NOT recommended (no auto-direction, no ESD protection, no hot-swap protection) !!!
76+
* **TTL to RS485 module with an automatic flow direction control**.<br>You can buy cheap modules with MAX485, MAX3485, MAX13487, SP485 or SP3485 chips (some of these modules are branded as "XY-017", "XY-485", "XY-G485", etc.) from Aliexpress and other marketplaces.<br>ATTENTION: Some TTL module manufacturers invert TX and RX !!! If you experience problems, try to swap TXD and RXD.<br>ATTENTION: Avoid those ubiquitous MAX485 modules with manual direction control (DE and RE pins). They will work (use Arduino pin 6 for DE+RE), but are not recommended (no auto-direction, no ESD protection, no hot-swap protection) !!!<br>ATTENTION: Modules with automatic direction control are recommended. But be aware that switching the direction takes time (see this [issue](#rs485-automatic-direction-control))
7777
* **External power supply**.<br>Use regulated 5V external power supply for both the Arduino (+ the ethernet shield) and the RS485 module.<br>ATTENTION: By using the 5V pin, you are bypassing Arduino's built-in voltage regulator and reverse-polarity protection curcuit. Make sure your external power supply does not exceed 5,5V !!!
7878

7979
<img src="pics/fritzing.png" alt="fritzing" />
@@ -83,6 +83,10 @@ Here is my HW setup:
8383
Terminal shield + Arduino Nano + W5500 ethernet shield (from RobotDyn, no longer available) + TTL to RS485 module (automatic flow control)
8484
<img src="pics/HW.jpg" alt="HW" style="zoom:100%;" />
8585

86+
And here is another (much nicer) implementation by [adicorra](https://github.com/adicorra):
87+
[KKSB Arduino Case](https://kksb-cases.com/products/kksb-arduino-case-for-arduino-uno-and-arduino-mega-space-for-arduino-shield) (incl. [DIN adapter](https://kksb-cases.com/products/kksb-din-rail-clip-including-screws)) + Arduino Uno + ethernet shield + [DSD Tech SH-U12 TTL to RS485 Adapter](https://www.deshide.com/product-details.html?pid=304606)
88+
<img src="pics/adicorra.jpg" alt="HW" style="zoom:100%;" />
89+
8690
# Firmware
8791

8892
You can either:
@@ -190,7 +194,7 @@ Enjoy :-)
190194

191195
**Stop Bits**. 1 or 2 stop bits.
192196

193-
**Inter-frame Delay**. Delay (ms) between the end of reading Modbus RTU frame and writing new frame. Higher Frame Delay is needed for RS485 modules with automatic flow control. Increase Frame Delay if you have very short polling period and Response Timeouts in stats. The minimum Inter-frame Delay is calculated from baud rate according to Modbus standards.
197+
**Inter-frame Delay**. Delay (ms) between the end of reading Modbus RTU frame and writing new frame. Higher Inter-frame Delay is needed for RS485 modules with automatic flow control. Increase Frame Delay if you have very short polling period and Response Timeouts in stats. The minimum Inter-frame Delay is calculated from baud rate according to Modbus standards.
194198

195199
**Response Timeout**. Timeout for Modbus RTU response. Increase Response Timeout if you see Response Timeouts in Modbus statistics.
196200

@@ -251,11 +255,19 @@ The code was tested on Arduino Nano, Uno and Mega, ethernet chips W5100 and W550
251255
* The random number generator (for random MAC) is seeded through watch dog timer interrupt - this will work only on Arduino (credits to https://sites.google.com/site/astudyofentropy/project-definition/timer-jitter-entropy-sources/entropy-library/arduino-random-seed)
252256
* The restart function will also work only on Arduino.
253257

254-
## Ethernet sockets
258+
## W5x00 Chip Reset
259+
260+
Sometimes the gateway is running fine for days but after power-up or brief loss of power (caused for example by undervoltage), ethernet connection is lost. What is the problem? The W5x00 chip on the Arduino Ethernet Shield is not initialized correctly upon power-up. There is an easy solution to the issue described in a separate [document here](Ethernet_SW_Reset.md).
261+
262+
## RS485 Automatic Direction Control
263+
264+
It is recommended to use TTL to RS485 modules with automatic direction control. But be aware that switching the direction takes time (up to cca 100 ms depending on the module type). If you have a Modbus slave with very short response time, the Modbus response may arrive before the module switches direction. As a result, the response is not detected by the gateway (see [issue #35](https://github.com/budulinek/arduino-modbus-rtu-tcp-gateway/issues/35)).
265+
266+
## Ethernet Sockets
255267

256268
The number of used sockets is determined (by the Ethernet.h library) based on microcontroller RAM. Therefore, even if you use W5500 (which has 8 sockets available) on Arduino Nano, only 4 sockets will be used due to limited RAM on Nano.
257269

258-
## Memory
270+
## Memory Limitations
259271

260272
Not everything could fit into the limited flash memory of Arduino Nano / Uno. If you have a microcontroller with more memory (such as Mega), you can enable extra settings in the main sketch by defining ENABLE_DHCP and/or ENABLE_EXTENDED_WEBUI in advanced settings.
261273

arduino-modbus-rtu-tcp-gateway/arduino-modbus-rtu-tcp-gateway.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
v7.2 2023-10-20 Disable DHCP renewal fallback, better advanced_settings.h layout
2626
ENABLE_EXTENDED_WEBUI and ENABLE_DHCP is set by default for Mega
2727
v7.3 2024-01-16 Bugfix Modbus RTU Request form, code comments
28-
v7.4 2024-XX-XX CSS improvement, code optimization, simplify DHCP renew
28+
v7.4 2024-12-16 CSS improvement, code optimization, simplify DHCP renew, better README (solution to ethernet reset issue)
2929
*/
3030

3131
const byte VERSION[] = { 7, 4 };

pics/adicorra.jpg

233 KB
Loading

pics/reset_bridges_Ethernet.jpg

90.1 KB
Loading

0 commit comments

Comments
 (0)