Top Banner

of 57

Interfacing mc

Jun 03, 2018

Download

Documents

Maha Devan
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • 8/11/2019 Interfacing mc

    1/57

    Interfacing of Devices to Microcontroller

    Prof Prabhat Ranjan([email protected])

    Dhirubhai Ambani Institute of Information andCommunication Technology, Gandhinagar

  • 8/11/2019 Interfacing mc

    2/57

    Acknowledgment

    Based on a document MicrocontrollerInterfacing Techniques available fromwww.bipom.com

    Wikipedia

  • 8/11/2019 Interfacing mc

    3/57

    Overview

    Micro-controllers are useful to the extent thatthey communicate with other devices, such assensors, motors, switches, keypads, displays,memory and even other micro-controllers

    Many interface methods have been developedover the years to solve the complex problem

    of balancing circuit design criteria such asfeatures, cost, size, weight, powerconsumption, reliability, availability,manufacturability

  • 8/11/2019 Interfacing mc

    4/57

    Overview

    Many microcontroller designs typically mixmultiple interfacing methods. In a verysimplistic form, a micro-controller system canbe viewed as a system that reads from(monitors) inputs, performs processing andwrites to ( controls ) outputs

  • 8/11/2019 Interfacing mc

    5/57

  • 8/11/2019 Interfacing mc

    6/57

  • 8/11/2019 Interfacing mc

    7/57

    Digital I/O - On/OFF control andmonitoring

    Advantages Simplest interface Lowest-cost to

    implement (built intothe microcontroller)

    High speed

    Low programmingoverhead

    Disadvantages Only on/off

    control/monitoring Short distance, few

    feet maximum Single device

    control/monitoring

    Digital Input Example: Reading the status ofbuttons or switches

  • 8/11/2019 Interfacing mc

    8/57

  • 8/11/2019 Interfacing mc

    9/57

    Digital Output : LED display

  • 8/11/2019 Interfacing mc

    10/57

    Digital Output : Relay Control

  • 8/11/2019 Interfacing mc

    11/57

    Analog I/O : Voltage-based controland monitoring

    Simple interface Low cost for low-

    resolutions High speed Low programming

    overhead

    High cost for higherresolutions

    Not all uC haveanalog I/O built-in

    Complicates thecircuit design when

    external ADC orDAC are needed Short distance, few

    feet maximum

  • 8/11/2019 Interfacing mc

    12/57

    Analog I/O types

    Voltage Ranges 0 to 2.5 V 0 to 4 V 0 to 5 V +/- 2.5 V +/- 4 V

    +/- 5 V

    Current Ranges 0-20 mA 4-20 mA

  • 8/11/2019 Interfacing mc

    13/57

    Analog Interface

  • 8/11/2019 Interfacing mc

    14/57

    Parallel Bus

    High speed High throughput:

    Several bits aretransmitted on oneclock transition

    Low cost

    Large number ofmicrocontroller pins

    needed forimplementing theparallel bus

    Consists of multiple digital inputs/outputs. Most common types: 4-bit 8-bit ( e.g. Centronics ) 16-bit ( e.g. ISA )

    32-bit ( e.g. PCI )

  • 8/11/2019 Interfacing mc

    15/57

  • 8/11/2019 Interfacing mc

    16/57

  • 8/11/2019 Interfacing mc

    17/57

    Serial Buses : I 2 C (Inter IntegratedCircuit bus)

    2-wire interface with one master and multipleslaves ( multi-master configurations possible)

    Originated by Philips Semiconductor in theearly 80s to connect a microcontroller toperipheral devices in TV sets

    Signals: DATA (SDA), CLOCK (SCL) and

    Ground. SDA is always bi-directional; SCL isbi-directional only in multi-master mode Maximum allowable capacitance on the lines

    is 400 pF. Typical device capacitance is 10 pF

  • 8/11/2019 Interfacing mc

    18/57

    Serial Buses : I 2 C (Inter IntegratedCircuit bus)

    To start the communications, the bus master(typically a microcontroller) places theaddress of the device with which it intends tocommunicate (the slave) on the bus

    All slave devices monitor the bus to determineif the master device is sending their address

    Only the device with the correct addresscommunicates with the master By definition, I 2C is 5V

  • 8/11/2019 Interfacing mc

    19/57

    Multiple slave

    devices - with only 3wires Low-cost to

    implement Implemented in

    hardware orsoftware

    Ease to implement,many examples

    Supports multi-master configuration

    Short distance

    Slow speed: 100KHz although 400KHz and 1 MHzslave device exist

    These can notcoexist with slowerdevices

    Limited deviceaddresses

  • 8/11/2019 Interfacing mc

    20/57

  • 8/11/2019 Interfacing mc

    21/57

    Start & Stop

    An I2

    C master prepares to communicate with aslave device first by generating a Startcondition on the bus

    Start condition is defined as SDA signal goinglow while SCL signal is high

    Stop condition is defined as SDA going highwhile SCL is high

  • 8/11/2019 Interfacing mc

    22/57

    Data Validity

    Data can change while the clock is low Data should remain stable while the clock is

    going high

  • 8/11/2019 Interfacing mc

    23/57

    Acknowledge(ACK)

  • 8/11/2019 Interfacing mc

    24/57

    Writing a byte to a serial EEPROM (24C04 )on the I2C bus:

  • 8/11/2019 Interfacing mc

    25/57

    where Device Address is defined as : P0, P1,P2 indicate the page number ( 2Kbit pages ).A0, A1, A2 indicate the device number on thebus

  • 8/11/2019 Interfacing mc

    26/57

    Reading a byte from a serial EEPROM(24C04 ) on the I2C bus ( starting from thecurrent address )

  • 8/11/2019 Interfacing mc

    27/57

  • 8/11/2019 Interfacing mc

    28/57

    SPI ( Serial Peripheral Interface )

    SPI bus is a master/slave interface. Whenevertwo devices communicate, one is referred toas the "master" and the other as the "slave"device

    The master drives the serial clock SPI is full duplex: Data is simultaneously

    transmitted and received

  • 8/11/2019 Interfacing mc

    29/57

    Multiple slavedevices - with onlyfew wires

    Low-cost HW/SW Implement Ease to implement,

    many examples

    Can be high speed( e.g. 4MHz orhigher ifimplemented inhardware )

    Short distance Data and clock lines

    can be shared buteach device requiresa separate ChipSelect signal, limitingthe number of

    devices in limited I/Osystems

  • 8/11/2019 Interfacing mc

    30/57

    SPI bus specifies fourlogic signals

    SCLK Serial Clock

    (output from master) MOSI Master Output,Slave Input (output frommaster)

    MISO Master Input,Slave Output (outputfrom slave)

    SS Slave Select(active low; output frommaster

    Sometimes, the followingnaming convention isused:

    SCLK Serial Clock(output from master) SDI Serial Data In SDO Serial Data Out CS Chip Select

    (active low; output frommaster)

  • 8/11/2019 Interfacing mc

    31/57

    SPI Bus with multiple slaves

    M lti di C d ( MMC ) I t f

  • 8/11/2019 Interfacing mc

    32/57

    Multimedia Card ( MMC ) Interfaceusing SPI

  • 8/11/2019 Interfacing mc

    33/57

  • 8/11/2019 Interfacing mc

    34/57

    Multiple slave devices-with only 2 wires Low-cost Implemented in HW/SW

    Ease to implement,many examples Relatively long

    distance. Theoretically

    300 meters but this islimited in practice dueto noise and cablecapacitance

    Slow speed 1-wire slave devices

    typically has to comefrom one source:DallasSemiconductor

    RS232

  • 8/11/2019 Interfacing mc

    35/57

    Asynchronous communications

    Popular interface with many examples Many compatible legacy devices Relatively long distance, 50 feet maximum for

    low baud rates although longer distanceswork in practice, with low baud rates and errorcorrection

    Immune to noise due to +/-5 Volts or highervoltage levels for logic 0 and 1

    Implemented in hardware or software Ease to implement, many examples

  • 8/11/2019 Interfacing mc

    36/57

    More suitable for system to systemcommunications, not so much for chip to chipor chip to sensor

    Low speed for long distance, 115200 baudcan be achieved with small microcontrollersusing short distances

    Requires transceiver chips which add tosystem cost ( TTL/CMOS level RS232 can beused without transceiver chips ).

    Single master/single slave

  • 8/11/2019 Interfacing mc

    37/57

    RS485

  • 8/11/2019 Interfacing mc

    38/57

    Asynchronous communications

    Popular interface Very long distance,

    thousands of feet Immune to noise due to

    differential voltage Implemented in

    hardware or software Ease to implement Widely used in

    industrial automation Higher speeds beyond

    115200 baud

    More suitable forsystem to system

    communications, not somuch for chip to chip orchip to sensor

    Requires transceiverchips and twisted paircable with terminatingresistors which add tosystem cost

  • 8/11/2019 Interfacing mc

    39/57

    RS485 Network Topology: Any station cancommunicate with any other station, but not atthe same time

  • 8/11/2019 Interfacing mc

    40/57

    UART : Universal asynchronous

  • 8/11/2019 Interfacing mc

    41/57

    UART : Universal asynchronousreceiver/transmitter

    UARTs are commonly used in conjunctionwith other communication standards such asEIA RS-232.

    A UART is usually an individual (or part of an)integrated circuit used for serialcommunications over a computer orperipheral device serial port.

    UARTs are now commonly included inmicrocontrollers. A dual UART or DUARTcombines two UARTs into a single chip.

  • 8/11/2019 Interfacing mc

    42/57

    As of now, UARTs are commonly used withRS-232 for embedded systemscommunications.

    It is useful to communicate betweenmicrocontrollers and also with PCs.

    Many chips provide UART functionality insilicon, and low-cost chips exist to convertlogic level signals (such as TTL voltages) toRS-232 level signals (for example, MaximMAX232)

  • 8/11/2019 Interfacing mc

    43/57

    h

  • 8/11/2019 Interfacing mc

    44/57

    Ethernet

    Very high speed (10Mbit to 100 Mbit/s )

    Very long distance,hundreds of feet canbe achieved, morewith hubs andswitches

    Immune to noise Widely used in

    industrial automationdue to noise immunity

    Cost More suitable for system

    to systemcommunications, not somuch for chip tochip/sensor

    Requires Ethernet chipset,transformer, jack andspecial cabling that add tosystem cost.

    Complicated to implement High code footprint

  • 8/11/2019 Interfacing mc

    45/57

    P i

  • 8/11/2019 Interfacing mc

    46/57

    Programming

    Hardware interface Software emulation : Bit banging

    Bit b i

  • 8/11/2019 Interfacing mc

    47/57

    Bit banging

    Bit-banging is a technique in embeddedsystems for example to use serialcommunications without the use of dedicated

    hardware such as a UART or shift register,instead using software to emulate theirbehavior

    A software routine handles the UART transmitfunction by alternating a pin on themicrocontroller by given time intervals

    Bit b gi g

  • 8/11/2019 Interfacing mc

    48/57

    Bit banging

    A receiver function is implemented bysampling a pin on the microcontroller by agiven time interval

    With a few extra components, video signals can be output from digital pins

    Although it is not referred to as bit-banging,software-defined radio is an extremeextension of the same idea

  • 8/11/2019 Interfacing mc

    49/57

    Bit banging

  • 8/11/2019 Interfacing mc

    50/57

    Bit banging

    Another problem is that the microcontroller isbusy most of the time looking at samples orsending a sample to the pin, instead of

    performing other tasks Yet another potential problem is that the

    signal produced normally has more jitter orglitches, especially when the microcontrollermoves on to perform other tasks.

    However, if the bit-banging software ishardware interrupt-driven by the signal, this

    may be of minor importance

    More Buses

  • 8/11/2019 Interfacing mc

    51/57

    More Buses

    USB RS232 UART RS-422

    CAN Diff between TWI and I 2C FIREWIRE

  • 8/11/2019 Interfacing mc

    52/57

    CAN

  • 8/11/2019 Interfacing mc

    53/57

    CAN ...

    It can be even more robust against noise iftwisted pair wire is used.

    Although initially created for automotive

    purposes (as a vehicle bus), nowadays it isused in many embedded control applications(e.g., industrial) that may be subject to noise

    The messages it sends are small (8 data

    bytes max) but are protected by a CRC-15(polynomial 0x62CC) that guarantees aHamming bit length of 6 (so up to 5 bits in arow corrupted will be detected by any node on

    CAN

  • 8/11/2019 Interfacing mc

    54/57

    CAN ...

    Bit rates up to 1 Mbit/s are possible atnetworks length below 40 m. Decreasing thebit rate allows longer network distances (e.g.125 kbit/s at 500 m)

    USB

  • 8/11/2019 Interfacing mc

    55/57

    USB

    Universal Serial Bus (USB) is a serial busstandard to interface devices It was originally designed for computers, but

    its popularity has prompted it to also becomecommonplace on video game consoles,PDAs, portable DVD and media players,cellphones; and even devices such astelevisions, home stereo equipment, carstereos and portable memory devices

    The radio spectrum based USBimplementation is known as Wireless USB

    USB : Overview

  • 8/11/2019 Interfacing mc

    56/57

    USB : Overview

    USB was devised as a major component inthe transition towards a legacy-free PC

    The intention was to let go of all older serial

    and parallel ports on personal computerssince these were not properly standardizedand required a multitude of device drivers tobe developed and maintained

    A USB system has an asymmetric design,consisting of a host controller and multipledaisy-chained devices

    USB : Overview

  • 8/11/2019 Interfacing mc

    57/57

    USB : Overview

    Additional USB hubs may be included in thechain, allowing branching into a tree structure

    No more than 127 devices, including the bus

    devices, may be connected to a single hostcontroller Modern computers often have several host

    controllers, allowing a very large number ofUSB devices to be connected

    USB cables do not need to be terminated