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

loop in nrf_drv_uart_rx_for_uarte() after run uart_close()

Hi, now I'm using NRF52832 's UART with SD12 and it required to receive 40 bytes per 10ms.

In fact, it does not take 10ms to complete the reception.So my idea is to create a 10ms timer task to execute uart_init and when I received the last byte, run uart_close() to close the UART in order to save power. Here is the function:

void uart_init(void)
{
    uint32_t err_code;
    const app_uart_comm_params_t comm_params =
    {
            UART_RX_PIN,
            UART_TX_PIN,
            UART_RTS_PIN,
            UART_CTS_PIN,
            APP_UART_FLOW_CONTROL_DISABLED,
            false,
            UART_BAUDRATE_BAUDRATE_Baud115200
    };

    APP_UART_FIFO_INIT( &comm_params,
                       UART_RX_BUF_SIZE,
                       UART_TX_BUF_SIZE,
                       uart_event_handle,
                       APP_IRQ_PRIORITY_LOW,
                       err_code);
    APP_ERROR_CHECK(err_code);

}

uint32_t app_uart_close(void)
{
    nrf_drv_uart_uninit(&app_uart_inst);
    return NRF_SUCCESS;
}

But when I received the last byte and run app_uart_close(), the program was stoped and looped in nrf_drv_uart_rx_for_uarte()

do {
    endrx  = nrf_uarte_event_check(p_instance->reg.p_uarte, NRF_UARTE_EVENT_ENDRX);
    rxto   = nrf_uarte_event_check(p_instance->reg.p_uarte, NRF_UARTE_EVENT_RXTO);
    error  = nrf_uarte_event_check(p_instance->reg.p_uarte, NRF_UARTE_EVENT_ERROR);
}while ((!endrx) && (!rxto) && (!error));

Did i make a mistake during this period? I was very confused...

Any help would be appreciated.

Parents
  • Hi,

    Is the UART instance successfully uninitialized? I.e. if you turn on RTT logging, do you get the "Instance uninitialized: #instance" printed ?

    Also what priority are using for UART? Maybe you are calling app_uart_close() from a interrupt, when you are in nrf_drv_uart_rx() function?

    Also check the values of endrx,rxto and error. You could also try to call nrf_drv_uart_rx_abort() before you call app_uart_close().

Reply
  • Hi,

    Is the UART instance successfully uninitialized? I.e. if you turn on RTT logging, do you get the "Instance uninitialized: #instance" printed ?

    Also what priority are using for UART? Maybe you are calling app_uart_close() from a interrupt, when you are in nrf_drv_uart_rx() function?

    Also check the values of endrx,rxto and error. You could also try to call nrf_drv_uart_rx_abort() before you call app_uart_close().

Children
No Data
Related