5 V logic and RS-485
This page shows the wiring for both adapters, the UART frame settings (parity and stop bits) and a pytest that reads a Modbus holding register through a transceiver.
The LA pins' limit
LA1 to LA14 swing between 0 V and the I/O voltage you set, 1.8 V or 3.3 V, and that is also the most they take: never connect a signal above the I/O voltage you set, so never more than 3.3 V. A 5 V signal on an LA pin can damage the pod. See Safety and limits for every port.
5 V TTL serial
Put a two-channel level shifter between the pod and a 5 V UART: its low side on the pod (VCC from J1 pin 17, +3V3, with the I/O voltage set to 3.3 V), its high side on the DUT's 5 V. Use a shifter that is fast enough for your baud rate; most are fine up to 115200 baud.
- DUT TX (5 V) to the high side, low side to the pod's RX pin (LA5 in the examples).
- Pod TX pin (LA4) to the low side, high side to the DUT's RX.
- Pod GND (J1 pin 15) to the DUT's GND.
# The pod's side of the shifter at 3.3 V, the DUT's side at 5 V.
# Set the pod's I/O voltage to match the low side first:
benchpod.set_la_voltage(3.3)
with benchpod.open_uart(rx=5, tx=4, baud=9600) as uart: # through the shifter
uart.write("version\r\n")
print(uart.read_until("\n", timeout=1))A plain resistor divider on the DUT's TX also works for the pod's RX at low baud rates, but the pod's 3.3 V TX may not reach a 5 V input's high level: use the shifter for both directions.
Parity and stop bits
The pod's UART is 8N1 unless you ask for another frame. Some protocols use another one: Modbus RTU, for example, uses 8E1 (8N2 when the device has no parity), always through the adapters above. Every UART surface takes the frame format; it needs pod firmware 3.10.8 or later (gateware v56):
- SDK:
open_uart(..., parity="even", stop_bits=1), also oncapture_uartandpower_cycle_and_capture.parityis"none","even"or"odd";stop_bitsis 1 or 2. - MCP: the
parityandstop_bitsarguments ofuart_open,capture_uartandpower_cycle_and_capture. - Web app and desktop app: the Frame setting next to the baud rate in the console.
- Pod API:
uart_proxy_startwith"parity"and"stop_bits".
The pod checks the parity bit and the first stop bit of every byte it receives. A byte with a wrong parity bit is still delivered, and the pod's status reports uart_rx_parity_error: true until the next session. Older firmware refuses anything but 8N1 with an error that names the firmware to install.
RS-485 and Modbus RTU
RS-485 is a differential bus and the pod cannot drive it: put an external half-duplex RS-485 transceiver between the pod and the bus. Use one made for a 3.3 V supply (a 5 V transceiver needs a level shifter on its three logic lines as well). It takes two LA pins for the data and one for the direction (DE and /RE):
| Pod | Transceiver | Note |
|---|---|---|
| LA5 (pod RX) | RO (receiver out) | The pod listens here |
| LA4 (pod TX) | DI (driver in) | The pod sends here |
| LA9 (GPIO) | DE and /RE, tied together | High: the pod drives the bus. Low: it listens. Add 10k to GND so the transceiver listens while the pod is not driving the pin |
| J1 pin 17, +3V3 | VCC | A transceiver made for 3.3 V supplies |
| J1 pin 15, GND | GND | Also connect it to the bus ground (the "C" or "0 V" terminal) of the device |
| (bus) | A and B | To the device's A and B (some label them D+ and D-, or swap the names: if nothing answers, swap them) |
- Termination: 120 ohms across A and B at each end of the bus. On a short bench cable with one device, one resistor at the far end is enough.
- Bias: the bus needs one pull-up on A and one pull-down on B somewhere (often built into the master or the transceiver board), so it idles at a defined level while nobody drives it.
- Pins: any free LA pins work. Avoid LA1 to LA6 for DE: their pull-ups, when on, would turn the driver on. LA7 and LA8 have a switchable 10k pull-down that can stand in for the external one.
A pytest example: read a holding register
The test sends a Modbus RTU "read holding registers" request (function 3) and checks the reply's CRC. The session uses encoding="latin-1", which keeps every byte as one character, so .encode("latin-1") gives the raw bytes back. It needs the benchpod fixture from the pytest framework.
# test_modbus.py: read a holding register from a Modbus RTU device through an
# RS-485 transceiver on LA4 (DI), LA5 (RO) and LA9 (DE + /RE), 19200 baud, 8E1.
import struct
import time
BAUD = 19200
SLAVE = 1 # the device's Modbus address
REGISTER = 0 # the holding register to read
def crc16(data: bytes) -> bytes:
"""Modbus RTU CRC, low byte first."""
crc = 0xFFFF
for b in data:
crc ^= b
for _ in range(8):
crc = (crc >> 1) ^ 0xA001 if crc & 1 else crc >> 1
return struct.pack("<H", crc)
def read_holding_registers(uart, de, slave, first, count=1, timeout=1.0):
request = struct.pack(">BBHH", slave, 0x03, first, count)
request += crc16(request)
de.high() # drive the bus
uart.write(request)
time.sleep(len(request) * 11 / BAUD + 0.002) # 11 bits a byte at 8E1
de.low() # release it: the device answers
want = 5 + 2 * count # address, function, length, data, CRC
reply = b""
deadline = time.monotonic() + timeout
while len(reply) < want and time.monotonic() < deadline:
reply += uart.read(timeout=0.05).encode("latin-1")
assert len(reply) >= want, f"no answer from slave {slave}: {reply.hex()}"
reply = reply[:want]
assert crc16(reply[:-2]) == reply[-2:], f"bad CRC: {reply.hex()}"
assert reply[1] == 0x03, f"exception {reply[2]} from slave {slave}"
return list(struct.unpack(f">{count}H", reply[3:3 + 2 * count]))
def test_read_holding_register(benchpod):
de = benchpod.gpio(9, "output", level=0) # listen until we send
try:
with benchpod.open_uart(rx=5, tx=4, baud=BAUD, parity="even",
encoding="latin-1") as uart:
values = read_holding_registers(uart, de, SLAVE, REGISTER)
assert 0 <= values[0] <= 0xFFFF
assert not benchpod.status().get("uart_rx_parity_error")
finally:
benchpod.release_gpio(9)