I'm trying to read data from a sensor connected to an mcu over UART. When powered the sensor outputs continuously an ASCII capital “R”, followed by four ASCII character digits representing distance in millimeters, followed by a carriage return (ASCII 13). E.g. R9999CR
For the uart there are two read functions a blocking one and non-blocking:
Blocking
/**
* UART character data read.
*
* Perform a single character read from the UART interface.
* This is a blocking synchronous call.
*
* @param[in] uart UART index.
* @param[out] data Data to read from UART. This must not be NULL.
* @param[out] status UART specific status.
*
* @return Standard errno return type for QMSI.
* @retval 0 on success.
* @retval Negative @ref errno for possible error codes.
*/
int uart_read(const uart_t uart, uint8_t *const data,
uart_status_t *const status);
Non_blocking
/**
* UART character data read.
*
* Perform a single character read from the UART interface.
* This is a non-blocking synchronous call.
*
* @param[in] uart UART index.
* @param[out] data Character read. This must not be NULL.
*
* @return Standard errno return type for QMSI.
* @retval 0 on success.
* @retval Negative @ref errno for possible error codes.
*/
int uart_read_non_block(const uart_t uart, uint8_t *const data);
I was wondering if somebody could help me figure out a logic to get a reading e.g. 9999 as a variable called reading.
Should I use the blocking or non blocking function and how would I isolate the characters if the data is streaming in?