-
Notifications
You must be signed in to change notification settings - Fork 195
Timeout on ModbusRTU with Esp32S2 #85
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
Comments
Hello,
|
Hello, sorry for the long response, but I was pretty bussy with other stuff. Unfotunetly, the code that you have provided doesn't work in my case. I've eaven tried to steer the RTS pin manualny, but without any success. I've been measuring signals on the pins:
Maybe there is a problem with my PCB? In theory, if I connect pin RE, and DE, the transciver should work automatically. Could you also look at my schematic? I'm pretty new to the world of electronics, so I would be grateful for any advice that you have. |
How about to specify pins for Serial1 ? Serial1.begin(19200, SERIAL_8E1, GPIO_RXD, GPIO_TXD); From the library perspective i can suggest only to play with RTS direct/inverse control: mb.begin(&Serial1, GPIO_RTS, false); All other things might be hardware related. (Schematics looks ok in my opinion) Just for reference: bool begin(SoftwareSerial* port, int16_t txPin=-1, bool direct=true);
bool begin(HardwareSerial* port, int16_t txPin=-1, bool direct=true);
Assing Serial port. txPin controls transmit enable for MAX-485. |
I've just tried what you suggested, and I think that I can see what is causing the issue. After I applied your code, I was able to read from the RTS pin, and it looked like this: As you can see, the RTS pin is changing to LOW state about 800 microseconds too quickly, and I'm unable to finish my transmission. I guess that transmission length can vary, so I would assume than simple delay of RTS pin is not an option. Do you think there is anything I can do about it from the software side? |
After some investigation i found that in some situations Modbus object has reported as free before previous transaction ended. |
I've tried out the latest code base, and unfortunately, that doesn't resolve my issue. I'm still getting the same result on the osciloscope. However I've tried to modify the rawSend, and I managed to get it working. Now it looks like this:
I've added |
Just for the sake of trying.... try removing "portENTER_CRITICAL(&mux);" and "portEXIT_CRITICAL(&mux);" and check if you see any change. @emelianov Why do you need a mutex if internally the Serial.write and Serial.flush use UART_MUTEX_LOCK ? https://github.com/espressif/arduino-esp32/blob/master/cores/esp32/esp32-hal-uart.c#L377 |
@DawidDiaco, |
@gonzabrusco, |
What version of ESP are you using for testing? ESP32S2 is fairly new, and arduino libs that I'm using are still in beta version, so they might be buggy. I'm also wondering if there is any important architectural difference between these two, that I'm missing out. I've only made sure that the oscilators are the same speed (8Mhz), but maybe there is something else that may differ - here is the datasheet for ESP32S2. @gonzabrusco I've tried it. Doesn't change anything. |
@DawidDiaco it seems Serial.flush() is not working in ESP32S2 ?? Could you test a simple code (without modbus) and test if Serial.flush is working? (write some data to serial port, then flush it and then switch a digital pin output). You could set a slow baudrate so it's more visible. It seems that in your case Serial.Flush is not blocking and still proceeds with the execution of the program. |
@DawidDiaco, From other hand delay you've added is ok. |
You could try Serial.flush(false) and see if it makes a difference? (setting it to false discards RX data and sends out TX data). |
Setting this parameter (not matter if i set it to true or false) doesn't affect anything. The transmission look exactly the same as in my previous post. |
Ok it was just a random test. This clearly is an espressif problem. |
Hello,
I was trying to use your library in order to use my Esp32S2 as a master device. I'm using ST3485EBD transceiver and I successfully managed to send commands to slave device, and I can see that it does react on my requests. Unfortunately, no matter what I was doing I'm unable to readback from the device, and I'm getting a timeout. I suspect that my issue might be related with the fact that i don't do anything with the RTS pin. For now my code looks like this:
The text was updated successfully, but these errors were encountered: