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

Feedback on nrf_serial API - process for detecting transmission complete

Hi, I've got an application where I need to send a message and then receive a response on a half duplex serial link.

I feel like this is a pretty common use case but the way I found of detecting transmission complete is kind of awkward. The serial library generates a NRF_SERIAL_EVENT_TX_DONE event for every single character, so I have to dig deep into the SDK internals to detect when all bytes have been transmitted.

It seems like there ought to be a better way, like a field in nrf_serial_event_t to indicate how many bytes remain in the transmit queue

modbus_uart_event_handler(struct nrf_serial_s const *p_serial, ... nrf_serial_event_t event) {
    ...
    case NRF_SERIAL_EVENT_TX_DONE:
        nrf_queue_t const * p_txq = p_serial->p_ctx->p_config->p_queues->p_txq;
        if (nrf_queue_is_empty(p_txq)) {
            /* switch the transceiver to receive and start the nrf_serial_read() */

Any ideas for a better way to do this, or can the nrf_serial API be extended in the future?

 

Parents
  • Couldn't you simply add some logging after the call to nrf_serial_write()? Then you will know when the transmission is completed. If you provide a size_t pointer in the fourth position of the function, you can check its content after function return to see how many bytes are transmitted. If all the bytes aren't transmitted (if size - bytes-written > 0) you may have to increase the timeout.

    Best regards,

    Simon

  • The key is that it's a half duplex serial link, I need to switch the direction as soon as the transmission is complete

  • I am not too familiar with the nrf_serial library and was not able to find a solution, does your current solution work ok, or should I move on with it?

    Best regards,

    Simon

  • My current solution works. I have two goals in posting:

    1. Help other users who are using nrf_serial

    2. Provide feedback that nrf_serial is missing a basic feature and suggest that this could be included in the documentation

Reply
  • My current solution works. I have two goals in posting:

    1. Help other users who are using nrf_serial

    2. Provide feedback that nrf_serial is missing a basic feature and suggest that this could be included in the documentation

Children
No Data