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 Reply Children
  • 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.

  • Hello.

    I would like to know why FIFO is not working.

    The reason why I could not do FIFO was because I was using app_uart.c instead of app_uart_fifo.c.
    I changed to app_uart_fifo.c and now I can use APP_UART_DATA_READY.

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

    Also, in my environment, UART communication is performed in 100ms cycles, and when I added nrf_delay_ms(1000) before app_uart_get, the RTS went High and I was able to confirm that flow control was working.

    I have a question, even when I was using app_uart.c, RTS went High by putting delay.
    Is it correct to think that this is not because there is no room in the receive buffer, but because the delay made it temporarily impossible to receive the message, and RTS went High?

    Sorry for repeating. Best regards, and thank you for your understanding.

Related