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

Polling Mode in Serial library

Hello,

Can anyone point me to a good example for Polling mode using serial library?

I'm looking for an application in which I can poll the serial port for data. I went through API documentation and found that Serial library has a polling mode. Can anyone guide me in using that?

Parents
  • Hi,

    I'm not aware of any examples of using polling mode, but this should be quite straight forward. You can start with the serial example, and modify it to your needs. You need to change the configuration as described in the documentation:

    NULL, NULL, NULL, NULL);
    Polling mode does not use QUEUES, BUFFERS, EVENT_HANDLER, or SLEEP_HANDLER, so you can remove all defines of these. You then need to call nrf_serial_write() and nrf_serial_read() to write and read the UART. The UART driver will operate in blocking mode, waiting for the operation to complete.
     
    Best regards.
    Jørgen
  • How does it fail? Are you getting an error code from any of the function calls?

  • When I entered debug mode with Seggar Embedded studio, I saw that the control is stuck at line no.6 (ret = nrf_serial_read(&serial0_uart, &c, sizeof(c), NULL, 1000)). If you can suggest some debugging approach that would help me debug this problem better, I can try that too.

  • Is it stuck on the line on the first iteration of the loop, or on second/later run? Did you check the suggestion from Jakub in the other thread where you posted your issue? Why are you not checking the error codes from nrf_serial_flush function calls?

  • It does print the received data in the first iteration. It gets stuck only in the second iteration of the loop.

    Btw, I'm going with polling mode because the functionality I'm trying to achieve is very trivial and doesn't need any complex queues and interrupt handlers. I just have to read data from both UARTs at will and store them. An example or code snippet describing the nuances of this polling mode would be very helpful. 

  • When using the POLLING mode, the function calls nrf_serial_read and nrf_serial_write will not return until the operation is complete (the number of specified bytes have been transmitted or received), the timeouts will not be functional. If you do not write anything to the UART line, it will be stuck on the read if until the requested number of bytes are received. nrf_serial_flush will not have any effect in polling mode:

Reply
  • When using the POLLING mode, the function calls nrf_serial_read and nrf_serial_write will not return until the operation is complete (the number of specified bytes have been transmitted or received), the timeouts will not be functional. If you do not write anything to the UART line, it will be stuck on the read if until the requested number of bytes are received. nrf_serial_flush will not have any effect in polling mode:

Children
No Data