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

[NRF51822QFAC][SDK11] How to recover Uart errors

Hi,

I'm trying to interface SIM808 with nrf51822 over uart using nrf_drv_uart. Everything works well for some time, but then uart starts reporting error code 1, NRF_UART_ERROR_PARITY_MASK, for all transactions on uart. Re-initializing the uart doesn't correct it. Also the time after which error starts appearing is also random, varies from 15 minutes to 1 hour. The problem is not with the module as when the error occurs, I can still communicate with the module using external uart to usb. Here is what I think is relevant information:

  • Baudrate is 115200
  • Tx is blocking
  • Listen to rx for 20ms
  • Max transaction size for rx is 10 bytes

I can upload the code, if necessary.

Hoping for a positive response and thanks in advance :)

  • I am suspecting clock jitter or deviation error. What type of clocks is driving nRF51 and the peer uart? what kind of deviation/jitter could they have?. You said re-initializing the device in software does not work, but did you try to reset one device and see if it recovers?

  • nRF51 clock is 16Mhz Xtal, sim808 has an internal clock, specs are not available for that. If I connect other uart device to sim808 module without resetting, it works fine. If I reset the module, then also it works fine. Clock jitter looks prime suspect, but I doubt that can be diagnosed without altering the clock of both modules. Also if I change the baud rate to 460800, error frequency increases, but at bps of 230400, error frequency decreases a lot, minimum error time reduces to 2 hours at 230400. Can anything be done without changing the hardware?

  • Does the peer UART keep on transmitting irrespective of errors happening on nrf side? If not maybe we can handle the PARITY error clearing all events, disabling and enable nRF side uart. Then it will listen to the TX/RX line normally. But if peer is transmitting all time without knowing what is happening on the nRF side, then disabling/enabling will not work because nrf chip will be re-enabled and peer could be in middle of transmitting a byte and that will generate more errors.

    If you need me to help you with code snippets to disable and enable uart then tell mewhich version of SDK drivers you are using.

  • The peer UART is command based, so if a command is completed, it will not broadcast, meaning peer UART is not broadcasting all the times. I have tried disabling and enabling using nrf_drv_uart_uninit and nrf_drv_uart_init functions, but it doesn't solve the issue, I haven't tried clearing the events though. One thing to mention is that I'm disabling/enabling the uart when all the events are complete, RX complete is ensured by using nrf_drv_uart_rx_abort. I am using SDK11, please share code snippet so that I can double check everything.

  • When you get a parity error you will not get the RX complete event for that particular byte. You should do this in your uart event handler.

    static void uart_event_handler(nrf_drv_uart_event_t * p_event, void* p_context)
    {
       ...
       ...
    
        else if (p_event->type == NRF_DRV_UART_EVT_ERROR)
        {
            nrf_uart_event_clear(NRF_UART0, NRF_UART_EVENT_TXDRDY);
            nrf_uart_event_clear(NRF_UART0, NRF_UART_EVENT_RXTO);
            nrf_uart_event_clear(NRF_UART0, NRF_UART_EVENT_ERROR);  /* thanks for correction Lalit*/
            nrf_drv_uart_uninit
            nrf_drv_uart_init
     
        }
    
       ...
       ...
    }
    
Related