Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nrf_serial_read() stops receiving data after some time.

Hi,

I am using nrf52840 dk. Also, I am using nrf_serial library with DMA mode for uart communication. I have a continuous loop running in main and there i read data using nrf_serial_read() with timeout set to 0. I have to read continuous polling message and then response. For sometime the data is received perfectly but then it suddenly stops to receive data giving read count passed to nrf_serial_read() zero. Moreover, after I stop receiving data I checked if event is generated at uart_event_handler() in nrf_serial.c, but no rx_done event is encountered in uart_event_handler().

  • Hi

    This issue can be caused by multiple reasons, and it is hard to tell what by this information. Your buffer might be full, which causes it to stop, or there is a timer somewhere in your application that stops the read function after a while. So I have a few questions for you, to help me narrow down the issue. What SDK are you using? Is your code one of our example projects, or based on one? How long do you receive data for? (If it is for 180 seconds, there is probably a timer somewhere going off, as most of the timers in our default code stops there.)

    Best regards,

    Simon

  • Hi,

    Thanks for the response. I am using sdk v15.2.0. Time until data is received is random (it stops within a minute). I have used serial example. Moreover, hwfc is off and I transmit data after each complete packet receive. Also, I checked the data length put into queue in uart_event_handler and data read count in nrf_serial_read and both are found to be same. I have used event handler (passed to serial config) to identify if data is transmitted completely.  I have kept fifo size pretty large( i tried with 32, 256, 5000) and buff size 1 (passed to serial config in NRF_SERIAL_CONFIG_DEF) so i guess there's no probelm of buffer getting full.

    Thanks & Regards,

    Prerit

  • Hi

    This seems strange. What exact changes have you made to the example? And can you describe how I can test this here on my end? It is usually easier to get to the bottom of this kind of issues if I am able to recreate the problem myself. 

    Best regards,
    Simon

  • Hi

    I figured out something here. On receiving NRF_SERIAL_EVENT_DRV_ERR the reception stops. I had read somewhere on devzone that on error event the rx stops so I had uninitialized and initialized serial already but uninit returns busy sometimes so the serial doesn't gets restarted and data rx stops. So, i just commented out the trylock for read and write in nrf_serial_uninit and it works fine. I just need to be sure if it's ok? After this the reception works properly, but the error event is encountered many times. On checking error mask i found it to be frame error. So, is there a way to decrease the frequency of this error? I also checked that both communicating devices have same baudrate and no parity.

    Thanks and Regards,

    Prerit Choksi

  • Hi

    I'm glad to hear you got it working! Framing errors usually occur when:

    • Baud rates are mismatched
    • A serial line is very long
    • When there is a lot of electrical noise on the serial cable

    They can also occur if there is no serial ground connection between the two connected serial devices, or if the connection is intermittent/has a high impedance because of poorly connected ends. You can try to use a sniffer to watch your data during transmission.

    Best regards,

    Simon

Related