summaryrefslogtreecommitdiff
path: root/digital/avr/modules/uart/uart.txt
blob: 301167326ec56c26c04dbaf3f3e77acb11a2286d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
=================
 UART AVR module
=================
:Author: Nicolas Schodet

Introduction
============

This module provides easy access to embedded AVR UART(s).  If the device offers
two UARTs, they can be configured independently and two sets of functions are
provided.  The first one starts with ``uart0`` and the second one with
``uart1``.

Two modes of operation are available, polling mode, with no interruption
usage, and ring mode, in which characters are stored and retrieved from a ring
buffer using interruptions.

Usage
=====

It can not be easier.  Call the ``uartN_init`` at startup, then ``uartN_putc``
to send a character and ``uartN_getc`` to receive a character. The
``uartN_poll`` gives the number of available characters (which is at most 1 if
not using interrupts).

In case of transmission errors, ``uartN_getc`` will return 0xff.  This is
returned for example for framing error or parity error.  This is easy to use
with text transmission as this is not an ASCII character, but this is not
suitable for binary as a legitimate 0xff will be seen as a transmission error.

As all modules, set the configuration in the ``avrconfig.h`` file.

In host compilation, you can configure two different modes.  In the PTS mode,
the program will open a pseudo-terminal which can be used like a regular
serial port.  A link will be created in the program directory (``uartN.pts``)
to ease locating the pseudo-terminal.

In the STDIO mode, the standard input/output are used as the serial port.
Only one port can be configured to be used in the STDIO mode.  In this mode,
there is an automatic conversion between carriage returns and line feeds (this
is also not good if you plan to use it for binary transfers.

API
===

.. include:: uart.exd