Serial Communications Sending and receiving data between devices
Serial Communications Sending and receiving data between devices CE-2810 Dr. Mark L. Hornick 1
Serial Communications describes a general way in which two devices can send or receive data from one another To send or receive data, bits have to be moved around The term Serial indicates that the data bits are transmitted sequentially, one bit at a time l Using only one wire pair Conversely, in parallel communication, multiple bits are transmitted simultaneously using multiple wires CE-2810 Dr. Mark L. Hornick 2
The physical transmission of serial data takes many forms (e. g. different speeds and voltages) l l l USB (Universal Serial Bus) Firewire Ethernet RS-232 RS-422 RS-485 CS-280 Dr. Mark L. Hornick 3
Atmel Atmega 32 USART : Universal Synchronous/Asynchronous Receiver/Transmitter The USART is a subsystem of the chip that can be enabled/disabled and controlled via special-purpose I/O registers CS-280 Dr. Mark L. Hornick 5
Serial data is received/sent using RXD and TXD pins, which overlap Port. D pins PD 0 and PD 1 The microcontroller does not have enough pins for all functions, so some pins server multiple purposes, depending on what function you enable l Enabling the USART receiver disables PD 0 function l Enabling the USART transmitter disables PD 1 function RXD/PD 0 pin is used to receive serial data TXD/PD 1 pin is used to transmit serial data CE-2810 Dr. Mark L. Hornick 6
On the ATMEGA 32 board, RXD, TXD, and GND are generally accessed via the “UART” terminal GVTR Embedded Systems II, Copyright 2010 7
Asynchronous vs Synchronous l In synchronous communications, the two communicating devices must keep their respective clock signals synchronized l l Even when no data is being sent, the two devices continuously exchange “sync” characters In asynchronous communications, the two devices maintain their own clocks l Nothing is transmitted when there is nothing to send l But a “handshake” has to be established whenever data needs to be transmitted – extra overhead The USART subsystem of the Atmega 32 supports both modes, but we’ll only use the asynchronous mode. CE-2810 Dr. Mark L. Hornick 8
Asynchronous transmission of a byte of data l Each byte of data is surrounded by “framing” bits, inserted by the USART LSB MSB 5, 6, 7, 8, or 9 data bits Parity bit can be disabled (no parity bit) 1 or 2 stop bits CS-280 Dr. Mark L. Hornick 9
The Parity bit is an error checking mechanism used to detect data corruption Equal to 1 if the number of non-zero data bits is odd, (#data bits + parity bit = even number of bits) Equal to 1 if the number of non-zero data bits is even, (#data bits + parity bit = odd number of bits) The Parity is computed first on the transmitting end, and included as the Parity bit in the frame. The Parity is then recomputed on the receiving end, and the result is compared to the Parity bit value. If the Parity calculation on the receiving end does not match, the receiver knows data corruption occurred. This allows errors to be DETECTED, but does not provide a means of CORRECTION. CS-280 Dr. Mark L. Hornick 10
TTL signal transmission of the letter ‘K’ (ASCII 0 x 4 B=01001011) with 8 data bits, 1 start bit, 1 stop bit, and no parity bit – 10 bits total Idle Start 1 1 0 0 1 0 Stop 5 v 0 v time All time increments are equal CS-280 Dr. Mark L. Hornick 11
RS-232 signal transmission of the letter ‘K’ (ASCII 0 x 4 B=01001011) with 8 data bits, 1 start bit, 1 stop bit, and no parity bit – 10 bits total CS-280 Dr. Mark L. Hornick 12
Speed metrics l l l The speed of serial transmission is usually measured in bits-per-second This is called the baud rate Because of the overhead bits used in each frame, 2400 baud is NOT the same as 300 characters per second l l Since each character takes 10 -12 bits to transmit, depending on configuration The Atmega 32 USART can be configured to operate between 2400 and 1 M baud CS-280 Dr. Mark L. Hornick 13
- Slides: 13