UART
UART setup, byte I/O, formatting, and line input.
import "lib/uart.nbl";
Setup
uart_route(1); // main I/O connector
uart_init(3); // baud index 3: 9600
uart_init(baud) writes the low three bits of SerCtrl. uart_route(1)
selects the main I/O connector; uart_route(0) selects the SAO header.
uart_available() returns the unread-byte count saturated at 15.
uart_error() returns nonzero when the sticky error bit is set and clears it.
uart_baud() returns the baud index and also clears the error bit.
uart_puts and puts read flash strings. uart_write sends len bytes from
a RAM char[]; pass &buf. uart_print_str sends a RAM byte string.
uart_print_hexdump prints len bytes as hex.
Functions
Call |
Returns |
Notes |
|---|---|---|
|
|
|
|
|
|
|
|
Send a flash string (literal, const char[], or flashptr). |
|
|
Send len bytes from a RAM char array (pass &buf). |
|
|
|
|
|
|
|
|
Reading SerCtrl clears the sticky error bit. |
|
|
|
|
|
|
|
|
Route the UART to the main I/O connector (enable) or SAO header (disable). |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Signed decimal formatting for raw two’s-complement values. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Read bytes until CR or LF. Returns the number of bytes stored. The buffer is terminated with 0x00 and is not echoed. |