Serial Communications (Chapter 10)

Slides:



Advertisements
Similar presentations
Serial Interface Dr. Esam Al_Qaralleh CE Department
Advertisements

Chapter 14 Communications Introduction
I2C bus Inter Integrated Circuits bus by Philips Semiconductors
INPUT-OUTPUT ORGANIZATION
11-1 ECE 424 Design of Microprocessor-Based Systems Haibo Wang ECE Department Southern Illinois University Carbondale, IL I/O System Design.
Interrupts, Low Power Modes and Timer A (Chapters 6 & 8)
MSP430G2553 launchpad and MPU6050 Introduction
Chung-Ta King National Tsing Hua University
ECT 357 Ch 18 UART. Today’s Quote: Be careful that your marriage doesn’t become a duel instead of a duet. Be careful that your marriage doesn’t become.
The 8051 Microcontroller Chapter 5 SERIAL PORT OPERATION.
Lecture 8: Serial Interfaces
ECE 447 Fall 2009 Lecture 9: TI MSP430 Interrupts & Low Power Modes.
Confidentiality/date line: 13pt Arial Regular, white Maximum length: 1 line Information separated by vertical strokes, with two spaces on either side Disclaimer.
LAB 6: Serial Communication
7-1 Digital Serial Input/Output Two basic approaches  Synchronous shared common clock signal all devices synchronised with the shared clock signal data.
Chapter 6 Serial Communications Objectives Introduce the RS232 standard and position it within the crowded field of serial communications standards. Configure.
ECE 371- Unit 11 Introduction to Serial I/O. TWO MAJOR CLASSES OF SERIAL DATA INTERFACES ASYNCHRONOUS SERIAL I/O - USES “FRAMING BITS” (START BIT AND.
Network and Systems Laboratory nslab.ee.ntu.edu.tw.
Lecture 27: LM3S9B96 Microcontroller – Inter- Integrated Circuit (I 2 C) Interface.
University of Tehran 1 Interface Design Serial Communications Omid Fatemi.
Technology Training that Works Hands of Data Communications, Networking & TCP/IP Troubleshooting.
LSU 10/22/2004Serial I/O1 Programming Unit, Lecture 5.
4.0 rtos implementation part II
The 8051 Microcontroller and Embedded Systems
Serial Port I/O Serial port sends and receives data one bit at a time. Serial communication devices are divided into: Data Communications Equipment (DCE),
SC200x Peripherals Broadband Entertainment Division DTV Source Applications July 2001.
Lecture Set 9 MCS-51 Serial Port.
Universal Synchronous/Asynchronous Receiver/Transmitter (USART)
1 Microprocessor-based Systems Course 9 Design of the input/output interfaces (continue)
CSE466 Autumn ‘00- 1 Music Format if amp = 0, note is a command switch(note) 0: turn off specified channel 1: continue for specified tne w/ no change else.
Universal Asynchronous Receiver/Transmitter (UART)
Microprocessors 2 lesson Subjects lesson 7 Planning Interrupts Serial communication /USART Questions.
Serial Communications
Scott Baker Will Cross Belinda Frieri March 9 th, 2005 Serial Communication Overview ME4447/6405.
Example. SBUF Register SCON Register(1) SCON Register(2)
 8251A is a USART (Universal Synchronous Asynchronous Receiver Transmitter) for serial data communication.  Programmable peripheral designed for synchronous.
NS Training Hardware. Serial Controller - UART.
Universal Asynchronous Receiver/Transmitter (UART)
ATtiny23131 A SEMINAR ON AVR MICROCONTROLLER ATtiny2313.
©2008 R. Gupta, UCSD COSMOS Summer 2008 Peripheral Interfaces Rajesh K. Gupta Computer Science and Engineering University of California, San Diego.
Serial Communications Interface Module Slide #1 of 19 MC68HC908GP20 Training PURPOSE -To explain how to configure and use the Serial Communications Interface.
© 2009, Renesas Technology America, Inc., All Rights Reserved 1 Course Introduction  Purpose:  This course provides an overview of the serial communication.
Essentials of Communication This simple model requires many guarantees. Sender Receiver Communication Link Data.
CE-2810 Dr. Mark L. Hornick 1 Serial Communications Sending and receiving data between devices.
UBI >> Contents Lecture 11 Communications Introduction & USI Module MSP430 Teaching Materials Texas Instruments Incorporated University of Beira Interior.
8251 USART.
Tiva C TM4C123GH6PM UART Embedded Systems ECE 4437 Fall 2015 Team 2:
The HCS12 SCI Subsystem A HCS12 device may have one or two serial communication interface. These two SCI interfaces are referred to as SCI0 and SCI1. The.
Introduction to MSP430G2553 and MPU6050
Serial mode of data transfer
ECE 382 Lesson 15 Lesson Outline S/W Delays Wrap up
I2C Protocol and RTC Interfacing
EMBEDDED SYSTEMS UNIT 4.
EE 107 Fall 2017 Lecture 5 Serial Buses – UART & SPI
Source: Serial Port Source:
SERIAL PORT PROGRAMMING
SPI Protocol and DAC Interfacing
Serial Communication: RS-232 (IEEE Standard)
Source: Serial Port Source:
UART Serial Port Programming
Asynchronous Serial Communications
Serial Communication Interface: Using 8251
Serial Communication Interface
Lecture 9: TI MSP430 Interrupts & Low Power Modes
AVR – ATmega103(ATMEL) Architecture & Summary
Source: Serial Port Source:
CHAPTER SERIAL PORT PROGRAMMING. Basics of Serial Communication Computers transfer data in two ways: ◦ Parallel  Often 8 or more lines (wire.
Serial Communication 19th Han Seung Uk.
Source: Serial Port Source:
PIC Serial Port Interfacing
Presentation transcript:

Serial Communications (Chapter 10) RS232, SPI, I2C

Multiple (8 typically) data lines Communications The simplest is parallel One way There may be mechanism for peripheral to get attention of μC (i.e., interrupt, or poll) Two way We need another line to differentiate between read and write. Half duplex (one way at a time) Full duplex (both ways at once; needs two sets of data lines. This is resource expensive (pins, real-estate…) in terms of hardware, but easy to implement, and fast. μC Peripheral Multiple (8 typically) data lines “Latch” “CS” μC Peripheral “Latch” “CS” “R/~W” Data lines

Serial Communications Many fewer lines are required to transmit data. This is requires fewer pins, but adds complexity. Synchronous communications requires clock. Whoever controls the clock controls communication speed. Asynchronous has no clock, but speed must be agreed upon beforehand (baud rate). μC Peripheral Clock “CS” Data

MSP430G2553

Asynchronous Serial (RS-232) Commonly used for one-to-one communication. There are many variants, the simplest uses just two lines, TX (transmit) and RX (receive). Transmission process (9600 baud, 1 bit=1/9600=0.104 mS) Transmit idles high (when no communication). It goes low for 1 bit (0.104 mS) It sends out data, LSB first (7 or 8 bits) There may be a parity bit (even or odd – error detection) There may be a stop bit (or two) required

RS232 Voltage levels From processor side, 0V=logic 0, 3.3V=logic 1 In a “serial” cable +12+3V=logic 0, -3-12V=logic 1

RS232 – Handshaking Some RS232 connections using handshaking lines between DCE (Data Communications Equipment) and DTE (Data Terminal Equipment). RTS (Ready To Send) Sent by the DTE to signal the DCE it is Ready To Send. CTS (Clear To Send) Sent by the DCE to signal the DTE that it is Ready to Receive. DTR (Data Terminal Ready) Sent to DTE to signal the DCE that it is ready to connect DSR (Data Set Read) Sent to DC to signal the DTE that it is ready to connect In practice if these handshaking lines are used it can be difficult to set up the serial communications, but it is quite robust once working. There is also software handshaking (XON/XOFF) DTE and DCE have different connector pinouts.

MSP430 USCI in UART mode (also USART peripheral) UART mode features include: 7- or 8-bit data; odd, even, or non-parity Independent transmit and receive LSB-first or MSB-first data Receiver start-edge detection for auto-wake up from LPMx modes Independent interrupt capability for receive and transmit Status flags for error detection and suppression Built-in idle-line and address-bit communication protocols for multiprocessor systems Status flags for address detection

UART code void main(void) { WDTCTL = WDTPW + WDTHOLD; // Echo received character, RX ISR used. Normal mode is LPM0. // USCI_A0 RX interrupt triggers TX Echo. // Baud rate divider with 1MHz = 1MHz/115200 = ~8.7 // ACLK = n/a, MCLK = SMCLK = CALxxx_1MHZ = 1MHz // // MSP430G2xx3 // ----------------- // /|\| XIN|- // | | | // --|RST XOUT|- // | P1.2/UCA0TXD|------------> // | P1.1/UCA0RXD|<------------ void main(void) { WDTCTL = WDTPW + WDTHOLD; BCSCTL1 = CALBC1_1MHZ; // Clock = 1MHz DCOCTL = CALDCO_1MHZ; P1SEL = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD P1SEL2 = BIT1 + BIT2; UCA0CTL1 |= UCSSEL_2; // SMCLK UCA0BR0 = 8; // 1MHz 115200 (Formulae in data sheet) UCA0BR1 = 0; // 1MHz 115200 UCA0MCTL = UCBRS2 + UCBRS0; // Modulation UCBRSx = 5 UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine** IE2 |= UCA0RXIE; // Enable USCI_A0 RX interrupt __bis_SR_register(LPM0_bits + GIE); // Enter LPM0, interrupts enabled } // Echo back RXed character, confirm TX buffer is ready first #pragma vector=USCIAB0RX_VECTOR __interrupt void USCI0RX_ISR(void) while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready? UCA0TXBUF = UCA0RXBUF; // TX -> RXed character

SPI (a synchronous interface) (Serial Peripheral Interface - Motorola) Two types of devices, masters and slaves. We’ll consider only one master, but multiple slaves. Signals SCLK: Serial CLocK, set by Master MOSI: Master Out, Slave In MISO: Master In, Slave Out ~SS: Slave Select Each slave gets its own slave select (other lines are shared) Pulling line low selects slave

SPI and the clock (intro) Clock idles low Master pull slave select line low to select device. First bit of data gets put on MISO and MOSI (so a byte goes both ways) Data gets shifted out (typically 8 bits, but not necessarily) The data gets put on bus on falling edge of clock (or SS). The data gets read on the rising edge of clock.

SPI and the clock (the hard truth) Unfortunately, clock can be set many ways as determined by clock polarity and phase. CPOL=0: Base value of the clock is 0 CPHA=0: Data read on rising edge, put on bus on falling edge of SCLK. (i.e., clock is low). (Case from previous slide) CPHA=1: Data read on falling edge, put on bus on rising edge (i.e., clock is high). CPOL=1: Base value of the clock is 1 CPHA=0: Data read on falling edge, put on bus on rising edge (i.e., clock is high). CPHA=1: Data read on rising edge, put on bus on falling edge (i.e., clock is low).

SPI and SCI SPI mode features include: 7- or 8-bit data length LSB-first or MSB-first data Master or slave modes Selectable clock polarity and phase control Programmable clock frequency in master mode Independent transmit and receive Continuous transmit and receive Independent interrupt capability for receive and transmit Slave operation in LPM4

SPI Code void main(void) { volatile unsigned int i; char data; // MCLK = SMCLK = default DCO ~1048k, BRCLK = SMCLK/2 // /|\ ---------------------- // TLC549 | | XIN |- 32kHz // ------------- --|RST XOUT|- // | CS|<---|P3.0 | // | DATAOUT|--->|P3.2/UCB0SOMI | // ~>| IN+ I/O CLK|<---|P3.3/UCB0CLK P5.1|--> LED void main(void) { volatile unsigned int i; char data; P5DIR |= 0x02; // P5.1 output P3SEL |= 0x0C; // P3.3,2 option select P3DIR |= 0x01; // P3.0 output direction UCB0CTL0 |= UCMST+UCSYNC+UCMSB; // 8-bit SPI mstr, MSb 1st, CPOL=0, CPHS=0 UCB0CTL1 |= UCSSEL_2; // SMCLK UCB0BR0 = 0x02; // Set Frequency UCB0BR1 = 0; UCB0CTL1 &= ~UCSWRST; // **Initialize USCI state machine** while(1) P3OUT &= ~0x01; // Enable TLC549 (A/D) , ~CS (~SS) reset UCB0TXBUF = 0x00; // Dummy write to start SPI while (!(IFG2 & UCB0RXIFG)); // USCI_B0 RX buffer ready? data = UCB0RXBUF; // data = 00|DATA P3OUT |= 0x01; // Disable TLC549, ~CS (~SS) set if(data>=0x7F) P5OUT |= 0x02; // data = AIN > 0.5(REF+ - REF-)? LED On else P5OUT &= ~0x02; // LED off }

I2C or I2C (Inter-Integrated Circuit – Philips) As with SPI a master- slave system. Also called a 2-wire bus. It Has only clock and data, with pull-up resistors (Rp in diagram). Lines can be pulled low by any device, and are high when all devices release them. There are no “slave-select” lines – instead the devices have “addresses” that are sent as part of the transmission protocol. Four max speeds (100 kbS (standard), 400 kbS (fast), 1 MbS (fast plus), and 3.4 MbS (high-speed)

I2C Write a Single Byte All: allow SDA, SCL start high Master: SDA low to signal start Master: Send out SCL, and 7 bit address followed by 0 (~W) on SDA Slave: Pull SDA low to signify ACKnowledge Master: Send out 8 data bits on SDA Slave: Ack All: allow SDA to go high when SCL is high (stop) For “Read”, Master: Address following by 1 (R) on SDA Slave: Send out 8 data bits on SDA Master: Ack

Other Features You can transfer multiple bytes in a row At any time, slave can hold SCL low to slow transfer down (called “clock-stretching”) Any device that malfunctions can disable bus.

I2C and SCI The I2C features include: Compliance to Philips I2C specification Slave receiver/transmitter mode Standard mode up to 100 kbps and fast mode up to 400 kbps support Programmable UCxCLK frequency in master mode Designed for low power Slave receiver START detection for auto-wake up from LPMx modes Slave operation in LPM4

I2C Code // Demo - USCI_B0 I2C Master Interface to DAC8571, Write // Description: Using UCB0TXIE, a continuous sine wave is output to // external DAC using a 16-point look-up table. Only one start // is executed. Data is handled by the ISR and the CPU is in LPM0. // MCLK = SMCLK = TACLK = BRCLK = 1MHz // DAC8571 I2C address = 0x4C (A0 = GND) // ------------------ ------------ // -|XIN P3.1/UCB0SDA|<--------------->|SDA | // 32kHz | P3.2/UCB0SCL|---------------->|SCL I2C | // -|XOUT | | SLAVE | // | I2C MASTER | GND|A0 | void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop Watchdog Timer P3SEL |= 0x06; // Assign I2C pins to USCI_B0 UCB0CTL1 |= UCSWRST; // Enable SW reset UCB0CTL0 = UCMST + UCMODE_3 + UCSYNC; // I2C Master, synchronous mode UCB0CTL1 = UCSSEL_2 + UCSWRST; // Use SMCLK, keep SW reset UCB0BR0 = 11; // fSCL = SMCLK/11 = 95.3kHz UCB0BR1 = 0; UCB0I2CSA = 0x4c; // Set slave address UCB0CTL1 &= ~UCSWRST; // Clear SW reset, resume operation IE2 |= UCB0TXIE; // Enable TX ready interrupt UCB0CTL1 |= UCTR + UCTXSTT; // I2C TX, start condition UCB0TXBUF = 0x10; // Write DAC control byte __bis_SR_register(CPUOFF + GIE); // Enter LPM0 w/ interrupts } // USCI_B0 Data ISR #pragma vector = USCIAB0TX_VECTOR __interrupt void USCIAB0TX_ISR(void) { static unsigned char ByteCtr; UCB0TXBUF = Sine_Tab[ByteCtr++]; // Transmit data byte ByteCtr &= 0x0f; // Do not exceed table

Wireless Data rates needed Order: Increasing complexity, power and bandwidth SimpliciTI: <200 kbS Zigbee (IEEE 802.15.4): 250 kbS Bluetooth (IEEE 802.15.1): 1 MbS – 24 MbS (Now Bluetooth LE) WiFi (IEEE 802.11): b 11 MbS; g 54 MbS; n 150 MbS Data rates needed Voice: 4 kbS Music: 700 kbS Video: 3.5 MbS Standard; 40 MbS Blu-ray