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

how to check the data available in serial

Hi...

 i want to read the data from another board using serial uart .. how to write the command to check the data is available ... in arduino i written like this how to write in this case

how to achieve the same thing using nRF52840

void loop() { //Choose Serial1 or Serial2 as required
  if(Serial2.available()) 
  {
    Serial1.print(char(Serial2.read()));
  }
     else if (Serial1.available()) 
     {
    Serial2.print(char(Serial1.read()));
  
}
}

Parents
  • Hi 

    If you use the nrf_serial library you can read data in a very similar fashion using the nrf_serial_read function:

    /**
     * @brief Function for reading from a serial port.
     *
     * @param p_serial   Serial port instance.
     * @param p_data     Receive buffer pointer.
     * @param size       Receive buffer size.
     * @param p_read     Amount of data actually read from the serial port.
     *                   NULL pointer can be passed.
     * @param timeout_ms Operation timeout, in milliseconds. Pass 0 to operate in
     *                   non blocking mode.
     *
     * @return Standard error code.
     * */
    ret_code_t nrf_serial_read(nrf_serial_t const * p_serial,
                               void * p_data,
                               size_t size,
                               size_t * p_read,
                               uint32_t timeout_ms);

    The p_read parameter tells you how many bytes were read, and the timeout_ms parameter allows you to tell the function how long to wait for new data (you can set it to 0 to only read the data currently in the buffer). 

    Best regards
    Torbjørn

Reply
  • Hi 

    If you use the nrf_serial library you can read data in a very similar fashion using the nrf_serial_read function:

    /**
     * @brief Function for reading from a serial port.
     *
     * @param p_serial   Serial port instance.
     * @param p_data     Receive buffer pointer.
     * @param size       Receive buffer size.
     * @param p_read     Amount of data actually read from the serial port.
     *                   NULL pointer can be passed.
     * @param timeout_ms Operation timeout, in milliseconds. Pass 0 to operate in
     *                   non blocking mode.
     *
     * @return Standard error code.
     * */
    ret_code_t nrf_serial_read(nrf_serial_t const * p_serial,
                               void * p_data,
                               size_t size,
                               size_t * p_read,
                               uint32_t timeout_ms);

    The p_read parameter tells you how many bytes were read, and the timeout_ms parameter allows you to tell the function how long to wait for new data (you can set it to 0 to only read the data currently in the buffer). 

    Best regards
    Torbjørn

Children
Related