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

BLE_NUS change UART baudrate at runtime

Can you please help i use ble _ nus and after few message i need to change uart baudrate. I cloes uart then init uart with new baudrate parameter but everytime MCU goes to in error handler function. Where will be best to put  new uart initialization. I know that after i send via bluetooth to nrf52840 0x06 0x39 0x36 0x30 0x30 and nrf52840 forward this message on tx  in next 200 ms device connected to nrf52840s uart will respond on new baudrate which i have send that it changes.

Parents
  • So what debugging have you done to determine when / where it gets sent to the error handler ?

    As always, I would strongly recommend that you start simple - so make sure that you can get this runtime change working without BLE  first.

    Once you have that working, then move on to integrating it with BLE ...

    I cloes uart then init uart with new baudrate

    So one thing that will be important is to ensure that nothing tries to use any UART-related functions after you close it, but before you're successfully initialised it with the new settings ...

  • in nus_data_handler function i have add condition 

    if (p_evt->params.rx_data.p_data[0] == 0x06 && p_evt->params.rx_data.p_data[1] == 0x39 && p_evt->params.rx_data.p_data[2] == 0x36){
    
    //app_uart_close();
    
    bsp_board_led_invert(3);
    NRF_UART0->BAUDRATE = (UART_BAUDRATE_BAUDRATE_Baud9600 << UART_BAUDRATE_BAUDRATE_Pos);
    }

    if i comment "NRF_UART0->BAUDRATE = (UART_BAUDRATE_BAUDRATE_Baud9600 << UART_BAUDRATE_BAUDRATE_Pos);"

    nrf52840 did not go to  NRF_BREAKPOINT_COND; in app_error_weak.c.

    if i dont put all if  condition block nrf52840  go to  NRF_BREAKPOINT_COND; in app_error_weak.c.

Reply
  • in nus_data_handler function i have add condition 

    if (p_evt->params.rx_data.p_data[0] == 0x06 && p_evt->params.rx_data.p_data[1] == 0x39 && p_evt->params.rx_data.p_data[2] == 0x36){
    
    //app_uart_close();
    
    bsp_board_led_invert(3);
    NRF_UART0->BAUDRATE = (UART_BAUDRATE_BAUDRATE_Baud9600 << UART_BAUDRATE_BAUDRATE_Pos);
    }

    if i comment "NRF_UART0->BAUDRATE = (UART_BAUDRATE_BAUDRATE_Baud9600 << UART_BAUDRATE_BAUDRATE_Pos);"

    nrf52840 did not go to  NRF_BREAKPOINT_COND; in app_error_weak.c.

    if i dont put all if  condition block nrf52840  go to  NRF_BREAKPOINT_COND; in app_error_weak.c.

Children
Related