ESP32 RS485driver hardwareserial ModbusMaster

TLSESP32
Posts: 2
Joined: Wed Jan 10, 2018 11:55 am

ESP32 RS485driver hardwareserial ModbusMaster

Postby TLSESP32 » Wed Jan 10, 2018 12:31 pm

Hi, I'm trying to establish RS485 Modbus communication between ESP32 - RS485 Arduino driver board - Modbus device by using harwareserial(2) and the MODBUSMASTER library.
https://github.com/4-20ma/ModbusMaster

I know the MAXRS485 is TTL and ESP is CMOS, but I tried the code on an Arduino MEGA, and powered the RS485 driver board via 3.3V and it works.

When connected via ESP, I see the pulse train going out of the TX (hardwareserial2 pins 4,5) and on the differential AB lines of the driver, but the Modbus device doesn't seem to respond. I don't see it on scope (differential AB lines).

So I'm assuming a problem with the message sent to the Modbus device. Any idea's? Maybe a problem of compatibility of the modbusmaster library on ESP32?

TLSESP32
Posts: 2
Joined: Wed Jan 10, 2018 11:55 am

Re: ESP32 RS485driver hardwareserial ModbusMaster

Postby TLSESP32 » Thu Jan 11, 2018 9:53 am

From time to time I get a response from the slave device. Still don't know what the cause could be, the pulse train looks very clean so I don't expect a hardware/noise issue.

There is also no softwareserial library for the ESP32?

tka4ev_s
Posts: 1
Joined: Sat Jan 13, 2018 6:15 pm

Re: ESP32 RS485driver hardwareserial ModbusMaster

Postby tka4ev_s » Sat Jan 13, 2018 6:22 pm

hello i want to compiling code modbus for esp 32 but i have error
:\Users\serg\Documents\Arduino\libraries\ModbusMaster-master\src\ModbusMaster.cpp: In member function 'uint8_t ModbusMaster::requestFrom(uint16_t, uint16_t)':

C:\Users\serg\Documents\Arduino\libraries\ModbusMaster-master\src\ModbusMaster.cpp:94:33: error: 'read' is used uninitialized in this function [-Werror=uninitialized]

_u8ResponseBufferLength = read;
cc1plus.exe: some warnings being treated as errors

i can test modbus in analyzer

bertvaneyken
Posts: 1
Joined: Tue Jan 30, 2018 8:13 pm

Re: ESP32 RS485driver hardwareserial ModbusMaster

Postby bertvaneyken » Tue Jan 30, 2018 8:23 pm

I'm using the MAX485 with ESP8266 and Atmega328 without any issue for a long time so I thought I could keep the circuitry and just exchange the mcu.
(I use the SimpleModbusMaster library in Arduino)

The first packet with the ESP32 is processed correctly but the Siglent reveals that all packets after are the first reply nonsense.
I assume Serial.flush() causes the issue.

I've found some usefull threads but I have not distilled a working solution with them:
https://github.com/espressif/arduino-esp32/issues/600
viewtopic.php?f=13&t=1858&start=20

antonyc
Posts: 20
Joined: Thu Dec 07, 2017 12:24 pm

Re: ESP32 RS485driver hardwareserial ModbusMaster

Postby antonyc » Thu Feb 01, 2018 1:07 pm

Hey, I also have this exact problem and I'm really interested to know the solution. :-)

What do we know so far?

Antony

casmeiron
Posts: 4
Joined: Thu Dec 07, 2017 7:39 pm

Re: ESP32 RS485driver hardwareserial ModbusMaster

Postby casmeiron » Thu Mar 08, 2018 7:40 pm

Hi Guys,

I'm having the exact same issue!
@TLSESP32 did you find a solution for your problem?

We're using MAX485 with ESP32 and ModBusMaster library https://github.com/4-20ma/ModbusMaster. The transmitter its working but we never get any response back. The same code works with Arduino UNO.

I would love if anybody could give me any hints on that :|

antonyc
Posts: 20
Joined: Thu Dec 07, 2017 12:24 pm

Re: ESP32 RS485driver hardwareserial ModbusMaster

Postby antonyc » Thu Mar 15, 2018 12:37 am

Hi everyone,

I need this to work, so I decided to try to diagnose and fix it myself.

The problem is that the ESP32 sends gibberish to the Modbus device. The device then doesn't respond because it doesn't understand what the hell the ESP32 is saying!

If you look at the pulse train, you can see that the ESP32 does try to send the pulses correctly, but the timing is out.

It looks like the ESP32 drops the stop bits too early. What it should so is hold the stop bit high for 1.5 times the length of a bit in order to denote a gap in the message. For some reason, the DE/RE timing is out too, they are also released early.

Antony

antonyc
Posts: 20
Joined: Thu Dec 07, 2017 12:24 pm

Re: ESP32 RS485driver hardwareserial ModbusMaster

Postby antonyc » Sat Mar 17, 2018 3:20 pm

Hi everyone,

An update for those who are interested. You can get Modbus to work with the ESP32.

The libraries for Arduino do not work. For some reason, they cause the transmission to the Modbus device to be messed up. The timing is not right and the RE/DE control doesn't work properly. This is because there is *something* in the libraries which doesn't suit the ESP32.

To make ESP32 work with Modbus, you have to manually transmit a Modbus frame to the device with raw bytes, according to the Modbus specification. Also, you need to manually control the DE/RE pin directly too.

Having written a sketch to transmit the data in a raw byte form, I can confirm that the ESP32 can be made to work with Modbus.

Basically, transmit a frame by transmitting individual bytes via serial with a 13us delay in between each byte.

The contents of your transmission depend on which command you're trying to transmit.

For more info, look here: http://www.modbustools.com/modbus.html

Antony...

casmeiron
Posts: 4
Joined: Thu Dec 07, 2017 7:39 pm

Re: ESP32 RS485driver hardwareserial ModbusMaster

Postby casmeiron » Sat Mar 17, 2018 10:00 pm

Hi Antony,
Could you share your sketch?
Didn't you try to run the same example using ESP-IDF without Arduino libraries like Wire?

Thanks.

gregger2k
Posts: 1
Joined: Sat Mar 24, 2018 6:23 pm

Re: ESP32 RS485driver hardwareserial ModbusMaster

Postby gregger2k » Sat Mar 24, 2018 6:58 pm

viewtopic.php?f=19&start=20&t=5094
antonyc wrote:
I've seen this sort of problem before with the ESP32. A few weeks ago, I fixed Modbus, TIA485. It was because the timing of the ESP32/libraries was just messed up. :-(

It looks like I'm going to have to look into the wire library. :-(
antonyc,
Are your fixed Modbus files or examples available anywhere?
I have been using Modbus with the ESP8266 but I am ready to move to the ESP32 and would like the upgrade to go as smooth as possible. Any Information on your fixes would be greatly appreciated.

Thanks, Greg

Who is online

Users browsing this forum: No registered users and 134 guests