c programing logic for reading sensor over UART
i'm trying read data sensor connected mcu on uart. when powered sensor outputs continuously ascii capital "r", followed 4 ascii character digits representing distance in millimeters, followed carriage return (ascii 13). e.g. r9999cr
for uart there 2 read functions blocking 1 , non-blocking:
blocking
code: [select]
/**
* uart character data read.
*
* perform single character read uart interface.
* blocking synchronous call.
*
* @param[in] uart uart index.
* @param[out] data data read uart. must not null.
* @param[out] status uart specific status.
*
* @return standard errno return type qmsi.
* @retval 0 on success.
* @retval negative @ref errno possible error codes.
*/
int uart_read(const uart_t uart, uint8_t *const data,
uart_status_t *const status);non_blocking
code: [select]
/**
* uart character data read.
*
* perform single character read uart interface.
* non-blocking synchronous call.
*
* @param[in] uart uart index.
* @param[out] data character read. must not null.
*
* @return standard errno return type qmsi.
* @retval 0 on success.
* @retval negative @ref errno possible error codes.
*/
int uart_read_non_block(const uart_t uart, uint8_t *const data);i wondering if me figure out logic reading e.g. 9999 variable called reading.
should use blocking or non blocking function , how isolate characters if data streaming in?
code: [select]
if (serial.available()>4){
if (serial.read() == 'r'){
char0 = serial.read();
char1 = serial.read();
char2 = serial.read();
char3 = serial.read();
}
}
put 4 variables want.
Arduino Forum > Using Arduino > Microcontrollers > c programing logic for reading sensor over UART
arduino
Comments
Post a Comment