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

Asynchronously receive over UART

I would like to receive data on UART asynchronously and handle the RX event in the backend in an IRQ handler. The application is - a user will be shown a menu and asked to enter a character. It is a kind of CLI. On receiving the character response, a corresponding task will be executed in the handler based on which character was received

Can I get a suggestion on how to do this reception in the backend as part of IRQ handler as all examples are leading to explicitly calling receive function ( like nrfx_uart_rx or app_uart_get ) 

Parents Reply Children
  • Once I call the nrfx_uart_rx function, the Rx will happen continuously over the back-end(like a separate thread running continuously in an infinite loop) when interrupt arrives each time. It is non-blocking as I am providing event_handler(which acts like an ISR) in nrfx_uart_init.

    Am I right?

    I had confusions with the examples as everytime the 'read' or 'get' functions are called in the examples explicitly.

  • If you provide a event_handler to nrfx_uart_init, nrfx_uart_rx will setup the driver for "background" receiving of data. Note that this function only setup a single receive operation, you will have to call it again when you receive the event/interrupt that the operation completed. It will not run in an infinite loop that will receive anything that is transmitted to the device. Did you try out the CLI example? It sounds similar to your application.

  • Thanks for the much needed clarification.

    you will have to call it again when you receive the event/interrupt that the operation completed

    ...means, before I exit from the event handler, I understand I must call nrfx_uart_rx

    I did try the CLI example but my application has a screen which gets updated with live data apart from menu options. I also looked into BLE over UART, UART and Serial examples as well. Am using the examples to only get ideas as my requirement is just tx/rx one character at a time

Related