Skip to content

UARTx_read

gicking edited this page Feb 10, 2018 · 1 revision

back to Command Reference / Serial

Description

blocking read of byte received via UARTx (x=1..4). Prior to receiving via UART, communication must be configured via UARTx_begin().

Notes:

  • formatted input e.g. via gets() is supported by using getcharAttach() with argument UARTx_read
  • UARTx_read() halts code execution until a byte has been received. To avoid stalling, first check receive buffer via UARTx_available(), or receive via interrupt UART1_RXF_ISR or UART234_RXF_ISR, respectively

Inclusion

  • defined in uartx.h (x=1..4)
  • not loaded by main_general.h
  • for UART1 receive interrupt set #define USE_UART1_RXF_ISR in config.h. The corresponding interrupt function name is UART1_RXF_ISR
  • for UART2,3,4 receive interrupt set #define USE_UART234_RXF_ISR in config.h. The corresponding interrupt function name is UART234_RXF_ISR

Syntax

c = UART1_read()

Parameters

  • input:

    • none
  • output:

    • none

Returns

  • read byte (char)

Example Code

The below function echoes bytes received via UART1

#include "main_general.h"
#include "uart1.h"

void setup() {
  UART1_begin(115200);
}

void loop() {
  if (UART1_available())
    UART1_write(UART1_read());
}

Relevant Tutorial

See also

Clone this wiki locally