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

Improve Hardware UART Speed

I am using NRFSDK 1702. I have one NRF52840 as central and multiple peripherals. The central receives data from the peripherals and then transmit the received data via hardware UART interface to the computer. The UART baud rate is set at 115,200. The UART initialization function at the NRF52840 (central) is as follows:

static void uart_init(void)
{
    ret_code_t err_code;

    app_uart_comm_params_t const comm_params =
    {
        .rx_pin_no    = RX_PIN_NUMBER,
        .tx_pin_no    = TX_PIN_NUMBER,
        .rts_pin_no   = RTS_PIN_NUMBER,
        .cts_pin_no   = CTS_PIN_NUMBER,
        .flow_control = APP_UART_FLOW_CONTROL_DISABLED,
        .use_parity   = false,
        .baud_rate    = UART_BAUDRATE_BAUDRATE_Baud115200
    };

    APP_UART_FIFO_INIT(&comm_params,
                       UART_RX_BUF_SIZE,
                       UART_TX_BUF_SIZE,
                       uart_event_handle,
                       APP_IRQ_PRIORITY_LOWEST,
                       err_code);

    APP_ERROR_CHECK(err_code);
}

Previously, the data length from the NRF52840 to the computer is less than 20 bytes each time and the UART is working well. Recently, I found one issue with the hardware UART: when the data length is at 240 a packet, then the UART transfer speed can not catch up and will cause the NRF52840 reset. If I lower the data rate from the peripheral to the central, then the NRF52840 central is working well. 

The UART data transfer function is very simple (taken from the SDK examples):

static void uart_send(uint8_t * p_data, uint16_t data_len)
{
   ret_code_t ret_val;
      for (uint16_t i = 0; i < data_len; i++)
        {
            do{
              ret_val=app_uart_put(p_data[i]);
              if ((ret_val != NRF_SUCCESS) && (ret_val != NRF_ERROR_BUSY)) 
                APP_ERROR_CHECK(ret_val);
            }while (ret_val == NRF_ERROR_BUSY);
         }
}

The above function will error out when there are multiple data coming in. Is there a way to improve the UART speed? For example, how to transfer multiple bytes a time instead of just one byte a time via the UART function. 

Parents Reply
  • Thank you very much Vidar. I have two more questions:

    1. How big can the UART_TX_BUF_SIZE and UART_RX_BUF_SIZE be? Is it safe to give a number of 16384 or bigger?

    2. Since there is no need for me to assign a big number for the UART_RX_BUF_SIZE, can I give different buffer size to UART RX and TX? From APP_UART_FIFO_INIT definition, it looks like it is safe to do so. 

Children
Related