ARTICLE

RS485 คืออะไร? ต่างจาก UART อย่างไร และทำไมใช้กับ Sensor/Meter ระยะไกล.

อธิบาย RS485 สำหรับ ESP32, Sensor, Meter และ Automation ตั้งแต่ differential signaling, bus topology, termination, biasing, UART transceiver, A/B naming และความสัมพันธ์กับ Modbus RTU

IoTAutomationElectricalโดย Thospaakเผยแพร่ 10 ต.ค. 2569อัปเดต 10 ต.ค. 2569

RS485 เป็นมาตรฐาน electrical/physical layer สำหรับการสื่อสาร serial แบบ differential ที่นิยมในงานอาคาร โรงงาน Energy Meter, Inverter, PLC, Sensor และระบบ Automation เพราะเหมาะกับสายที่ยาวและ environment ที่มี noise มากกว่า logic-level UART บนบอร์ด

สิ่งสำคัญคือ:

UART ≠ RS485 ≠ Modbus

ทั้งสามคำเกี่ยวกันได้ แต่เป็นคนละ layer

UART คืออะไรในภาพนี้

UART เป็น peripheral/serial interface ของ MCU

ตัวอย่าง ESP32:

ESP32 UART TX/RX

ระดับสัญญาณฝั่ง MCU เป็น logic-level ตาม hardware ของบอร์ด ไม่ได้ถูกออกแบบให้ลากออกไปเป็น field bus ระยะไกลโดยตรง

อ่านพื้นฐาน UART ได้ที่ UART, I²C และ SPI ต่างกันอย่างไร

RS485 เพิ่มอะไรให้ UART

การใช้งานทั่วไปจะมี transceiver ระหว่าง MCU กับสาย bus:

ESP32 UART
   ↓ TX/RX
RS485 Transceiver
   ↓ differential pair
A / B bus
   ↓
Field device

Transceiver แปลง logic-level serial ไปเป็น differential signaling ที่เหมาะกับ bus มากขึ้น

ดังนั้นคำว่า “ESP32 มี RS485” มักหมายถึงระบบมี UART + RS485 transceiver/interface ไม่ใช่ว่า GPIO TX/RX เองกลายเป็น RS485

Differential Signaling ช่วยเรื่อง Noise อย่างไร

RS485 ใช้ความต่างศักย์ระหว่างคู่สายแทนการตีความ signal จาก conductor เดียวเทียบ ground อย่างง่าย

แนวคิดคือ receiver สนใจ:

VA - VB

มากกว่าดูแรงดันเส้นเดียว

ทำให้ common-mode noise บางส่วนถูกปฏิเสธได้ดีขึ้นเมื่อ wiring/topology ถูกต้อง

แต่ RS485 ไม่ได้ immune ต่อทุกปัญหา เช่น:

  • ground potential difference มากเกินไป
  • surge/lightning transient
  • shielding/earthing ไม่เหมาะ
  • topology แย่
  • cable quality ไม่เหมาะ
  • termination ผิด

RS485 มักเป็น Bus ไม่ใช่ Star แบบ Ethernet Switch

Topology ที่พบบ่อยคือ trunk/bus:

Controller ─ Device 1 ─ Device 2 ─ Device 3

ไม่ใช่:

            ┌─ Device 1
Controller ─┼─ Device 2
            └─ Device 3

แบบ star ที่มี stub ยาวหลายทางอาจสร้าง reflection/signal integrity problem โดยเฉพาะเมื่อ baud rate/ระยะสูงขึ้น

ความยาวสาย, baud rate และจำนวน node ที่เหมาะสมต้องดู transceiver/cable/topology จริง ไม่ควรจำเลขเดียวใช้ทุกระบบ

Termination Resistor มีไว้ทำอะไร

Termination ช่วย match impedance ที่ปลายสายเพื่อลด reflection ใน bus ที่เหมาะสม

แนวคิดทั่วไป:

[Termination] ───────── RS485 trunk ───────── [Termination]

ไม่ได้แปลว่าต้องใส่ termination ที่ทุก device

การใส่ resistor มากเกินไปทำให้ load ของ bus เปลี่ยนและอาจทำให้ signal level แย่ลง

จึงต้องอิง topology, cable impedance, baud rate และคู่มืออุปกรณ์

Biasing / Fail-safe State คืออะไร

เมื่อไม่มี driver ใดส่งข้อมูล สาย bus อาจอยู่ในสภาวะ idle ที่ต้องมี state ชัด

บางระบบใช้ biasing/fail-safe network เพื่อช่วยกำหนด idle state แต่ transceiver สมัยใหม่บางรุ่นมี internal fail-safe behavior อยู่แล้ว

ห้ามใส่ bias resistor ซ้ำหลายจุดโดยไม่ดู architecture เพราะอาจเพิ่มโหลดหรือทำให้ voltage bias ผิด

A/B Naming เป็นจุดที่พลาดบ่อย

ผู้ผลิตแต่ละรายอาจใช้ชื่อ:

  • A/B
  • D+/D-
  • 485+/485-

และ convention ของคำว่า A/B อาจทำให้สับสนระหว่าง vendor

จึงไม่ควรต่อจาก “A ต้องต่อ A” โดยไม่ดู manual ของอุปกรณ์ทั้งสองฝั่ง

ถ้าสื่อสารไม่ได้ให้ตรวจ:

  1. pin naming/manual
  2. polarity
  3. common reference/ground requirement
  4. baud/parity/stop bit
  5. protocol/device address

RS485 Half-duplex ทำงานอย่างไร

ระบบ 2-wire RS485 จำนวนมากเป็น half-duplex คือหลาย node ใช้คู่สายเดียวกันทั้งส่งและรับ แต่ต้องไม่ขับ bus พร้อมกันโดยไม่มี protocol/arbitration

MCU อาจต้องควบคุม driver-enable ของ transceiver:

Receive mode
   ↓
Enable transmitter
   ↓
Send frame
   ↓
Wait transmission complete
   ↓
Disable transmitter
   ↓
Receive response

Timing ผิดอาจทำให้ response ถูกตัดหรือ bus collision

RS485 ไม่ได้กำหนด Baud Rate หรือ Message Format ของ Modbus ให้เอง

RS485 บอกเรื่อง electrical signaling แต่ไม่ได้กำหนดว่า payload ต้องเป็นอะไร

ตัวอย่าง protocol ที่อาจวิ่งบน serial physical layer มีหลายแบบ

กรณีที่พบบ่อยคือ:

RS485
  ↓
Modbus RTU

แต่มี RS485 ไม่ได้แปลว่าคือ Modbus

อ่านต่อที่ Modbus คืออะไร

Modbus RTU บน RS485 ต้องตั้งอะไรให้ตรงกัน

อย่างน้อย:

  • baud rate
  • parity
  • stop bits
  • device/server address
  • protocol framing
  • register map

ถ้า electrical layer ถูกแต่ communication setting ไม่ตรง ก็อ่านไม่ได้

ในทางกลับกัน ถ้า setting ถูกแต่ polarity/topology/termination ผิด ก็อ่านไม่ได้เช่นกัน

Ground ต้องต่อไหม

Differential signaling ไม่ได้หมายความว่าไม่มี common-mode limit

ระบบ field อาจต้องมี reference conductor, shielding, isolation หรือ surge protection ตาม design และ environment

คำตอบว่า “ต่อ GND ทุกครั้ง” หรือ “ห้ามต่อ GND เด็ดขาด” เป็นคำตอบที่กว้างเกินไป

ควรอิง:

  • transceiver common-mode range
  • isolation architecture
  • cable/shield design
  • ground potential difference
  • manufacturer wiring guide

Isolated RS485 มีประโยชน์เมื่อไร

Isolation ช่วยแยก galvanic path ระหว่าง controller กับ field bus ในบาง application เช่น:

  • อาคารหลายตู้
  • ground potential ต่างกัน
  • industrial environment
  • meter/inverter network
  • outdoor/long cable

แต่ isolation ไม่แทน surge protection หรือ wiring practice ที่เหมาะสม

RS485 เหมาะกับ Smart Farm อย่างไร

ตัวอย่าง:

Soil / Weather / Flow Sensor
       ↓ RS485
Field Bus
       ↓
Gateway / ESP32 / PLC
       ↓
MQTT / Home Assistant / Database

ข้อดีคือ sensor หลายตัวอยู่ไกล controller ได้โดยไม่ต้องให้ทุก node มี Wi-Fi/Cloud ของตัวเอง

RS485 เหมาะกับ Energy Monitoring อย่างไร

Energy Meter และ Inverter จำนวนมากมี serial interface สำหรับ telemetry/control ตามรุ่น

Architecture:

Energy Meter
   ↓ RS485 / Modbus RTU
Gateway
   ↓ MQTT/API
Load Profile / EMS

ทำให้ field layer แยกจาก application layer

Troubleshooting แยกทีละ Layer

ถ้าอ่านอุปกรณ์ไม่ได้ อย่ากระโดดไปแก้ register ก่อน

ตรวจตามลำดับ:

Power
 ↓
Wiring / polarity
 ↓
RS485 electrical bus
 ↓
UART settings
 ↓
Protocol address/function
 ↓
Register map / datatype / scale

วิธีนี้ช่วยแยก physical problem ออกจาก protocol problem

สรุป

RS485 เหมาะกับ field communication เพราะเป็น differential serial bus ที่ทนต่อ environment จริงได้ดีกว่า logic UART โดยตรงเมื่อออกแบบถูก

จำง่าย ๆ:

UART = MCU serial peripheral
RS485 = electrical field bus
Modbus RTU = protocol ที่มักวิ่งบน RS485

ถ้าจะต่อ ESP32 เข้ากับ Meter/Sensor จริง ให้ดูครบทั้ง transceiver, topology, termination, polarity, serial setting และ protocol map ไม่ใช่ดูแค่คำว่า “มี RS485” บนหน้าสินค้า