225 RS485 UART Bridge
225-rs485-uart-bridge.mc describes a UART-to-RS485 bridge.
MCU_UART provides the controller-side TTL UART. RS485_BRIDGE represents a small transceiver with a UART-side UART.TTL interface and bus-side A, B, and GND pins. The MCU TX signal connects to the bridge RX-side input, while the bridge TX-side output returns to MCU RX. RS485_A and RS485_B leave through J_BUS, and R_TERM provides a simple 120 Ω termination across the differential pair.
Parse 225-rs485-uart-bridge.mc:
bash
eval "$(../mcc/scripts/mcc-slot.sh)"
MCC_SYSTEM_ROOT="$(cd .. && pwd)" "$MCC_BIN" --local parse 22-interface-recipes/225-rs485-uart-bridge.mc --lib mcode --pass1 --pass2Generate HTML for 225-rs485-uart-bridge.mc:
bash
eval "$(../mcc/scripts/mcc-slot.sh)"
MCC_SYSTEM_ROOT="$(cd .. && pwd)" "$MCC_BIN" --local parse 22-interface-recipes/225-rs485-uart-bridge.mc --lib mcode --viz -o 22-interface-recipes/225-rs485-uart-bridge.htmlSource
text
// Example: RS485 UART Bridge
// Goal: Bridge UART signals to an RS485 transceiver.
// Library focus: UART, RS485, RES, DC.
component MCU_UART
{
name = "MCU with UART"
pins = [
io 1:2 = UART0::UART.TTL(DCE)
psnk [3,4] = [VCC, GND]
]
}
component RS485_BRIDGE
{
name = "UART to RS485 Bridge"
pins = [
io 1:2 = UART0::UART.TTL(DTE)
io 3:5 = BUS::UART.RS485.3(MASTER)
psnk [6,7] = [VCC, GND]
io 8 = DE
io 9 = RE_N
]
}
module main
{
io GND
io RS485_A
io RS485_B
io RX_ENABLE_N
io TX_ENABLE
io V5V
DC.SRC PWR(5V, 200mA)
MCU_UART U_MCU
RS485_BRIDGE U_RS485
HDR.1X3 J_BUS
RES R_TERM(120R, 50V)
PWR.1 -> V5V
PWR.2 -> GND
V5V -> U_RS485.VCC
U_RS485.GND -> GND
U_MCU.VCC -> V5V
U_MCU.GND -> GND
U_MCU.UART0.TX -> U_RS485.UART0.RX
U_RS485.UART0.TX -> U_MCU.UART0.RX
U_RS485.DE -> TX_ENABLE
U_RS485.RE_N -> RX_ENABLE_N
U_RS485.BUS.A -> RS485_A
U_RS485.BUS.B -> RS485_B
U_RS485.BUS.GND -> GND
RS485_A -> R_TERM -> RS485_B
RS485_A -> J_BUS.1
RS485_B -> J_BUS.2
GND -> J_BUS.3
}