1.05k likes | 1.24k Vues
2012 TS Academy DC – Serial Communication. Prepared by: Thomas Cheng Date: 31-09-2012. Who am I?. 鄭智仁 Thomas Cheng Member of technical service team in DC (8.5Y) Biking, hiking, & running Extension No.1154. Serial Communication. Why Serial Serial Introduction RS-232, RS-422/485
E N D
2012 TS AcademyDC – Serial Communication Prepared by: Thomas Cheng Date: 31-09-2012
WhoamI? • 鄭智仁 Thomas Cheng • Member of technical service team in DC (8.5Y) • Biking, hiking, & running • Extension No.1154 Confidential
SerialCommunication WhySerial Serial Introduction RS-232, RS-422/485 The Others about Practical Q&A Appendix Confidential
Training Essential • Reference&Advanced Study • http://en.wikipedia.org/wiki/Serial_port • http://en.wikipedia.org/wiki/Parallel_port • http://en.wikipedia.org/wiki/IEEE_1284 • http://www.freebsd.org/doc/en_US.ISO8859-1/articles/serial-uart/index.html Confidential
YouwillLearn… Theserialcommunicationconcept Thenecessaryinformationtobesuccessfulindesigning,modifyingortroubleshootinganRS-232,RS-422andRS485communicationsystem. Q&A Confidential
Why Serial? Confidential
Serial isEverywhere Confidential
Dial-upModem Confidential
POS Confidential
ATM Confidential
Kiosk Confidential
Door Access Control Confidential
LED and LCD text displays Confidential
GPS Confidential
Test and Measuring Equipment Confidential
Updating Firmware Confidential
CNC&DNC Confidential
UPS Monitoring Confidential
Software Debuggers Confidential
ConsoleManagement Confidential
Industrial Fieldbuses Confidential
Serial is Old Fashion? • Simple, cheap, highly standardized and widespread. • However, limited transmission speed, distance, relatively large voltage swing, and large standard connectors. • New techs: Ethernet, USB, SATA, PCIe Confidential
Serial Introduction Confidential
Serial Introduction • Parallel vs. Serial Communication • Synchronousvs.Asynchronous • Asynchronous Communication • UART • Block Diagram, Format, Framing, NRZ Coding • Baudrate, Throughput • FIFO, Flow Control • Transmission, Topology Confidential
Parallel Byte Byte ‘e’ ‘e’ 0x65 0x65 Byte(8 bits) -> Byte (8 bits)
Serial Communication Bit Byte Byte 0110 0101 ‘e’ ‘e’ 0x65 0x65 Byte -> Bit, Bit, Bit… -> Byte
Parallel vs. Serial Communication Confidential
Synchronous &Asynchronous Asynchronous Synchronous Serial setting must be the same on two side. Data Data CLK
Synchronousvs.Asynchronous Confidential
Asynchronous Comm. Type I • A & B set the same baudrate. • 16 times clock rate. • 當接收端偵測到falling edge時,再count 8個clock,如果仍是low表示是一個合法的start bit,此時正在start bit的中間,此後再count 16 clock則抓到D0,再count 16 clock則抓到D1….最後收完整個UART frame。 • 兩端的clock可以差距很大 (<3%) • Ex: UART Confidential
Asynchronous Comm. Type II • 假設兩端的clock差異是很小的(<3ppm) • 當接收端收到preamblepattern (ex,0101010101010), • 接收端的機制會開始做鎖相動作(校正), • 經過一段時間後(如Ethernet需要48bytes time), • 接收端的clock會調整成和送端相同的phase,此時就會視同兩端的clock同步。 • 同時具備sync.與async. comm.的優點. • 不需要傳送clocksignal, 又可以達到高速 • Ex, Ethernet, USB, SATA,PCIe Confidential
UART Bit Byte 0110 0101 ‘e’ 0x65 Universal asynchronous receiver/transmitter Translates data between parallel and serial forms Confidential
Block Diagram Confidential
Format Start bit: Always set “low”, 1 bit Data bit: 5, 6, 7, 8 bit Parity: None, Odd, Even, Space, Mark, 1 bit Stop bit: 1, 1.5 (Data bit = 5), 2 bit Confidential
Frame • D/P/S (Data/Parity/Stop) • 8/N/1 (8N1) • This specifies 8 data bits, no parity, 1 stop bit. • In this notation, the parity bit is not included in the data bits. • 7/E/1 (7E1) • Means that an even parity bit is added to the seven data bits for a total of eight bits between the start and stop bits. • If a receiver of a 7/E/1 stream is expecting an 8/N/1 stream, what will happen? Confidential
NRZCoding • Non return to zero • Binary code • “1” represented by one significant condition (usually a positive voltage) • “0” represented by the other significant condition (usually a negative voltage), • No other neutral or rest condition • For example, RS-232 data signal: • "one" is -12V to -5V • "zero" is +5 to +12V Confidential
Baud Rate, Throughput • Baud Rate • bps: bits per second • Include start bit, data bit, parity bit, stop bit • General range: 110 – 115.2k bps • Moxa product range: 50 – 115.2k~921.6k bps • Throughput • Bps: bytes per second • For 8N1, full rate: throughput = baud rate/10 • Ex: For 115.2kbps, 8N1, full rate = 11520 Bps • Throughput is not equal to baud rate. • Do not use “speed” for baud rate or throughput Confidential
Non-Standard Baudrate 500Kbps Users may enter the desired non-standard baud rate, such as 7812 bps, 89.3Kbps, 31250 bps, 153.6 Kbps For example, SICK Data Transmission Sensors require 500K bps Confidential
500000 - 491520 254234 - 250000 1.7% < 3% 1.7% < 3% = = 500000 250000 500000 526629 491520 1+ 6/8 1.8432 1+ 7/8 250000 254234 245760 3+ 5/8 3.6864 3+ 6/8 How to Calculate Baud Rate? Traditionalsolution is to change the oscillator Baud rate options are fixed 921600, 460800, 230400, … If 500000 bps (7.8% > 3%) or 250000 bps (7.8% > 3%) is needed, we must exchange the oscillator (modify the hardware) (divisoris integer) New solution allows any baud rate without changing oscillator → (Enum = 0-7) →
FIFO • A UART’s FIFO buffer is designed to improve communication performance. • If it is configured incorrectly, you may find that your communication performance is degraded. • For an 8250 or 16450 UART, • The FIFO has a size of only one byte. This means that the UART will issue an interrupt to the system for each byte of data received, which uses a lot of CPU resources. • If you don’t read the data from the UART in time, the next byte will overwrite the data. Confidential
Tradeoff Between Throughput and Latency • Higher throughput: transmitting more bytes once. • For some older devices with a small buffer, it is easy to get overrun in high throughput situations. The solution is to transmit one byte. • Smaller latency: transmitting less bytes once. • The relation on FIFO High/Low Water and Flow Control. Confidential
Flow Control • Prevent data overrun, improve performance • Flow control is used in UART FIFOs, drivers, and OS kernels. Confidential
High/Low Water Level • Receive buffer high water level (RBH) • RBH prevents the receive buffer from overrunning by telling the transmitting side to stop sending data before the Rx buffer is full • Receive buffer low water level (RBL) • RBL, on the other hand, defines when data transmission should be resumed. Confidential
On-chip Flow Control Lets You Stop Transmitting in Time • UART processes the RTS/CTS signals and XON/XOFF characters automatically. • Using a poorly designed driver could cause data loss either. • To enable flow control, you need to check both software and hardware settings. • If you don’t need to use flow control, make sure the setting is off. • If HWflow control is enabled without an RTS/CTS cable connection, what will happen? Confidential
Transmission Simplex Half-duplex Full-duplex Confidential
Topology Point to Point Daisy Chain (Multi-drop) Star Confidential