UART Configuration

These examples will show you how to configure the UART bus for non-sleep modes.

The E32Device class will automatically re-instantiate a UART class with the correct parameters when changing the module’s mode.

Baudrate

examples/uart/baudrate.py
 1# SPDX-FileCopyrightText: 2023 Herwin Bozet
 2#
 3# SPDX-License-Identifier: Unlicense
 4
 5import board
 6
 7import ebyte_e32
 8
 9PIN_M0 = board.IO13
10PIN_M1 = board.IO12
11PIN_RXD = board.IO11  # Pin marked as RX on the module
12PIN_TXD = board.IO10  # Pin marked as TX on the module
13PIN_AUX = board.IO9
14
15e32 = ebyte_e32.E32Device(PIN_M0, PIN_M1, PIN_AUX, PIN_TXD, PIN_RXD, address=0x1377, channel=4)
16
17# Setting the non-sleep UART bus speed
18e32.uart_rate = ebyte_e32.SerialBaudRate.BAUD_19200
19print(f"Sleep mode BPS: {e32.uart_rate}")
20
21# Switching to mode 0.  (Normal mode)
22e32.mode = ebyte_e32.Modes.MODE_NORMAL
23print(f"Normal mode BPS: {e32.uart_rate}")
24
25# We are now communicating with the module at 19200 bps.
26# If we go back to sleep mode, we'll be automatically put back at 9600.
27# Sending messages here will work on a module that uses the same air data rate and ANY UART baudrate.
28
29# Switching back to sleep mode.
30e32.mode = ebyte_e32.Modes.MODE_SLEEP
31print(f"Sleep mode BPS: {e32.uart_rate}")
32

Parity

examples/uart/parity.py
 1# SPDX-FileCopyrightText: 2023 Herwin Bozet
 2#
 3# SPDX-License-Identifier: Unlicense
 4
 5import board
 6
 7import ebyte_e32
 8
 9PIN_M0 = board.IO13
10PIN_M1 = board.IO12
11PIN_RXD = board.IO11  # Pin marked as RX on the module
12PIN_TXD = board.IO10  # Pin marked as TX on the module
13PIN_AUX = board.IO9
14
15e32 = ebyte_e32.E32Device(PIN_M0, PIN_M1, PIN_AUX, PIN_TXD, PIN_RXD, address=0x1377, channel=4)
16
17# Setting the non-sleep UART bus parity
18print(f"Sleep mode UART parity: {e32.uart_parity}")
19e32.uart_parity = ebyte_e32.SerialParity.PARITY_ODD
20
21# Switching to mode 0.  (Normal mode)
22e32.mode = ebyte_e32.Modes.MODE_NORMAL
23print(f"Normal mode UART parity: {e32.uart_parity}")
24
25# We are now communicating with the module at 9600 bps with odd parity.
26# If we go back to sleep mode, we'll be automatically put back at PARITY_NONE.
27# Sending messages here will work on a module that uses the same air data rate and ANY UART parity.