Comparision.docx

download Comparision.docx

of 12

Transcript of Comparision.docx

  • 8/10/2019 Comparision.docx

    1/12

    Major Difference Between SPI and I2C is: SPI is full Duplex(SPI can be full/half duplex,

    depending on the hardware, 3 or 4 wire) and I2C is half duplex communication....we cannt

    send and receive data at a time in I2c..but it possible in SPI ....SPI much faster Than I2C.......

    Main topic to discuss the difference is

    1) speed is difference

    in case of i2c is 100/400kbps in 7 bit mode max 400kbps (But High speed I2C communication

    protocols allow speeds upto 3.4Mbps!!)

    in case of spi speed is upto 1mbps (the higher speed of SPI is due to fact that unlike I2C, SPI

    interfaces to a slave device using a sperate pin called the slave select + no concept of

    acknowledgements which means increased Band width..)

    2)Connection wise: i2c require less pin then spi (SPI 3wire: 3 IOs, SPI 4 wire: 4 IOs, I2C: 2 IOs)

    as spi require slave select for individual device...

    3)it is better to use i2c in case of if u want to connect more device to connect. (slave

    addressing advantageous over SPI slave select individual pins for individual slaves)

    4)bus arbitration is possible in case of i2c... not in case of spi... (SPI does not require it, since

    only 1 slave is controlled by the master at any given point)

    6)noise sensitivity of i2c is high... there is chance to corrupt the r/w bit... then whole data is

    corrputed... but in case of spi.. chance is very less as whole word is trasmitted... However, I

    must say that I2C is more reliable, since the protocol supports slave feedback machanism

    (ACK) to detect whether was received correctly or corrupt.

    8) it is easy to implement the spi...while i2c is little bit complex... (over heads

    Re: In protocols (I2c,SPI,CAN) which one is best?

    CAN is the best protocol.

    Re: In protocols (I2c,SPI,CAN) which one is best?

  • 8/10/2019 Comparision.docx

    2/12

    we can separate them based on Clock in the following way.

    1) I2C & SPI are Synchronous Interfaces & used on PCB2) CAN is Asyncronus Interface & uses wires for long

    distence communications.

    Diff B/W I2C & SPI:

    1) a)I2C is invented by Philips

    b)Invented by Mototola

    2) a) Used to interface with Audio/Video Devices as the

    philips is expertise.b) Access High Data trnsmission deives like EEPROMS

    3) a) I2C Supports Speed is :100Kbps(Standard)

    :400Kbps(Fast)

    :3.4Mbps(High Speed)

    b) SPI Supports : 3Mbps to 10Mbps

    4) a) I2C is multi-master, Address based Communication

    b) SPI is Master Slave, With Slave select(SS) based

    Communication

    5) a) I2C needs 2 pins

    b) SPI needs 3+n pins (n is no.of devices)

    6) a) I2C supports 127 devices

    b) limited by avilable Chip slects

    Coming To CAN:

    invented by Robert Bosh

    Sudheer has given good explaination,just to add on it :-

    1)I2C is half duplex as there are only two lines(SCL and

    SDA).

    2)SPI is Full Duplex as between a Master and a dedicated

    slave as selected by slave_select signal; there are 4 lines

    (Spi_clk,Spi_datain,Spi_dataout and slave_select).So,at any

  • 8/10/2019 Comparision.docx

    3/12

    given time data can be sent and received by the master on

    two seperate lines.

    I2C Questions

    Question: What is the maximum distance of the I2C bus?

    This depends on the load of the bus and the speed you run at. In typical applications, the length is a

    few meters (9-12ft). The maximum capacitive load has been specified (see also the electrical Spec's

    in the I2C FAQ). Another thing to be taken into account is the amount of noise picked up by long

    cabling. This noise can disturb the signal transmitted over the bus so badly that it becomes

    unreadable.

    The length can be increased significantly by running at a lower clock frequency. One particular

    application - clocked at about 500Hz - had a bus length of about 100m (300ft). If you are careful in

    routing your PCB's and use proper cabling (twisted pair and/or shielded cable), you can also gain

    some length.

    If you need to go far at high speed, you can use an active current source instead of a simple pull-up

    resistor. Philips has a standalone product for this purpose.Using a charge pump also reduces "ghost

    signals" caused by reflections at the end of the bus lines.

    Question: I'd like to extend the I2C bus. Is there something like a repeater for

    I2C?

    Yes indeed this exists. Philips manufactures a special chip to buffer the bi-directional lines of the I2C

    bus. Typically, this is a current amplifier. It forces current into the wiring (a couple of mA). That way

    you can overcome the capacitance of long wiring.

    However, you will need this component on both sides of the line. The charge pump in this devices can

    deliver currents up to 30mA which is way too much for a normal I2C chip to handle. With these buffers

    you can handle loads up to 2nF. The charge amplifier 'transforms' this load down to a 200pF load

    which is still acceptable by I2C components.

    Question: Are there stand-alone I2C controllers available?

    Yes indeed. There is a special chip to do the I2C interfacing. The PCD8584 or PCF8584 incorporate a

    complete I2C interface. These chips are designed in such way that they can interface to almost any

    microcontroller around.

    Question: Can I abort an ongoing I2C bus transmission?

    http://photos1.blogger.com/blogger/4922/868/1600/fig1.gif
  • 8/10/2019 Comparision.docx

    4/12

    Is it okay to abort an on-going transmission any time.

    According to the specification, this should work. It depends on the layout of the component. A real I2C

    compatible IC will be able to handle this. It might make sense to test this before you use it.

    Usually, when a START or STOP condition is detected, the internal logic of the chip is forced into a

    certain state. Internally, the logic that detects START and STOP is different from the logic that does

    all other processing. The START together with the address register is to be considered as a functional

    unit inside the chip.

    When a START is detected, all internal operations are cancelled and the chip will compare the

    incoming data with its own address.

    When a STOP is detected, ALL chips on the bus will reset their internal logic to IDLE mode except for

    the START detector (this is also used to cut power consumption). Therefore, when a start condition isissued on the bus, the START detector will 'wake-up' the rest of the internal logic.

    Question: Do I need to generate an ACK in read mode on the last byte? My

    chip starts sending data and occupies the bus...

    This is a somewhat puzzling question. Indeed this is a bit strange. Usually, if you have read the last

    byte in a chip and generate an ACK, the chip should do nothing anymore, so the bus should be clear

    for you to create a STOP condition. Apparently, there are some chips that start transmitting data

    again. One such chip is the PCF 8574 I/O expander.

    Though not always desirable, this feature can come in handy. If you need to sample incoming data

    fast, then you just continue reading from the chip. This prevents that you lose 'arbitration' of the bus in

    a multi-master environment.

    It also speeds things up. You don't have to address the chip over and over again so you save the time

    for START, Address, ACK and STOP stage for every next byte read. This can lead to a more than

    doubled transfer rate.

    Question: Why does the SCL line have to be bi-directional?

    The clock line needs to be bi-directional when using a MULTI-MASTER protocol and when using the

    synchronization protocol.

    When you are using only one Master then this is not required since the clock will always be generated

    by this device. If you run Multi-master then this changes. One master must be able to receive data

    from another master. At that time it must be able to receive clock information via the clock line also.

    Question: How can I monitor the I2C bus?

    There are a few commercial I2C monitor / debuggers around that can do this. Information on these

    devices can be foundhere.

    http://www.esacademy.com/faq/i2c/general/i2cdebug.htmhttp://www.esacademy.com/faq/i2c/general/i2cdebug.htmhttp://www.esacademy.com/faq/i2c/general/i2cdebug.htmhttp://www.esacademy.com/faq/i2c/general/i2cdebug.htm
  • 8/10/2019 Comparision.docx

    5/12

    There is another possibility to do this: By using the stand-alone I2C controller PCF8584 from Philips.

    This chip has a certain mode in which it does not take part in the real I2C action but only records what

    is going on. It listens to all addresses, but does not generate any acknowledge.Using some software

    routines and a MCU you could build a universal I2C data logger.

    Question: How can I test / debug the I2C bus?

    There is no general way to debug an I2C bus. However, a few guidelines might help to get it running.

    First thing is to check the levels on the bus. You should see a clear signal that has a low level that is

    lower then 0.8 volt and a high level which is at least 3.5 volts.

    If the high level is not high enough or does not rise fast enough then you can try to lower the value of

    the pull up resistor. You must take care however not to surpass the maximum allowable current in the

    I2C driver stage. The minimum allowable resistor for a 5 volt driven I2C bus is 5 V / 3mA = 1600Ohms. A typical value of 4700 ohm should work fine.

    Make sure the bus is not 'stuck' to '0'. This could be the result of a bad power supply (chips go into

    latch up during power-on) or a bad chip.

    There are a few commercial I2C monitor / debuggers around. Information on these devices can be

    foundhere.

    Question: Which microcontrollers do have an on-chip I2C interface?

    A LOT of MCU's have a real I2C interface implemented in hardware, but this should not restrict the

    use of the I2C bus on other MCU's. ANY MCU can be made to talk to I2C using some small software

    routines.

    There are microcontrollers with on-chip I2C modules as well as stand-alone I2C bus peripherals.

    To list all the devices here would be impossible.A good overview can be found here:

    http://www.embeddedlinks.com/chipdir(search for keyword I2C)

    Question: What bus speeds are available with I2C?

    The bus speed for I2C was increased over the years. The following modes are available:

    Standard mode, with a bit rate up to 100kbit/s

    Fast-mode,with a bit rate up to 400 kbit/s

    High-speed mode(Hs-mode), with a bit rate up to3.4 Mbit/s

    http://www.esacademy.com/faq/i2c/general/i2cdebug.htmhttp://www.esacademy.com/faq/i2c/general/i2cdebug.htmhttp://www.esacademy.com/faq/i2c/general/i2cdebug.htmhttp://www.embeddedlinks.com/chipdirhttp://www.embeddedlinks.com/chipdirhttp://www.esacademy.com/faq/i2c/general/i2cfastm.htmhttp://www.esacademy.com/faq/i2c/general/i2cfastm.htmhttp://www.esacademy.com/faq/i2c/general/i2chighspeedm.htmhttp://www.esacademy.com/faq/i2c/general/i2chighspeedm.htmhttp://www.esacademy.com/faq/i2c/general/i2chighspeedm.htmhttp://www.esacademy.com/faq/i2c/general/i2cfastm.htmhttp://www.embeddedlinks.com/chipdirhttp://www.esacademy.com/faq/i2c/general/i2cdebug.htm
  • 8/10/2019 Comparision.docx

    6/12

    I2C or SPI Serial Communication,

    which one to go with?

    I2C or SPI communication this is the question! Serial Peripheral Interface

    Bus (SPI) was established by Motorola and Inter Integrated Circuit (I2C)

    was invented by Philips. So the main protocols to consider are: SPI protocol

    and I2C protocol.

    SPI and I2C Serial Communication

    Before adding serial communication to your design, lets say adding a serial

    eeprom, you should have an understanding of the different types of serial

    communication that you can use. There are two main protocols to consider,

    SPI protocol and I2C protocol.

    Both systems have their unique advantages and disadvantages which make

    them more or less suitable for a given application.

    Differences between SPIand I2C:

    SPI supports full duplex communication with higher throughput than I2C.

    It is not limited to 8-bit words so you can send any message sizes with

    arbitrary content and purpose. The SPI interface does not require pull-up

    resistors, which translates to lower power consumption. However, I2C is

    simpler by having fewer lines which means fewer pins are required to

    interface to an IC. When communicating with more than one slave, I2C has

    the advantage of in-band addressing as opposed to have a chip select line

  • 8/10/2019 Comparision.docx

    7/12

    for each slave. I2C also supports slave acknowledgment which means that

    you can be absolutely sure that youre actually communicating with

    something. With SPI, a master can be sending data to nothing at all and

    have no way to know that. In general SPI is better suited for applicationsthat deal with longer data streams and not just words like address

    locations. Mostly longer data streams exist in applications where youre

    working with a digital signal processor or analog-to digital converter. For

    example, SPI would be perfect for playing back some audio stored in an

    eeprom and played through a digital to analog converter DAC. Moreover,

    since SPI can support significantly higher data rates comparing to I2C,

    mostly due to its duplex capability, it is far more suited for higher speed

    applications reaching tens of megahertz. And since there is no device

    addressing involved in SPI the protocol is a lot harder to use in multiple

    slave systems. This means when dealing with more than one node,

    generally I2C is the way to go.

    SPI interface:

    As you can see in the picture, SPI has 4 lines. The SCLK line is the clock

    line, the clock is generated by the master and drives the communication in

    both directions, and this line is an input to all slaves. The MOSI line is the

    master data output, slave data input, and it caries data from the master to

    the slave. The MISO line is the master data input, slave data output, and it

    carries data from the slave to the master. Finally the SS or sometimes

    known as the CS line is the slave select or chip select line, it is toggled to

    select a slave to be communicated with. Usually the transfer sequence

    consist of driving the SS line low with a general I/O pin, sending X number

  • 8/10/2019 Comparision.docx

    8/12

    of clock signals with the proper polarity and phase, driving the SS line high

    to end the communication. As the clock signals are generated, data is

    transferred in both directions, therefore in a transmit only system the

    received bytes have to be discarded and in a receive only system a dummybyte has to be transmitted. Care has to be taken not to toggle the SS during

    the communication since this will introduce errors. The clock polarity and

    clock phase controls on which edge of the clock signal the data is received

    and sent. This has to be set up to match between the master and the slave.

    There is also a 3-Wire version of SPI however it only supports half duplex

    communication. This set up uses a SISO line, this single bidirectional data

    line carries data in and out of the slave. This mode has a tendency of not

    being supported by microcontrollers however it is easily implemented with

    bit banging in software.

    I2C:

    I2C consists of two bidirectional lines that are pulled up to Vdd. The SDA

    line is the serial data line and SCL is the serial clock line. The standard I2Cmodules support a 7-bit slave address and can support up to 112/128 nodes,

    some extended I2C modules can support 10-bit slave addressing however

    all the modules are limited to 400pF bus capacitance. Standard speeds are

    10kbit/s Low-speed mode and 100kbit/s Standard mode. The extended

    versions support 400kbit/s Fast mode, 1Mbit/s Fast mode plus, and

    3.4Mbit/s High-speed mode. The three types of messages that are defined

    by the I2C protocol are a single message where the master writes to a slave,

  • 8/10/2019 Comparision.docx

    9/12

    a single message where the master reads from a slave, and a combined

    message where a master issues at least two reads and/or writes to one or

    more slaves. The sequence of the communication begins with the master

    sending a start bit followed by the 7 or 10-bit slave address and finally a bitthat selects if the operation is a write(0) or a read(1). At this point, if the

    slave address exists on the bus the slave will send an acknowledgment bit to

    the master. The data is than transferred on the SDA line in the direction

    that was specified by the master. An acknowledgment bit is sent at the end

    of each transfered byte by the receiving end of the transmission. The only

    exception is that when the master is in receive mode and the slave in

    transmit mode the master will not send an acknowledge bit after the very

    last bit received. Lastly the communication is stopped with the master

    sending a stop command. The start and stop commands are simply a

    transition from high to low (Start) on the SDA line with SCL high or low to

    high (Stop) on the SDA line with SCL high. Transitions for the data bits are

    always performed while SCL is low; the high state is only for the start/stop

    commands.Hopefully this gives you a better understanding of these two protocols, and

    their differences. It should be a lot simpler to select one over the other for a

    given application. But life is not always that easy, you still have to consider

    if other types of communications are not more suitable for your application,

    you could even be better off not using a serial protocol at all but to go with a

    parallel type communication.

    protocol

    John Artiuch's blog

    Loginto post comments

    I2C SPI Communication

    Submitted by frabs on Fri, 2008-10-17 14:53.

    http://dev.emcelettronica.com/category/tags/spi-protocolhttp://dev.emcelettronica.com/category/tags/spi-protocolhttp://dev.emcelettronica.com/john-artiuchhttp://dev.emcelettronica.com/john-artiuchhttp://dev.emcelettronica.com/user/login?destination=node%2F51997%23comment-formhttp://dev.emcelettronica.com/user/login?destination=node%2F51997%23comment-formhttp://dev.emcelettronica.com/i2c-or-spi-serial-communication-which-one-to-go#comment-602http://dev.emcelettronica.com/i2c-or-spi-serial-communication-which-one-to-go#comment-602http://dev.emcelettronica.com/i2c-or-spi-serial-communication-which-one-to-go#comment-602http://dev.emcelettronica.com/user/login?destination=node%2F51997%23comment-formhttp://dev.emcelettronica.com/john-artiuchhttp://dev.emcelettronica.com/category/tags/spi-protocol
  • 8/10/2019 Comparision.docx

    10/12

    I think sometimes a few pictures are worth hundreds of words:

    Following is a diagram of I2C protocol with the compliments of NXP (formerly known as Philips

    Semiconductors).

    Next diagram shows an example of SPI Protocol taken from an Intersil document.

    Loginto post comments

    I2C and SPI

    I2C (Inter Integrated Circuit Communications, pronounced I squared C) and SPI (or Serial-

    Peripheral interface) are protocols that can link a microcomputer to other micros or integrated

    circuits.

    Both protocols are widely used in hobby electronics and robotics projects.

    I2C was originally developed by Philips (now nxp) and is used in all sorts of equipment

    including virtually every tv, monitor and computer motherboard. I2C is a flexible protocol

    but has fairly limited bandwidth.

    SPI was originally developed by Motorola (now Freescale). Its simple and fast but has some

    limitations compared to I2C.

    Most modern micro-controllers have hardware support for both protocols. Examples include

    the Arduino, mbed, BeagleBone, BeagleBoard and Raspberry Pi.

    Lets look at the two protocols in a little more detail.

    http://dev.emcelettronica.com/user/login?destination=node%2F51997%23comment-formhttp://dev.emcelettronica.com/user/login?destination=node%2F51997%23comment-formhttp://dev.emcelettronica.com/user/login?destination=node%2F51997%23comment-form
  • 8/10/2019 Comparision.docx

    11/12

    I2C

    I2C can be used to connect up to 127 nodes via a bus that only requires two data wires,

    known as SDA and SCL.

    Since the devices need a common voltage reference (Ground) and a power line (referred to as

    Vcc or Vdd) the full bus has four wires, two for data and two for power. Sometimes

    additional lines are added, for example to support interrupts when the state of I2C devices

    change.

    In theory the I2C bus can support multiple masters, but most micro-controllers cant. A

    master is usually a microcontroller, although it doesnt have to be. Slaves can be ICs or

    microcontrollers.

    In the diagram above a RasPi is a master and there are several slaves: a Digital-to-Analog

    converter (DAC), an Analog-to-Digital converter (DC), and an Arduino.

    I2C can be used to control a very wide range of devices. Common examples include

    Digital-to-analogue converters (DACs)

    Analogue-to-digital converters (ADCs)

    LCD displays

    OLED Screens

    Keyboards

    Motor drivers

    LED drivers

    Memory chips and cards (EEPROM, RAM, FERAM, Flash)

    bus expanders/extenders (chips with 8 or 16 I/O pins controllable via I2C)

    other microcontrollers

    When the master wishes to communicate with a slave it sends a series of pulses down the

    SDA and SCL lines. The data that is sent includes an address that identifies the slave with

    which the master needs to interact. Addresses take 7 bits out of a data byte; the remaining bit

    specifies whether the master wishes to read (get data from a slave) or write (send data to a

    slave).

    Some devices have an address that is entirely fixed by the manufacturer; others can be

    configured to take one of a range of possible addresses. When a micro-controller is used as a

    slave it is normally possible to configure its address by software, and for that address to take

    on any of the 127 possible values.

    http://quick2wire.com/wp-content/uploads/2012/05/image00.png
  • 8/10/2019 Comparision.docx

    12/12

    The address byte may be followed by one or more byes of data, which may go from master to

    slave or from slave to master.

    When data is being sent on the SDA line, clock pulses are sent on the SCL line to keep

    master and slave synchronised. Since the data is sent one bit at a time, the data transfer rate is

    one eighth of the clock rate. The original standard specified a standardclock rate of 100KHz,and most I2C chips and micro-controllers can support this. Later updates to the standard

    introduced a fastspeed of 400KHz and a highspeed of 1.7 or 3.4 MHz. The Arduino can

    support standard and fast speeds; the BeagleBoard has three I2C busses, one at each speed;

    the RasPi and BeagleBone can both support standard and fast I2C.

    The fast rate corresponds to a data transfer rate of 50K bytes/sec which is too slow for some

    control applications. One option in that case is to use SPI instead of I2C.

    SPI

    The SPI interface was originally developed by Motorola (now Freescale). SPI is much

    simpler than I2C. Master and slave are linked by three data wires, usually called MISO,

    (Master in, Slave out), MOSI (Master out, Slave in) and M-CLK.

    As the names suggest, the M_CLK line carries clock pulses which provide synchronisation.

    When a transfer is taking place, a bit of data is transferred via MOSI from Master to slave

    and at the same time a bit of data is transferred via MISO from Slave to Master. At the end of

    eight clock pulses an entire byte of data has been transferred in each direction.

    Many SPI-enabled ICs and Microcontrollers can cope with data rates of over 10MHz, so

    transfer is much faster than with I2C. The downside is that SPI normally has no addressingcapability; instead, devices are selected by means of a Chip Select signal which the master

    can use to enable one slave out of several connected to the SPI bus. If more than one slave

    exists, one chip select line is required per device, which can use precious GPIO lines on the

    Master.

    SPI is less well specified than I2C, but the SPI module on the Broadcom chip at the heart of

    the Raspberry Pi is flexible enough to cope with most common SPI devices.