Skip to content

Commit

Permalink
Update UART programmers guide.
Browse files Browse the repository at this point in the history
Previously failed to mention RX/TX options, and suggested they would default according to the schema, which they dont.

Fixes atomvm#1356

Signed-off-by: Peter M <petermm@gmail.com>
  • Loading branch information
petermm committed Oct 25, 2024
1 parent 24084c5 commit 6a2dde9
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 @@ -1795,34 +1795,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 |


The default 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 6a2dde9

Please sign in to comment.