Open luisgcu opened 7 years ago
I too have a similar problem, the esp8266 getting soft reset every time when the modbus device goes offline.
I got same problem, too. But the chip what I use is SP3485 rather than MAX3485.
I think I found one of the reasons for this problem. When my MODBUS_MASTER is working under the software serial port, it resets by WDT when the slave disconnects. But when my MODBUS master works on the hardware serial port, it works normally no matter the slave is disconnected or not. So I think the problem lies in the software serial port.
Hi, i'm having the exact same problem. I'm using MAX3485 with level shifting. Did someone find a solution?
hi, I went a little deeper on the working of the software wathdog of the ESP8266. Problem is the waiting on a response from a modbus slave (espacially during testing with no slave connected), during that time the software wathdog fires because it thinks the program hangs.
you can solve it elegantly by disabling the watchdog during modbus reads: ESP.wdtDisable(); result = node.readHoldingRegisters(15206,3); ESP.wdtEnable(1);
I have no more soft WDT resets anymore
hi, I went a little deeper on the working of the software wathdog of the ESP8266. Problem is the waiting on a response from a modbus slave (espacially during testing with no slave connected), during that time the software wathdog fires because it thinks the program hangs.
you can solve it elegantly by disabling the watchdog during modbus reads: ESP.wdtDisable(); result = node.readHoldingRegisters(15206,3); ESP.wdtEnable(1);
I have no more soft WDT resets anymore
Seems it works. Now it works more stable, haven't seen any WDT reset.
ModbusMaster version
[2.0.1]
Arduino IDE version
[1.8.2]
Arduino Hardware
[ESP8266, NodeMCU1.0 ESP-12E]
Platform Details
[Operating system distribution and release version]
Scenario:
[Read holding register (10) from a VFD, Max485 is conected to GPIO, 14,12 on the ESP8266 using the software serial]
Steps to Reproduce:
[II am able to read modbus registers without problem , the only problem that I have is, if I disconnect the RS485 conection from the MAX485 then the ESP8266 crash and reset over and over again]
THE CODE
include
include
/! We're using a MAX485-compatible RS485 Transceiver. Rx/Tx is hooked up to the hardware serial port at 'Serial'. The Data Enable and Receiver Enable pins are hooked up as follows: /
define MAX485_DE 5 // was 5(moteino) //and was 2(d4) on esp8266 but have trouble
define MAX485_RE_NEG 4 // was 6
define NANO_HSP(m,n) (m *100+ n-1) ///<
ModbusMaster node;
SoftwareSerial mySerial(14, 12, false,256); //esp8266 void preTransmission() { digitalWrite(MAX485_RE_NEG, 1); digitalWrite(MAX485_DE, 1); }
void postTransmission() { digitalWrite(MAX485_RE_NEG, 0); digitalWrite(MAX485_DE, 0); }
void setup() { pinMode(MAX485_RE_NEG, OUTPUT); pinMode(MAX485_DE, OUTPUT);
// Init in receive mode digitalWrite(MAX485_RE_NEG, 0); digitalWrite(MAX485_DE, 0); Serial.begin(19200); // Commander SK @ 19200 mySerial.begin(19200); Serial.println("Modbus-Master");
// Modbus slave ID 1 node.begin(1, mySerial); // Callbacks allow us to configure the RS485 transceiver correctly node.preTransmission(preTransmission); node.postTransmission(postTransmission); }
bool state = true;
void loop() { uint8_t result;
result=node.readHoldingRegisters(NANO_HSP(18,11), 10); //
if (result == node.ku8MBSuccess) { Serial.println("Data: "); // Serial.println(node.getResponseBuffer(1)); for (uint8_t j = 0; j < 10; j++) Serial.println(node.getResponseBuffer(j),DEC);
} else { Serial.println("NO- RESPONSE"); //mySerial.flush(); }
delay(3000); Serial.println("running..."); }
#############
THE Crash from the ESP8266
Soft WDT reset
ctx: cont sp: 3ffef4f0 end: 3ffef820 offset: 01b0
##############################
thanks for any guidance.