Serial Device: usart speed change "on the fly"

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
ucasano
Posts: 57
Joined: Mon Aug 06, 2012 1:05 pm
Has thanked: 1 time

Serial Device: usart speed change "on the fly"

Post by ucasano »

Hi,

I need to change the speed of my serial port driver, i.e. at 57600bps, after the serial driver has already been started, i.e. at 9600bps.

In order to do so, I have to start at 9600bps, send the AT command "AT+IPR=57600", wait for OK answer and then switch to 57600.

This is what I think to do:

1) send sdStop()
2) change speed parameter to 57600bps
3) send sdStart()

Could this be working for me?
Thanks.
-g
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Serial Device: usart speed change "on the fly"

Post by Giovanni »

Hi,

You don't need to stop, just call sdStart() again to set new parameters, of course you need multiple configuration structures.

Giovanni
ucasano
Posts: 57
Joined: Mon Aug 06, 2012 1:05 pm
Has thanked: 1 time

Re: Serial Device: usart speed change "on the fly"

Post by ucasano »

Alright, I will do so!
Thanks.
-g
kalevik
Posts: 3
Joined: Wed Dec 21, 2011 1:15 pm

Re: Serial Device: usart speed change "on the fly"

Post by kalevik »

Giovanni wrote:Hi,

You don't need to stop, just call sdStart() again to set new parameters, of course you need multiple configuration structures.

Giovanni


You must be kidding :shock:

If i make user selectable communication parameters (with dip switch), lets say 1200-115200 and 1/2 stop bit, i must wrote 16 configuration structure?

kalevik
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Serial Device: usart speed change "on the fly"

Post by Giovanni »

You can have one structure and change it or multiple constant structures.

Giovanni
kalevik
Posts: 3
Joined: Wed Dec 21, 2011 1:15 pm

Re: Serial Device: usart speed change "on the fly"

Post by kalevik »

Giovanni wrote:You can have one structure and change it or multiple constant structures.

Giovanni


Okay, i understand wrong your answer to ucasano, "of course you need multiple configuration structures".

kalevik
rew
Posts: 383
Joined: Sat Jul 19, 2014 12:59 pm
Has thanked: 2 times
Been thanked: 14 times

Re: Serial Device: usart speed change "on the fly"

Post by rew »

Giovanni wrote:You don't need to stop, just call sdStart() again to set new parameters, of course you need multiple configuration structures.
i
This is inconsistent with lots of other stuff in Chibios: Many things in Chibios don't tolerate being restarted by "just call start again", because they are not in the right "state".
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Serial Device: usart speed change "on the fly"

Post by Giovanni »

Start is meant to be call-able when the device is in "started" state, not when it is in "active" state, you cannot call start when there is an operation in progress.

Serial does not have a defined "active" state and can be always restarted. Look at the assertions in the driver to see the valid states (or the HAL documentation, there are state diagrams there).

Giovanni
Post Reply