-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
Serial(2) only works first loop after reboot, Serial(1) works fine, with modbusmaster #991
Comments
I tried using the default UART2 pins 16 and 17, no improvement. |
Wich modbusmaster library are you using? |
Hi, I'm using the https://github.com/4-20ma/ModbusMaster)
loop:
Now when I change And although the common MAX485 Arduino board is specified for TTL use, it runs fine at CMOS levels (and powered by 3.3V). |
same issue for me using UART1 works forever |
Most likely it's related to hardware issue of UART2. RS485 communication using ESP32's UART2 hits this problem as it needs to flush send buffer to exit RTS state. In esp-idf, workaround has been applied but not in Arduino-ESP32. In my case, I abandoned using Arduino-ESP32's HardwareSerial and used esp-idf's uart library instead by including driver/uart.h. (Implementing modbus by my own was a bit pain in the ass, though) |
@shimarin maybe you are right about the hardware bug.. could you extend and apply the workaround on the Arduino HardwareSerial library too? |
@baggior Well, I wish I was someone who could do it. Rewriting my code to use esp-idf's uart library was the best I could do. |
who could correct the HardwareSerial library and include the uart fix, then? |
yes, having only UART1, (most of us use UART0 for IDE communication) feels like a limitation on ESP32. Hopefully someone with the right skillset can fix this. |
I think there have been some changes lately, does this problem still persist? |
this problem still persist |
JacoFourie got all three UARTS working, you need to add a serial.flush() in the pretransmission routine. I haven't tested it. |
@TLS1000 thank you for your reply. below works well. HardwareSerial uart(2);
...
loop(){
uint8_t data[11] = {0x01, 0x10, 0x01, 0x02, 0x00, 0x01, 0x02, 0x00, 0x09, 0x77, 0x74};
uart.write(data, 11);
} output
but let me add a line of code., it output garbled data. HardwareSerial uart(2);
...
loop(){
uint8_t data[11] = {0x01, 0x10, 0x01, 0x02, 0x00, 0x01, 0x02, 0x00, 0x09, 0x77, 0x74};
uart.write(data, 11);
uart.flush(); // next loop output garbled data.
} output
but |
Another clue for finding this issue. I am using Arduino ide with a Wrover module, the uart2.available() function will only respond every 10 seconds if I am initialising uart2 non-inverted. When I enable invert the uart2.available() responds normally. ------UPDATE ----- |
I have been working with ESP32, connected to a SP3485 RS485 driver chip (but should work with others) using a simple circuit to drive the DE/RE pins automatically from the TX line. I have been struggling for some time now to get the Simple Modbus Slave Arduino library to correctly send a response to a Modbus Master. The library was correctly generating the response but on the RS485 side the data was corrupted. As you can see from the above the first message which is a request for data always gives a good response but alll the following message, which just happen to be write messages, are corrupted. This device is oone of a number on the Modbus link so after this set of messages the master moves on to other devices before looping round and repating a set of requests. I have been scanning the various forums looking for a solution and eventually found one that works, Code for transmit function In the sendPacket function I added the 13uS delay after each character and now the software correctly responds to all the messages. My hardware is a purpose designed PCB using an ESP32 WROOM-U, programmed using the Arduino IDE and latest development code for Arduino EPS32 the SDK is Versionv3.2-dev-1055-g3276a1316, the library is heavily modified version of Simple Modbus Slave. The RS485 is provided by a SP3485 RS485 chip using Serial2 ( pins 16 and 17) and no hardware pin for the direction select as this works automatically via a simple circuit that detects when transmission starts With reference to using an ESP WROVER chi with serial2, it cannot be done as pins 16 and 17 are not connected, they are used to handle the PSRAM. One other point of interest that caught me out is that the ESP32 WROVER uses 1.8V Flash and not 3V3 as used by the ESP32 WROOM, this means that the GPIO pin 12 must have different biasing for the WROVER chip, so they are not interchangeable as I first thought. |
With my new project I need all three UARTS, problem still persists... I can use Serial(1) with no problem, when I change to Serial(2) the code only runs once after startup... please help |
I managed to get Serial(2) working with the ESP32Serial.h library |
Please fill the info fields, it helps to get you faster support ;)
If you have a Guru Meditation Error, please decode it:
https://github.com/me-no-dev/EspExceptionDecoder
----------------------------- Remove above -----------------------------
Hardware:
Board: ?DOIT V1 ESP32 Dev Module?
Core Installation/update date: ?11/jul/2017?
IDE name: ?Arduino IDE? ?Platform.io? ?IDF component?
Flash Frequency: ?40Mhz?
Upload Speed: ?115200?
Description:
I'm using modbusmaster library to communicate with some Modbus slave. I initially used hardwareserial(2) because I thought serial1 was for communicating to Arduino IDE. With serial2 I only got response from the Modbus slave the first time after reboot. When I use Serial1 UART it works fine.
this has been reported earlier: [https://github.com//issues/650]
Sketch:
Debug Messages:
The text was updated successfully, but these errors were encountered: