-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Fixes UART MODBUS and Loopback issue #6133
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could somebody explain why exactly was the
uart_wait_tx_done()
call replaced here with theuart_ll_is_tx_idle()
loop?The ModbusMaster library is now broken in ESP32S2 v2.0.3, and it was working correctly in v2.0.2 (checked, I switch between the two versions at will). Our project, like many others, uses RS485 and flips the data-enable and read-enable pins, and uses flush() to wait until TX done before switching to RX mode. I still have to do more tests, but this change in particular seems the most likely culprit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@avillacis
Have you read the issues related to this PR? They are related to MODBUS and
flush()
issues.In summary:
uart_wait_tx_done()
returns as soon as data is stored in TXRingBuffer, before the TX FIFO is really empty.uart_ll_is_tx_idle()
returns true just when TX FIFO is completely empty.The code for it is here - but it is the same for all other SoC, thus, the issue you see should happen for any ESP32-xx
https://github.com/espressif/esp-idf/blob/master/components/hal/esp32s2/include/hal/uart_ll.h#L714-L717
I tested
flush()
and I'm sure it works fine.Maybe the issue you see isn't related to this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Objection withdrawn. With access to the actual hardware, I found out that our RS485 card was echoing back request commands, and this echo was previously hidden by the
uart_set_mode()
call. Now I have manually added the call in our own code, and the issue was fixed.However, is there any upstream bug report documenting this issue with
uart_wait_tx_done()
? Is it a true software bug, or a documentation error?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently
uart_wait_tx_done()
works correctly when used withuart_set_mode(uart_num, UART_MODE_RS485_HALF_DUPLEX)
, considering an IDF environment.But for Arduino, it isn't useful because of the its generic UART usage and APIs.
Thus we had to change it for the LL API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By default, IDF starts UART with
uart_set_mode(uart_num, UART_MODE_UART)
and in this case, it returns as soon as data is stored in TXRingBuffer, before the TX FIFO is really empty.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could anyone recommend any solution to be using with Arduino as ModbusMaster is not working any more?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The solution I adopted in my project is as follows:
Where UART_NUM_{N} must be chosen to match Serial{N} as used in the project. The
#include "driver/uart.h"
is to have access to the functionuart_set_mode()
.After this, initialize ModbusMaster as before with the Serial{N}.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@avillacis Thank you. It works fine. I really appreciate your support