Serial Communications (Chapter 10) RS232, SPI, I2C



Similar documents
Elettronica dei Sistemi Digitali Costantino Giaconia SERIAL I/O COMMON PROTOCOLS

Implementing SPI Communication Between MSP430 G2452 and LTC ADC

Embedded Systems Design Course Applying the mbed microcontroller

SPI I2C LIN Ethernet. u Today: Wired embedded networks. u Next lecture: CAN bus u Then: wireless embedded network

Serial Communications

Implementing SPI Master and Slave Functionality Using the Z8 Encore! F083A

Raspberry Pi. Hans- Petter Halvorsen, M.Sc.

Introduction the Serial Communications Huang Sections 9.2, 10.2 SCI Block User Guide SPI Block User Guide

Quectel Cellular Engine

Serial Communications

Data Cables. Schmitt TTL LABORATORY ELECTRONICS II

Objectives. Basics of Serial Communication. Simplex vs Duplex. CMPE328 Microprocessors (Spring ) Serial Interfacing. By Dr.

Pmod peripheral modules are powered by the host via the interface s power and ground pins.

ARM Thumb Microcontrollers. Application Note. Software ISO 7816 I/O Line Implementation. Features. Introduction

Allows the user to protect against inadvertent write operations. Device select and address bytes are Acknowledged Data Bytes are not Acknowledged

USER GUIDE EDBG. Description

Timer A (0 and 1) and PWM EE3376

AND8336. Design Examples of On Board Dual Supply Voltage Logic Translators. Prepared by: Jim Lepkowski ON Semiconductor.

DS1621 Digital Thermometer and Thermostat

DS1621 Digital Thermometer and Thermostat

AVR151: Setup and Use of the SPI. Introduction. Features. Atmel AVR 8-bit Microcontroller APPLICATION NOTE

SC16IS740/750/760. Single UART with I 2 C-bus/SPI interface, 64 bytes of transmit and receive FIFOs, IrDA SIR built-in support

Using the HT46R46 I/O Ports to Implement Half-Duplex SPI Communication

TURBO PROGRAMMER USB, MMC, SIM DEVELOPMENT KIT

FR FAMILY MB91460 SPI - DAISY CHAIN COMMUNICATION 32-BIT MICROCONTROLLER APPLICATION NOTE. Fujitsu Microelectronics Europe Application Note

Develop a Dallas 1-Wire Master Using the Z8F1680 Series of MCUs

Part 1. MAX BIT DAC with an Arduino Board. MIDI to Voltage Converter Part1

RS-232 COMMUNICATIONS

Data Sheet. Adaptive Design ltd. Arduino Dual L6470 Stepper Motor Shield V th November L6470 Stepper Motor Shield

DS Wire Digital Thermometer and Thermostat

Modbus Communications for PanelView Terminals

Bluetooth UART/RS232 Module

User Manual IC-485AI

MODULE BOUSSOLE ÉLECTRONIQUE CMPS03 Référence :

SC16C652B. 1. General description. 2. Features. 5 V, 3.3 V and 2.5 V dual UART, 5 Mbit/s (max.) with 32-byte FIFOs and infrared (IrDA) encoder/decoder

Using Xbee in Serial Communication

Single channel data transceiver module WIZ2-434

LTM-1338B. Plus Communications Manual

MicroMag3 3-Axis Magnetic Sensor Module

RN-131-PICTAIL & RN-171-PICTAIL Evaluation Boards

Internal Oscillator. I 2 C Interface. SPI Interface. Controller. Internal Registers Port Controller. Eight I/O Pins. Figure 1.

Microtronics technologies Mobile:

The I2C Bus. NXP Semiconductors: UM10204 I2C-bus specification and user manual HAW - Arduino 1

DS1307ZN. 64 x 8 Serial Real-Time Clock

AN736. An I 2 C TM Network Protocol for Environmental Monitoring THE I 2 C BUS SPECIFICATION INTRODUCTION

Data Acquisition Module with I2C interface «I2C-FLEXEL» User s Guide

LOW COST GSM MODEM. Description. Part Number

VMR6512 Hi-Fi Audio FM Transmitter Module

AVR319: Using the USI module for SPI communication. 8-bit Microcontrollers. Application Note. Features. Introduction

Application Note 83 Fundamentals of RS 232 Serial Communications

Design and Implementation of Home Monitoring System Using RF Technology

INFORMATICA INDUSTRIALE

Hello, and welcome to this presentation of the STM32L4 reset and clock controller.

Analog to Digital Conversion of Sound with the MSP430F2013

AN141 SMBUS COMMUNICATION FOR SMALL FORM FACTOR DEVICE FAMILIES. 1. Introduction. 2. Overview of the SMBus Specification. 2.1.

RPDO 1 TPDO 1 TPDO 5 TPDO 6 TPDO 7 TPDO 8

Data sheet Wireless UART firmware version 4.02

Chapter 13. PIC Family Microcontroller

Software User Guide UG-461

USB2.0 <=> I2C V4.4. Konverter Kabel und Box mit Galvanischetrennung

Appendix A. This Appendix includes the following supplemental material:

MDM192 MULTI-DROPS DIGITAL MODEM FOR PRIVATE LINE. USER GUIDE Document reference :

2.8.3 / (Z80 Serial I/O)

USART and Asynchronous Communication

Implementing a Real-Time Clock on the MSP430

Real-Time Clock. * Real-Time Computing, edited by Duncan A. Mellichamp, Van Nostrand Reinhold

Parallel IO. Serial IO. Parallel vs. Serial IO. simplex vs half-duplex vs full-duplex. Wires: Full Duplex. Wires: Simplex, Half-duplex.

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Question Bank Subject Name: EC Microprocessor & Microcontroller Year/Sem : II/IV

Date Rev. Details Author

AVR315: Using the TWI Module as I2C Master. Introduction. Features. AVR 8-bit Microcontrollers APPLICATION NOTE

Manual Serial PCI Cards

DECT Module UM-9802 Datasheet

Definitions and Documents

8051 Serial Port. Crystal TXD. I/O Device RXD. Embedded Systems Peripherals

Below is a diagram explaining the data packet and the timing related to the mouse clock while receiving a byte from the PS-2 mouse:

AVR1309: Using the XMEGA SPI. 8-bit Microcontrollers. Application Note. Features. 1 Introduction SCK MOSI MISO SS

Section 17. UART HIGHLIGHTS UART. This section of the manual contains the following major topics:

Advanced Data Capture and Control Systems

UART IP Core Specification. Author: Jacob Gorban

SKYEMODULE GEMINI DATASHEET VERSION

ZL30136 GbE and Telecom Rate Network Interface Synchronizer

Debugging Serial Buses in Embedded Systems Designs

HARDWARE MANUAL. BrightSign HD120, HD220, HD1020. BrightSign, LLC Lark Ave., Suite 200 Los Gatos, CA

Microcomputer Protocol Implementation at Local Interconnect Network Georgi Krastev

AN601 I2C 2.8 Communication Protocol. SM130 SM130 - Mini APPLICATION NOTE

DK40 Datasheet & Hardware manual Version 2

INFORMATICA INDUSTRIALE

GTS-4E Hardware User Manual. Version: V1.1.0 Date:

Network Operation and Troubleshooting

Microcontrollers in Practice

Universal EXTension connector (UEXT)

CENTRONICS interface and Parallel Printer Port LPT

Computer Organization and Components

Implementing MOD bus and CAN bus Protocol Conversion Interface

SafeSPI - Serial Peripheral Interface for Automotive Safety

8-bit Microcontroller. Application Note. AVR134: Real-Time Clock (RTC) using the Asynchronous Timer. Features. Theory of Operation.

Real-Time Vehicle Data Logging System Using GPS And GSM

FPGA INTEGRATION MANUAL SATURN-SIL 2 MODULES. Dictionary Code. Edition 01. Revision 00. Number of pages 18

Interfacing Of PIC 18F252 Microcontroller with Real Time Clock via I2C Protocol

PLC Master / Slave Example

Transcription:

Serial Communications (Chapter 10) RS232, SPI, I2C

Thesimplest is parallel One way Communications There may be mechanism for peripheral to get attention of μc(i.e., interrupt, or poll) μc Multiple (8 typically) data lines Latch CS Peripheral Two way Data lines μc Latch CS R/~W Peripheral This is resource expensive (pins, real estate estate ) in terms of hardware, but easy to implement

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

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)

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 On Experimenter s board Physical connector

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 h 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 autowake up from LPMx modes Independent interrupt capability for receive andtransmit 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 #include "msp430xg46x.h" void main(void) { volatile unsigned int i; // Echo a received character, RX ISR used. Normal mode is LPM3, // USCI_A0 RX interrupt triggers TX Echo. // ACLK = BRCLK = LFXT1 = 32768, MCLK = SMCLK = DCO~1048k // Baud divider, 32768hz XTAL @9600= 32768/9600= 3.41(0003h 03h ) // ----------------- // / \ MSP430xG461x - // XIN - 32kHz // -- RST XOUT - // P4.7/UCA0RXD ------------> // 9600-8N1 // P4.6/UCA0TXD <------------ P4SEL = 0x0C0; // P4.7,6 = USCI_A0 RXD/TXD UCA0CTL1 = UCSSEL_1; // CLK = ACLK UCA0BR0 = 0x03; // 32k/9600-3.41 UCA0BR1 = 0x00; // User s manual has formulas for these UCA0MCTL = 0x06; // Modulation UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine** IE2 = UCA0RXIE; // Enable USCI_A0 RX interrupt } _BIS_SR(LPM0_bits + GIE); // Enter LPM0, interrupts enabled // Echo back RXed character, confirm TX buffer is ready first #pragma vector=usciab0rx_vector interrupt void USCIA0RX_ ISR (void) { while(!(ifg2&uca0txifg)); // Make sure last character went out. UCA0TXBUF = UCA0RXBUF; // TX -> RXed character }

SPI (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 t( (other lines are shared) Pulling line low selects slave

SPI and the clock (intro) Pull slave select line low to select device. First bit of data gets put on MISO and MOSI (so a byte goes both ways) Dt Data gets shifted out (typically 8 bits, but not necessarily) The data gets put on bus on falling edge of clock. 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, g,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 #include "msp430xg46x.h" // MCLK = SMCLK = default DCO ~1048k, BRCLK = SMCLK/2 // ---------------------- // / \ MSP430xG461x // 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 i 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 I 2 C (Inter Integrated Circuit Philips) p) As with SPI a masterslave system. Also called a 2 wire bus. It Has only clock and data, with pull up p 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 1. All: allow SDA, SCL start high 2. Master: SDA low to signal start 3. Master: Send out SCL, and 7 bit address followed by 0 (~W) on SDA 4. Slave: Pull SDA low to signify ACKnowledge 5. Master: Send out 8 data bits on SDA 6. Slave: Ack 7. All: allow SDA to go high when SCL is high (stop) For Read, 3. Master: Address following by 1 (R) on SDA 5. Slave: Send out 8 data bits on SDA 6. Master: Ack

Other Features You can transfer multiple bytes in a row At end of transfer, 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 itt mode Standard mode up to 100 kbps and fast mode up to 400 kbps support Programmable UCxCLK frequency in master mode Designedfor low power Slave receiver START detection for auto wake up from LPMx modes Slave operation in LPM4

I2C Code // MSP430xG461x 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) // MSP430xG461x DAC8571 // ------------------ ------------ // - 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 = 0x010; // 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 &= 0x1f; // Do not exceed table

Wireless Order: Increasing complexity, y,power and bandwidth SimpliciTI: <200 kbs Zigbee (IEEE 802.15.4): 250 kbs Bluetooth (IEEE 802.15.1): 1): 1 MbS 24 MbS 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

References MSP430x4xx Family User s Guide http://focus.ti.com/lit/ug/slau056j/slau056j.pdf MSP430FG4618/F2013 Experimenter s Board du User s Guide http://focus.ti.com/lit/ug/slau213a/slau213a.pdf /li / / l / l Serial Comm image http://www.ee.nmt.edu/~rison/ee308_spr99/supp/990406/sync_serial.gif RS 232 byte image http://www.eeherald.com/images/rs232 3.jpg RS 232 Connector Image http://www.bisque.com/tom/bluetooth/images/db9.jpg SPI http://en.wikipedia.org/wiki/serial_peripheral_interface_bus I2C: http://en.wikipedia.org/wiki/i%c2%b2c I2C: http://www.best microcontroller projects.com/i2c tutorial.html I2C: http://www.eetimes.com/design/analog design/4010395/signal CHAIN BASICS Part 32 Digitalinterfaces con t The I2C Bus