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
  • Thank you for the guidance. I was able to read and write the data using polling mode.

    I tried to replicate the same approach while using both UART0 and UARTE1 and tried to read the data from both UARTS. I'm able to read first character of UART0 only and after that the program gets stuck. Here is the code. Can you please suggest what could be done to overcome this?

            

    // UART0 -> RX_PIN_NUMBER, TX_PIN_NUMBER (DEFAULT)
    //UARTE1 -> ARDUINO_SDA_PIN, ARDUINO_SCL_PIN (DEFAULT)
            
            //In a loop
            
            ret = nrf_serial_read(&serial0_uart, &c, sizeof(c), NULL, 1000);
            if (ret != NRF_SUCCESS)
            {
                continue;
            }
            (void)nrf_serial_write(&serial0_uart, &c, sizeof(c), NULL, 0);
            (void)nrf_serial_flush(&serial0_uart, 0);
            
            ret = nrf_serial_read(&serial1_uart, &c, sizeof(c), NULL, 1000);
            if (ret != NRF_SUCCESS)
            {
                continue;
            }
            (void)nrf_serial_write(&serial0_uart, &c, sizeof(c), NULL, 0);
            (void)nrf_serial_flush(&serial1_uart, 0);
            (void)nrf_serial_flush(&serial0_uart, 0);
            

    On commenting out each uart sections individually, the code works fine. Only when i put both together, it fails! What might be the reason?

           

Reply
  • Thank you for the guidance. I was able to read and write the data using polling mode.

    I tried to replicate the same approach while using both UART0 and UARTE1 and tried to read the data from both UARTS. I'm able to read first character of UART0 only and after that the program gets stuck. Here is the code. Can you please suggest what could be done to overcome this?

            

    // UART0 -> RX_PIN_NUMBER, TX_PIN_NUMBER (DEFAULT)
    //UARTE1 -> ARDUINO_SDA_PIN, ARDUINO_SCL_PIN (DEFAULT)
            
            //In a loop
            
            ret = nrf_serial_read(&serial0_uart, &c, sizeof(c), NULL, 1000);
            if (ret != NRF_SUCCESS)
            {
                continue;
            }
            (void)nrf_serial_write(&serial0_uart, &c, sizeof(c), NULL, 0);
            (void)nrf_serial_flush(&serial0_uart, 0);
            
            ret = nrf_serial_read(&serial1_uart, &c, sizeof(c), NULL, 1000);
            if (ret != NRF_SUCCESS)
            {
                continue;
            }
            (void)nrf_serial_write(&serial0_uart, &c, sizeof(c), NULL, 0);
            (void)nrf_serial_flush(&serial1_uart, 0);
            (void)nrf_serial_flush(&serial0_uart, 0);
            

    On commenting out each uart sections individually, the code works fine. Only when i put both together, it fails! What might be the reason?

           

Children
No Data
Related