This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

NRF_DRV_UART_EVT_ERROR handling

Hi,

I'm using nRF52840DK with a UART peripheral (on SDK 17.1). I'm wondering what's the right way to handle UART error. Every time the peripheral power cycles, I'll get an NRF_DRV_UART_EVT_ERROR event. However, the nrf_drv_uart_errorsrc_get() always returns 0. I tried using `nrf_uart_errorsrc_get_and_clear` to clear the error but it doesn't work. Could anyone suggest the right way to clear the error?

Thanks,

Ye-Sheng 

 static void uart0_event_handler(nrf_drv_uart_event_t * p_event, void * p_context) {
    (void)p_context;
    uint32_t error_code;
    switch (p_event->type)
    {
        case NRF_DRV_UART_EVT_ERROR:
        error_code = nrf_drv_uart_errorsrc_get(&m_uart0_driver);
        NRF_LOG_INFO("Error code: %u", error_code);
        break;
    ...

Parents
  • You are checking for the error source in the library and not the driver. The errorsrc is cleared in the driver modules\nrfx\drivers\src\nrfx_uarte.c before the library gets this callback to the event handler. Maybe add some logs in the driver level so as to understand what type of error that is and we can think about how to clear it properly based on the type of the error.

  • Hi Susheel,

    I tried to turn on the UART_CONFIG_LOG_ENABLED and NRFX_UART_CONFIG_LOG_ENABLED in sdk_config.h. It prints an NRF_SUCCESS message when it's working properly. But it doesn't print anything when an error occurs. 

    This is the RX line when the UART peripheral resets, I'm guessing it's probably a framing error.

    The main issue I'm having is I couldn't clear the event. If the peripheral resets, all the following bytes will trigger NRF_DRV_UART_EVT_ERROR.

    Thoughts and suggestions?

    Thanks,

    Ye-Sheng

  • Oh, I figured the error_codes, I can get the actual error code by doing this

    error_code = (p_event->data).error.error_mask;

    The returned error code was a framing error and a break error. I was wrong about not clearing the error event. The error events that come later were overrun errors. After restarting RX, the errors go away.

    Thanks for the help!

Reply
  • Oh, I figured the error_codes, I can get the actual error code by doing this

    error_code = (p_event->data).error.error_mask;

    The returned error code was a framing error and a break error. I was wrong about not clearing the error event. The error events that come later were overrun errors. After restarting RX, the errors go away.

    Thanks for the help!

Children
No Data
Related