Please tell me about UART flow control.

nrf52832 (s132 v7.0.1, SDK v17.0.0) is under development as peripheral device.

I have a question regarding flow control of UART communication.

I am currently doing UART communications with flow control enabled, but the RTS is not working.

From what I read on the site, I think that the RTS is not working because there is a space in the receive buffer, but is this idea valid?

Also, I would like to confirm that RTS works with the current code, but I would like to know how to confirm this without changing the size of the data to be sent by the communication partner.

Thank you in advance.

Parents
  • Hello,

    From what I read on the site, I think that the RTS is not working because there is a space in the receive buffer, but is this idea valid?

    This is very likely the case yes. Especially if you are using libuarte driver that have been optimized to ensure it can receive data continously:
    https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/lib_libuarte.html 

    Also, I would like to confirm that RTS works with the current code, but I would like to know how to confirm this without changing the size of the data to be sent by the communication partner.

    Maybe you can get it to go inactive if you choose not to call nrf_libuarte_async_rx_free():
    https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/lib_libuarte.html#lib_libuarte_async_rx 

    Best regards,
    Kenneth

  • Hello.

    I was using UART, not UARTE, so I assume you are not using the libuarte driver.

    The current UART configuration is the following code.

    #define UART_RX_BUF_SIZE (32)
    #define UART_TX_BUF_SIZE (32)
    
    static 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_ENABLED,
        .use_parity   = false,
        .baud_rate    = UART_BAUDRATE_BAUDRATE_Baud115200,
      };
      
    APP_UART_FIFO_INIT(&comm_params, UART_RX_BUF_SIZE, UART_TX_BUF_SIZE, uart_evt_handler, APP_IRQ_PRIORITY_LOWEST, err_code);              
    APP_ERROR_CHECK(err_code);

    I am initializing the UART using APP_UART_FIFO_INIT, but "buffer" is not used in app_uart_init and I believe the size is not set.
    Will the size be the size set in APP_UART_FIFO_INIT?

    Also, I am using app_uart_get in the event handler to get data from the buffer.
    I thought that stopping this acquisition would make the RTS work, but as a result it does not work.
    Is it correct to use this method to make the RTS work?

    Thank you in advance.

  • If you are using the default uart example from nrf5 sdk:
    \examples\peripheral\uart\pca10040\

    Then in main.c change to:
    #define UART_TX_BUF_SIZE 4 /**< UART TX buffer size. */
    #define UART_RX_BUF_SIZE 4 /**< UART RX buffer size. */
    #define UART_HWFC APP_UART_FLOW_CONTROL_ENABLED

    And in your main() add a very long delay of 1second, e.g.:

    while (true)
    {
    uint8_t cr;
    nrf_delay_ms(1000);
    while (app_uart_get(&cr) != NRF_SUCCESS);
    while (app_uart_put(cr) != NRF_SUCCESS);

    if (cr == 'q' || cr == 'Q')
    {
    printf(" \r\nExit!\r\n");

    while (true)
    {
    // Do nothing.
    }
    }
    }

    Then if you for instance type characters in a terminal window faster than <1 second I can see that characters are not lost, so I can only assume that the RTS seems to ensure HFWC works.

    Best regards,
    Kenneth

  • Hello.

    Am I understanding correctly that if a character is entered earlier than 1 second, flow control will stop receiving from the terminal, and after 1 second has elapsed, the character will be received from the terminal?

    In this case, could you please check if the RTS is High/Low while receiving from the terminal is stopped and while receiving?

    Thank you in advance.

  • Hello, I'm looking for a UART event handler.

    I would like to explain the UART event handler as well.

    I was trying to find out if the free space in fifo is related to the condition that RTS goes High when 4 bytes of free space runs out.

    In that case, I initialized the UART with APP_UART_FIFO_INIT and set APP_FIFO_ENABLE to 1, but found that APP_UART_DATA_READY was not generated by the event handler.
    In the current implementation, APP_UART_DATA was used for receive processing.

    I would like to know why FIFO is not working.
    Also, does fifo have anything to do with why RTS cannot be set High?

    Thanks in advance.

    PS: I forgot to translate it into English. My apologies.

Reply
  • Hello, I'm looking for a UART event handler.

    I would like to explain the UART event handler as well.

    I was trying to find out if the free space in fifo is related to the condition that RTS goes High when 4 bytes of free space runs out.

    In that case, I initialized the UART with APP_UART_FIFO_INIT and set APP_FIFO_ENABLE to 1, but found that APP_UART_DATA_READY was not generated by the event handler.
    In the current implementation, APP_UART_DATA was used for receive processing.

    I would like to know why FIFO is not working.
    Also, does fifo have anything to do with why RTS cannot be set High?

    Thanks in advance.

    PS: I forgot to translate it into English. My apologies.

Children
Related