Skip to content

Commit

Permalink
Merge pull request #1357 from petermm/uart-doc-fix
Browse files Browse the repository at this point in the history
Update UART programmers guide

Previously failed to mention RX/TX options, and suggested they would default
according to the schema, which they dont.

Fixes #1356

These changes are made under both the "Apache 2.0" and the "GNU Lesser General
Public License 2.1 or later" license terms (dual license).

SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
  • Loading branch information
bettio committed Nov 3, 2024
2 parents 4c45ca7 + 9d0d748 commit 0d5437f
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions doc/src/programmers-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -1716,34 +1716,37 @@ Information about the ESP32 UART interface can be found in the IDF SDK [UART Doc

The AtomVM UART implementation uses the AtomVM Port mechanism and must be initialized using the [`uart:open/2`](./apidocs/erlang/eavmlib/uart.md#open2) function.

The first parameter indicates the ESP32 UART hardware interface. Legal values are:
The first parameter indicates the ESP32 UART hardware interface. Valid values are:

```erlang
"UART0" | "UART1" | "UART2"
```

The selection of the hardware interface dictates the default RX and TX pins on the ESP32:

| Port | RX pin | TX pin |
|-------------|--------|-------|
| `UART0` | GPIO_3 | GPIO_1 |
| `UART1` | GPIO_9 | GPIO_10 |
| `UART2` | GPIO_16 | GPIO_17 |

The second parameter is a properties list, containing the following elements:

| Key | Value Type | Required | Default Value | Description |
|-----|------------|----------|---------------|-------------|
| `rx` | `integer()` | no | -1 (`UART_PIN_NO_CHANGE`) | RX GPIO Pin |
| `tx` | `integer()` | no | -1 (`UART_PIN_NO_CHANGE`) | TX GPIO Pin |
| `speed` | `integer()` | no | 115200 | UART baud rate (bits/sec) |
| `data_bits` | `5 \| 6 \| 7 \| 8` | no | 8 | UART data bits |
| `stop_bits` | `1 \| 2` | no | 1 | UART stop bits |
| `flow_control` | `hardware \| software \| none` | no | `none` | Flow control |
| `parity` | `even \| odd \| none` | no | `none` | UART parity check |


These are the usual RX and TX pins for the various UARTs on the ESP32 (as always check your board specs):

| Port | RX pin | TX pin |
|-------------|--------|-------|
| `UART0` | GPIO_3 | GPIO_1 |
| `UART1` | GPIO_9 | GPIO_10 |
| `UART2` | GPIO_16 | GPIO_17 |

For example,

```erlang
UART = uart:open("UART0", [{speed, 9600}])
UART = uart:open("UART0", [{rx, 3}, {tx, 1}, {speed, 9600}])
```

Once the port is opened, you can use the returned `UART` instance to read and write bytes to the attached device.
Expand Down

0 comments on commit 0d5437f

Please sign in to comment.