This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Config baud rate at Run time on the Thingy91

Hi Dev team,

I am working with the Thingy91 and I have connected it to an external sensor through UART-1. 

I am connecting another sensor through the same UART but with a different baud rate. In order to make them both running through the same UART, I need to be able to configure the baud rate at run time. 

Could you let me know how this could be done ? 

Right now, I have my config as : thingy91_nrf9160ns.overlay file.

&uart1 {
	current-speed = <9600>; 
	status = "okay";
	tx-pin = <13>;
	rx-pin = <16>;
	rts-pin = <14>;
	//cts-pin = <05>;	
};

The current baud rate is 9600 , but I would like it to switch between 9600 and 1200 at run time.

Regards,

Adeel.

Parents
  • Hi, Adeel!

    This should be no problem! I've attached a simple demonstration below that updates the baudrate to 9600. Notice how the peripheral must be disabled properly before the register can be updated.

     

    NRF_UARTE1->ENABLE = UARTE_ENABLE_ENABLE_Disabled;
    NRF_UARTE1->EVENTS_RXTO = 0; 
    NRF_UARTE1->TASKS_STOPRX =1; 
    
    while (NRF_UARTE1->EVENTS_RXTO == 0); // Wait for RXTO 
    /* Do you stuff here*/
    NRF_UARTE1->BAUDRATE = (UARTE_BAUDRATE_BAUDRATE_Baud9600 << UARTE_BAUDRATE_BAUDRATE_Pos);
    printk("Value of baudrate register : %d \n",NRF_UARTE1->BAUDRATE);
    
    NRF_UARTE1->ENABLE = UARTE_ENABLE_ENABLE_Enabled;


    Best regards,
    Carl Richard

Reply
  • Hi, Adeel!

    This should be no problem! I've attached a simple demonstration below that updates the baudrate to 9600. Notice how the peripheral must be disabled properly before the register can be updated.

     

    NRF_UARTE1->ENABLE = UARTE_ENABLE_ENABLE_Disabled;
    NRF_UARTE1->EVENTS_RXTO = 0; 
    NRF_UARTE1->TASKS_STOPRX =1; 
    
    while (NRF_UARTE1->EVENTS_RXTO == 0); // Wait for RXTO 
    /* Do you stuff here*/
    NRF_UARTE1->BAUDRATE = (UARTE_BAUDRATE_BAUDRATE_Baud9600 << UARTE_BAUDRATE_BAUDRATE_Pos);
    printk("Value of baudrate register : %d \n",NRF_UARTE1->BAUDRATE);
    
    NRF_UARTE1->ENABLE = UARTE_ENABLE_ENABLE_Enabled;


    Best regards,
    Carl Richard

Children
Related