-
-
Notifications
You must be signed in to change notification settings - Fork 75
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
Character silent interval issue and Buffer overrun #99
Comments
@mgmidura And I think the calculation is correct.
So the calculated quiet time of 3660 micros is imho correct. Regarding the mentioned uint16_t overflow, the result fits in this type (even @ 300 baud). *) Debug printout is only shown when Serial is already initialized before the Constructor runs ... BTW: Regards |
timing problems can happen due to interrupts. make sure that interrupts are short in execution and the code for checking the modbus read is called enough times. |
You can try my fork. Here is the descripton of the Issue Fix: |
Did not test the code,as I have currently no issues in this realm, just a comment ... Not sure whether releasing the DE signal immediately is a (always) stable approach. I feel it's better to hold DE active for a short moment after the last bit was shifted out, just to make sure the bus is actively driven to a short silence. But it's interesting that 2 people fixed communication issues by changing this delay! |
I can remember: Unfortunately, some Masters do not stick to the timing and start sending immediately after receiving the last byte. I also checked other libraries and none of them wait after sending. (Not even in the original OpenModbus.org library.) fact is: Maybe to explain: Slave: |
Nice discussion ..., and I just like to point out / comment some details. You are right, the DE on the slave can released very short after Serial.flush(), no need to adhere to some Modbus timings at this point. You are also right that some master libraries do not wait when a application calls "send()". As you observed: Too late, or too early, a good question ... Anyway, as the library is driven by periodic poll(), pause between calling poll() may potentially cause an unwanted stretching of the DE delay. Seeing this, I'm happy currently using a ESP32 and automatic transceiver w/o the need of a DE pin :-) Will have a closer look on this detail when I use the lib on a slow Arduino Mini etc, with an DE pin transceiver. |
Yes, nice discussion...:-) Yes, but I only agree with you partially.
and here we are right on topic. And yes, you are right. The problem only occurs on slower processors. I have used an ATMEGA 64 where this was a big problem. With the ESP32 it was practically unnoticeable. PS:: best regards, |
Running on SAMD21G18. I was encountering CRC errors randomly. After over a week of testing I convinced my self that it was not hardware and began noticing the bit timing on the modbus serial stream was violating the required quiet time. I began to look at the library. I believe that the _halfCharTimeInMicroSecond should be set to 50,000 for baud rates less than 19200. Once I made this change I have not seen any erros with over 116000 master slave transactions(16hrs running)
line 226 _halfCharTimeInMicroSecond = 5000000 / baudrate; // 0.5T.
Causes a truncation because value is too large for a uint16_t also I believe it is a typo because for 9600 baud it should be minimum of 3msec quiet time. Based on calculation on
line 230 _lastCommunicationTime = micros() + (_halfCharTimeInMicroSecond * MODBUS_FULL_SILENCE_MULTIPLIER);
the correct value should be 50000.
I also encountered random buffer overruns that would cause my program to lock up. I discovered that before transmit there was no check for this. I eliminated the lockups by adding check for transmission length greater than MODBUS_MAX_BUFFER
line 955 from if (length > 0) change to if ((length > 0) && (length < MODBUS_MAX_BUFFER))
line 981 from if (length > 0) change to if ((length > 0) && (length < MODBUS_MAX_BUFFER))
this eliminated any of my transmission overruns. I realize that the message response is lost in this case but it did not cause a issue for my application,
Thanks for your consideration.
The text was updated successfully, but these errors were encountered: