Added baudrate detection to esp32-hal-uart and HardwareSerial #1961
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.
Added function uartDetectBaudrate() and wrapped it into HardwareSerial::begin(). With this change it is possible to detect the baudrate on a serial port. Of course there must be incoming data on the serial port for detection to be possible. The uart can not detect other parameters like number of start- or stopbits, number of data bits or parity. For detection, if data is inverted is not important (of course for reading inversion is important).
To detect baudrate pass a 0 ('zero') for the baudrate and a timeout as the last parameter. Serial data must appear before the timeout, otherwise the Serial port will be left uninitialized. To detect if baudrate detection was successful test with HardwareSerial::baudRate() to return a value not equal to 0.
Pay attention: HardwareSerial::baudRate() may return an approximate baudrate. This has nothing to do with this PR but is due to rounding in the library. E.g. a baudrate of 115200 returns 115201.
Example usage: