0

I'm trying to connect a modbus meter to a nodeMcu LoLin v3

I'm using a MAX3485 module to transfer the TTL to a RS485 connection. The modbus server has unitId 1, baud rate 9600 and no Parity

This is the scheme. A e B from the module go to the modbus server device Connection

And this is my simple script

#define DIRECTION D3
#include <ModbusRTU.h>
#include <SoftwareSerial.h>
SoftwareSerial S(D2, D1);
ModbusRTU mb;
bool cb(Modbus::ResultCode event, uint16_t transactionId, void* data) { // Callback to monitor errors
 if (event != Modbus::EX_SUCCESS) {
 Serial.print("Error result: 0x");
 Serial.println(event, HEX);
 
 } else {
 Serial.print("No Error");
 }
 return true;
}
void setup() {
 Serial.begin(115200);
 pinMode(DIRECTION, OUTPUT);
 digitalWrite(DIRECTION, 0);
 S.begin(9600, SWSERIAL_8N1);
 
 mb.begin(&S);
 
 mb.client();
}
void loop() {
 uint16_t res[2];
 if (!mb.slave()) { // Check if no transaction in progress
 mb.readHreg(1, 5, res, 1, cb); // Send Read Hreg from Modbus Server
 while (mb.slave()) { // Check if transaction is active
 mb.task();
 delay(10);
 
 }
 Serial.println("Res");
 Serial.println(res[0]);
 Serial.println(res[1]);
 
 }
 delay(1000);
}

I created a Software Serial on D1 and D2 and i'm trying to read from it but no matter what i do, i keep getting error 4 from the response and 2 values in my reg array i do not where they come from...

Error result: 0xE4
Res
59044
16382

Am I missing something? The modbus server works because i connected it to another client and everything is ok

asked Mar 1, 2022 at 13:41
3
  • If you're using a MAX3485 then VCC should be connected to 3.3V, not VIN (which on some boards cannot provide power but instead can only be used to power the board itself). Commented Mar 1, 2022 at 16:10
  • You might find my answer to this question enlightening... Commented Mar 1, 2022 at 16:20
  • i do not know if it's 3.3V or 5V... i put it on 3.3V on the ESP8266, nothing changes, it's still powered on Commented Mar 1, 2022 at 16:46

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.