Serial baudrate change on the fly?

Status
Not open for further replies.

blazini36

Active member
First off, I'm not a software guy. A friend is helping me out with a program and how to go about doing this came up so I figured I'd help try to find an answer.

What would be needed to reinitialize the UARTs with a different baudrate during runtime? Serialx.end doesn't appear to exist in the Teensy lib so is Serialx.begin(baud) sufficient if the UART has already been initialized during the setup code? Maybe preceded by flush/clear?
 
If we're talking about the Teensy 4.x, from experience, you can get away with just doing another SerialX.begin(new_baud_rate).

Unless you're also using hardware handshaking (RTS/CTS), in which case you need to follow it with a SerialX.clear() to make sure that RTS is asserted. If RTS happened to be unasserted when you called begin(), it would stay in that state and you'd never receive another character.
 
Yeah it's a 4.0/4.1. I'm not using flow control but thanks for the mention, may just add the clear() in case RS485 comes into play down the road. We'll give just begin(new_baud) a try. Thanks
 
Status
Not open for further replies.
Back
Top