Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

Baud Rate change within program

Hi Nordic,

1.I am running  (C:\ncs\v2.1.0-rc2\zephyr\samples\drivers\uart\echo_bot) but i need to change baud rate within program

2. I Can Change my baud rate using overlay file

3. But I dont want overlay file i need to make changes within program

Parents Reply
  • Using the echo_bot sample as a starting point, you can do something like this:

    struct uart_config uart_config_current;
    
    if(uart_config_get(uart_dev, &uart_config_current) != 0)
    {
    	printk("uart_config_get() returned error");
    }
    
    uart_config_current.baudrate = 1000000;
    
    if(uart_configure(uart_dev, &uart_config_current) != 0)
    {
    	printk("uart_configure() returned error");
    }
    else
    {
    	printk("UART baudrate changed successfully");
    }

    If you then run a serial terminal at 1M baudrate, it should output some "garbage" (from the initial output at 115200 baudrate) and then print "UART baudrate changed successfully".

Children
Related