-
Notifications
You must be signed in to change notification settings - Fork 350
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
compatibility problem with ESP32? #96
Comments
I found out it's definitely a software issue. The first read after reboot works, then most reads result in E2(timeout), but sometimes there is a response from the slave device and but that results in E0 (wrong slave address) error. Please help... |
I found the problem. There is a problem with UART Serial(2). If you use Serial(1) it keeps working. |
Hi. Can you post your code sample. Are you using a MAX485 TTL to RS485 board ? |
Hi, sample code: espressif/arduino-esp32#991 (comment) and yes, I'm using the MAX485 board, it runs fine on CMOS levels |
thanks for the info. i can see that I am sending the data out the ttl side because when I hookup a ttl to usb then I can see data. But nothing happens on the rs485 side. how did you wire it? you say it works with 3.3 volt as the board stated it is a 5v board. |
you need to tie DE an RE together, and define in the pre- and post transmission routines to set this pin 'high' to transmit, and a 'low' to receive. Easiest way to verify is by scope. if you son't see a pulsetrain between the A-B lines, try swapping TX and RX. |
Also can you post your full code. You state you need to add a delay but is that before or after ? |
Did you connect VCC to the 3.3v of the ESP32 and ground to the ground of the ESP32 on the RS485 side ? |
Hi, I cannot post full code since it's a professional application. But yes, I'm using a very similar board, powered by 3,3V and ground coming from the ESP32. The delays are not so important. You just need to make sure when you're sending modbus commands, the previous ones had the time to execute. You can do this by adding delays, but there are also better ways. |
post you schematic and code, I'll check |
OK I have the board hooked up the following way. Sorry for the bad diagram. Here is the code. It is just sample code to get the RS-485 on the go. It is not the real program it will form part of as I have the same issue you do lol.
|
Should I check A and B with the scop or A with ground and then B with ground? I know the serial line is working as I connected a TTL to USB and can see the data that is sent out via the serial line |
you're trying to read modbus information from the Serial-UART??? your modbus-uart is called 'modbusSerial', so you should try to read from that one. you're also making it complicated by trying to decypher the modbusSerial info yourself. Try using the node.readmultipleregisters(start index, quantity) followed by node.getresponsebuffer(index) And by using this large delay in the post-tranmission loop you're probable missing the modbus slave answer. |
RS485 is differential transmission so you should measure between A-B |
Hi. MobusSerial is just a variable name of the UART handle of UART1. I could call it Sarial1 also. I like to keep descriptive names. I use a three UARTS on the ESP32. So giving it a name helps to make the code readable. I do pass the modbus master the modbus serial handlel
Where you see that I did a printline to mobusSerial I tested to see if I could see data on the line. That is now commented out. I saw that the data would be scrambled if I use all 3 at the same time. I added the Flush and that will fix the UART and then all 3 work fine, Here is a better diagram. |
I dont understand this statement "you're also making it complicated by trying to decypher the modbusSerial info yourself. Try using the node.readmultipleregisters(start index, quantity) followed by node.getresponsebuffer(index)" Where do you see I am reading the modbus data myself? I am doing it via the Modbus Master lib. |
The Checkserial stuff is my command structure that I use to send commands via the serial port. If I send a U1 it will call the function stop_vsd() that will call via modbus. U2 will start and U3 will read the register. That is on serial line that the serial monitor works on. You can ignore that. It has nothing to do with the modbus part. |
I see. you should definitely see the pulse train on the AB lines, no use in looking further before you see a pulsetrain. If you have pulses on Tx, and RE/DE is at the right level, you should see pulses between AB.... and the node.readholdingregisters doesn't return the data, it returns a constant indicating success/failure to transmit. You should read from the responsebuffer. I only got serial(1) working, there's a problem with serial(2), but maybe you've fixed it with that flush() command. |
OK let me have a look. I have code that is already working on a Raspberry Pi that I wrote in Python. I am just re writing it to see if all will work on the ESP32. That is why I thought I had to use
as this is what I did in Python using minimalmodbus
So does readHoldingRegisters only do the function and I need to read it from a buffer somewhere ? |
Did I do the wiring correct ? I do not see any pulses on the A B side. But maybe my scope does not pick it up as I have a wifi iPad scope. |
OK I got it working.
Now I can start and stop. Still need to figure out the read but at least now I have comms. Thanks for the help. |
no problem, good you got it working. Did you get it working with the third UART, using serial(2)? |
I am using all 3 UARTs now.
|
For some reason my new ESP32 doit V1 has different issues than the ones I received in the past. |
Did you fix the esp32-hal-uart.c code ?. You have to comment out
|
Hi Jaco, I'll try that tomorrow. I just compared scope images on the working max485 driver on arduino mega (TTL 5V), and then the same driver on the ESP32(CMOS 3.3V). They are very different: on the ESP:
on the mega (where everything works):
I think there are different versions of the MAX485 (bought on ALIEX), my latest batch doesn't seem to like CMOS 3.3V level. I'll also try some level shifting tomorrow |
Hallelujah, got it working. This MAX485 driver board (the one we all use?); contrary to what I claimed earlyer, they don't all work on 3.3V although the chips appear to be the same type!!! I tried the haluart fix, but it doesn't work anymore after that, so changing nothing is better for me :-) So this setup works... |
I have ordered these 2 3.3v and 5 v ttl to RS-485 boards. Will see how they are when I get them. These also don't need to have a transmit pin so it frees up another GPIO pin. |
interesting, let us know your feedback when you've tested them. |
Just tried this module on ESP32: works like a charm, no additional components required, all 3.3V, and no DE line (it's automatic detection) |
Hi, can you please provide the working code. |
I am getting responsetimeout error, while reading holding resisters |
my code is derived from the example sketches provided by the 4-20mA Modbus library. Just comment out the driver enable lines. Maybe the problem is your application that host doesn't respond or incorrect wiring? You could check with scope if signal is sent via AB-lines to the host. |
Hi, #include <HardwareSerial.h> HardwareSerial MySerial1(1); void preTransmission() MySerial1.flush(); void postTransmission() } void setup() {
} void loop() {
} |
Using a max485 on an ESP32, it can be done but I don't recommend it because it's made for 5V operation and it behaves funny on 3.3V. Instead I strongly suggest to use the hardware from my last link, that one is compatible with 3.3V and very easy to use. |
Hi, i need help about that, i have a TTGO LORA32 V2.1.6 and a TTL to RS485 module same to it used Jaco, i need to write and read holding registes from a PLC and i made this code: #include <ModbusMaster.h> #define MAX485_DE 36 SSD1306 display(0x3c, 21, 22); uint16_t resultMain; ModbusMaster node; HardwareSerial ExtraSerial1(1); void postTransmission() display.init(); pinMode(MAX485_RE_NEG, OUTPUT); //init int receive mode Serial.begin(115200); //Modbus Slave ID 1 node.begin(1, ExtraSerial1); //callbacks allow us to configure the RS485 transceiver correctly } void loop() { display.clear(); Serial.print("resultMain1: "); i=i+1; //delay(1000); resultMain = node.readHoldingRegisters(0x00, 1); if (resultMain == node.ku8MBSuccess) delay(1000); the command "writeSingleRegisters" is writing fine but the answer is "0xe2" for both "resultMain" and "resultMain1", so i can not watch any holding registers requested. Can you help me please |
to avoid watchdog timeouts in ESP32 when waiting for a slave response (or when no slave connected), you can disable the watchdog as described above. However this is not ideal. Also when working with multi-thread freeRTOS, the operating system should have the chance to jump to another task when waiting for slave response. This can be done by inserting a 1ms delay in the transmission loop, it also avoids watchdog timeouts: in the modbusMaster.ccp file:
|
Hi guys, Im trying to connect a ESP32 DEV KIT V1 with a MODBUS RTU Slave through this device. However, I have not received a response, even i tested it with SymplyModbusMaster, this adapter and my laptop successfully: This is my arduino code, I am using the 4-20ma library: "
" When wired, I get the error E0, but the slave has this address (1) and comm settings... I have read that there is an issue with ESP32 and MODBUS RTU, and I modified the Modbusmaster.cpp with a 1 ms delay in line, but then I get the E2 error... Do you recommend use the board you mentioned @TLS1000 ??? > https://www.aliexpress.com/item/Stable-UART-Serial-Port-to-RS485-Converter-Function-Module-RS485-to-TTL-Module/32442485555.html Or could you suggest something to establish communication?? |
ModbusMaster version
[Version of the project where you are encountering the issue]
Arduino IDE version
[Version of Arduino IDE in your environment]
Arduino Hardware
[Hardware information, including board and processor]
Platform Details
[Operating system distribution and release version]
Scenario:
[What you are trying to achieve and you can't?]
Steps to Reproduce:
[If you are filing an issue what are the things we need to do in order to repro your problem? How are you using this project or any resources it includes?]
Expected Result:
[What are you expecting to happen as the consequence of above reproduction steps?]
Actual Result:
[What actually happens after the reproduction steps? Include the error output or a link to a gist if possible.]
Feature Request
Narrative:
Acceptance Criteria:
The text was updated successfully, but these errors were encountered: