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

nrf_serial_write don't work in blocking mode

Hi!

I'm working on the NRF52832. I'm using the function "nrf_serial_write()" to send data over uart. I want it to work in blocking mode. As I can read in the infocenter, if I put a time into the "timeout_ms" parameter, the function should work in blocking mode. But the function seems to work in nonblocking mode because without the delay of 50 ms, the "nrf_serial_uninit()" function stops the data transmission. There is my code:

              //Uart speed is 9600 bps
              //BUF_LEN = 26
              nrf_serial_write(&serial_uart, &buf, BUF_LEN, NULL, 1000); // Send byte over OW
              nrf_delay_ms(50);
              nrf_serial_uninit(&serial_uart);
*

*I send 26 bytes at 9600 bps. A timeout of 1000 ms should be enough.

I expect the problem is with the timer initialization of the uart timer. There is my code:

    ret_code_t ret;

    ret = nrf_drv_clock_init();
    APP_ERROR_CHECK(ret);
    nrf_drv_clock_lfclk_request(NULL);
    ret = app_timer_init();
    APP_ERROR_CHECK(ret);

What am I missing?

Thank you!

Parents Reply Children
  • Hi Jared!

    The return of the function is NRF_SUCCESS.

    After further digging into the function nrf_serial_write, I can see that the function blocks only until there is less byte to send than the fifo size (SERIAL_FIFO_TX_SIZE).

    But in my case I want the function to stop only when there is no more byte to send. Do you know How I can do it? I tried with a flag triggered on the TX_DONE event. but this event doesn't seem to trigger when all the bytes have been sent, but when a chunk of data have been sent.

    Thank you!

  • Hi,

    Could you try calling nrf_serial_flush() after the call to nrf_serial_write(). That should flush the remaining data after the nrf_serial_write() returns.

    regards

    Jared 

Related