ESP32 RS485driver hardwareserial ModbusMaster
ESP32 RS485driver hardwareserial ModbusMaster
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?
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?
Re: ESP32 RS485driver hardwareserial ModbusMaster
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?
There is also no softwareserial library for the ESP32?
Re: ESP32 RS485driver hardwareserial ModbusMaster
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
:\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
-
- Posts: 1
- Joined: Tue Jan 30, 2018 8:13 pm
Re: ESP32 RS485driver hardwareserial ModbusMaster
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
(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
Re: ESP32 RS485driver hardwareserial ModbusMaster
Hey, I also have this exact problem and I'm really interested to know the solution.
What do we know so far?
Antony
What do we know so far?
Antony
Re: ESP32 RS485driver hardwareserial ModbusMaster
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
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
Re: ESP32 RS485driver hardwareserial ModbusMaster
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
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
Re: ESP32 RS485driver hardwareserial ModbusMaster
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...
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...
Re: ESP32 RS485driver hardwareserial ModbusMaster
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.
Could you share your sketch?
Didn't you try to run the same example using ESP-IDF without Arduino libraries like Wire?
Thanks.
Re: ESP32 RS485driver hardwareserial ModbusMaster
viewtopic.php?f=19&start=20&t=5094
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
antonyc,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.
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: Baidu [Spider] and 95 guests