app_uart_get question

I'm sending data to the serial port in two ways:

First, if I use a terminal emulator and send a character at a time, app_uart_get returns NRF_SUCCESS for each character. The UART error handler is also called once for each character as it goes on the fifo.

Second, if I send a 14-character string using using the "send file" feature of the terminal emulator, app_uart_get only returns NRF_SUCCESS for some of the characters. Others appear to get dropped. I can still see the UART error handler called 14 times as the characters come in, so I know they all arrived. But app_uart_get only returns NRF_SUCCESS 4 or 5 times.

Why would the UART/fifo drop characters that come in without a pause in between?

Here are some code snippets. I'm using the Segger RTT to implement printf.

#define UART_TX_BUF_SIZE 256                         /**< UART TX buffer size. */
#define UART_RX_BUF_SIZE 256                         /**< UART RX buffer size. */

void uart_error_handle(app_uart_evt_t * p_event)
{
    printf("UART Error handler.\r\n");
}

    
    const app_uart_comm_params_t comm_params = {
          RX_PIN_NUMBER,
          TX_PIN_NUMBER,
          RTS_PIN_NUMBER,
          CTS_PIN_NUMBER,
          UART_HWFC,
          false,
#if defined (UART_PRESENT)
          NRF_UART_BAUDRATE_115200
#else
          NRF_UARTE_BAUDRATE_115200
#endif
      };

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

    APP_ERROR_CHECK(err_code);

    printf("UART test started.\r\n");
    char_cnt = 0;
    uint32_t uart_status;

    while (true) { 
        uart_status = app_uart_get(&(JSON_char_buff[char_cnt]));
        switch( uart_status ) {
            case NRF_SUCCESS:
            printf("NRF_SUCCESS\r\n");
            char_cnt++;
            continue;

            case NRF_ERROR_NOT_FOUND:
            // printf("NRF_ERROR_NOT_FOUND\r\n");
            continue;

            default:
            printf("Unexpected status = 0x%x\r\n", uart_status );
            continue;
        }
    }

Parents Reply
  • I put the following test into the UART error callback to check if the UART is receiving all the bytes and it is:

    static uint32_t cntr = 0;
    
    void uart_error_handle(app_uart_evt_t * p_event)
    {
        // printf("UART Error handler.\r\n");
        cntr++;
        if( cntr > 13 ) {
            printf("cntr = %d\r\n",cntr);
        }
    }

    I send a 14-byte message and the cntr shows 14. In other words, the UART is receiving all the bytes but they are not getting transferred to the FIFO. Any idea why this might be?

Children
Related