libuarte+freertos receive wrong data

Hi there,

I used libuarte under FreeRTOS together with the SDK 17.1.0. When I test the application, I found that the data I received except some problem.

The baudrate is 921600, and I send the test data (abcdefg...), when i send about 10 pieces of data, the data I received was split into two parts.

i don't know what's going on.

uart.c is here.

NRF_LIBUARTE_ASYNC_DEFINE(libuarte, 0, 0, 0, NRF_LIBUARTE_PERIPHERAL_NOT_USED, 255, 3);

void uart_event_handler(void * context, nrf_libuarte_async_evt_t * p_evt)
{
    nrf_libuarte_async_t * p_libuarte = (nrf_libuarte_async_t *)context;
    ret_code_t ret;

    switch (p_evt->type)
    {
        case NRF_LIBUARTE_ASYNC_EVT_ERROR:
            UART_PRINTF("NRF_LIBUARTE_ASYNC_EVT_ERROR = %d.", p_evt->data.errorsrc);
            break;
        case NRF_LIBUARTE_ASYNC_EVT_RX_DATA:
            m_loopback_phase = true;
            memcpy(data_array, p_evt->data.rxtx.p_data, p_evt->data.rxtx.length);
            UART_PRINTF("data_array = %s", data_array);
            nrf_libuarte_async_rx_free(p_libuarte, p_evt->data.rxtx.p_data, p_evt->data.rxtx.length);
            break;
        case NRF_LIBUARTE_ASYNC_EVT_TX_DONE:
            if (m_loopback_phase)
            {
                nrf_libuarte_async_rx_free(p_libuarte, p_evt->data.rxtx.p_data, p_evt->data.rxtx.length);
                if (!nrf_queue_is_empty(&m_buf_queue))
                {
                    buffer_t buf;
                    ret = nrf_queue_pop(&m_buf_queue, &buf);
                    APP_ERROR_CHECK(ret);
                    UNUSED_RETURN_VALUE(nrf_libuarte_async_tx(p_libuarte, buf.p_data, buf.length));
                }
            }
            break;
        default:
            UART_PRINTF("Unexpected LibUarte Event = %d.", p_evt->type);
            break;
    }
}


int main()
{
    uint8_t err_code;
    nrf_libuarte_async_config_t nrf_libuarte_async_config = {
            .tx_pin     = TX_PIN_NUMBER,
            .rx_pin     = RX_PIN_NUMBER,
            .baudrate   = NRF_UARTE_BAUDRATE_921600,
            .parity     = NRF_UARTE_PARITY_EXCLUDED,
            .hwfc       = NRF_UARTE_HWFC_DISABLED,
            .timeout_us = 100,
            .int_prio   = APP_IRQ_PRIORITY_HIGH,
            .pullup_rx  = 1
    };

    err_code = nrf_libuarte_async_init(&libuarte, &nrf_libuarte_async_config, uart_event_handler, (void *)&libuarte);
    if(err_code != NRF_SUCCESS)
    {
        UART_PRINTF("nrf_libuarte_async_init err_code = %d.", err_code);
    }
    APP_ERROR_CHECK(err_code);

    nrf_libuarte_async_enable(&libuarte);

}

BR,

Lurn

Parents Reply Children
No Data
Related