-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Function added to detect baudrate #4978
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
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ff2858a
Function added to detect baudrate
7a4d433
Merge branch 'master' into feature/uart_detect_baudrate
8dd845e
Added uart_start_detect_baudrate, detectBaudrate() wrappers for Hardw…
27574a4
Some layout changes to pass Travis tests
223388c
Some more nitty-gritty layout changes to pass Travis tests
d30d9e8
Some even more nitty-gritty layout changes to pass Travis tests
200cf39
Merge branch 'master' into feature/uart_detect_baudrate
8dc44aa
renamed one function to testBaudrate() and updated doc/reference.rst
33d58be
Minor updates to doc/reference.rst
2ac82fd
New lines added
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 hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
34 changes: 34 additions & 0 deletions
34
libraries/esp8266/examples/SerialDetectBaudrate/SerialDetectBaudrate.ino
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#define TIMEOUT (10000UL) // Maximum time to wait for serial activity to start | ||
|
||
void setup() { | ||
// put your setup code here, to run once: | ||
|
||
Serial.begin(115200); | ||
|
||
// Serial.detectBaudrate() may also be called before Serial.begin() | ||
// There must be activity on the serial port for the baudrate to be detected | ||
unsigned long detectedBaudrate = Serial.detectBaudrate(TIMEOUT); | ||
|
||
if (detectedBaudrate) { | ||
Serial.printf("\nDetected baudrate is %lu, switching to that baudrate now...\n", detectedBaudrate); | ||
|
||
// Wait for printf to finish | ||
while (Serial.availableForWrite() != UART_TX_FIFO_SIZE) { | ||
yield(); | ||
} | ||
|
||
// Clear Tx buffer to avoid extra characters being printed | ||
Serial.flush(); | ||
|
||
// After this, any writing to Serial will print gibberish on the serial monitor if the baudrate doesn't match | ||
Serial.begin(detectedBaudrate); | ||
} else { | ||
Serial.println("\nNothing detected"); | ||
} | ||
} | ||
|
||
void loop() { | ||
// put your main code here, to run repeatedly: | ||
|
||
} | ||
|
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.
Are all of these rates valid for both 80MHz and 160MHz CPU speed?
Or rather, has the detection process been tested with both CPU speeds and different baudrates?
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.
These baud rates are common rates. Yes it has been tested with both 80MHz and 160 MHz, and with two devices, one at 9600 baud and one at 115200 baud. I did not test changing the crystal frequency, because I do not know the purpose of changing the crystal frequency.