Inter-Integrated Circuit(I²C)Bus

Embed Size (px)

Citation preview

  • 7/30/2019 Inter-Integrated Circuit(IC)Bus

    1/31

    Inter-Integrated Circuit(IC)Bus

  • 7/30/2019 Inter-Integrated Circuit(IC)Bus

    2/31

    Covered Topics

    Overview of I2C

    Using I2C on the PICmicro Microcontroller

    Example: A code walk-though for connecting aEEPROM to a PIC16 Microcontroller

  • 7/30/2019 Inter-Integrated Circuit(IC)Bus

    3/31

    Overview of I2C

    Used for moving data simply and quickly

    from one device to another

    Serial Interface Synchronous

    Bidirectional

  • 7/30/2019 Inter-Integrated Circuit(IC)Bus

    4/31

    Overview of I2C

    I2C is a Synchronous protocol

    The data is clocked along the clock signa(SCL)

    The clock signal controls when data is changedand when it should be read

    I2C is a Bidirectional protocol

    Data is sent either direction on the serial dataline (SDA) by the master or slave.

  • 7/30/2019 Inter-Integrated Circuit(IC)Bus

    5/31

    Overview of I2C

    I2C is a Master-Slave protocol

    The Master device controls the clock (SCL)

    The slave devices may hold the clock low toprevent data transfer

    No data is transferred unless a clock signal is

    present All slaves are controlled by the master clock

  • 7/30/2019 Inter-Integrated Circuit(IC)Bus

    6/31

    Overview of I2C Signals

    I2C is a Serial Interface of only two signals:

    SDA Serial DAta

    This line transfers data to or from the master.

    SCL Serial CLock

    This controls when data is sent and when it isread. The master controls SCK.

  • 7/30/2019 Inter-Integrated Circuit(IC)Bus

    7/31

    I2C Supporting Speeds

    Operates up to 100 kbit/s in the Standard-

    mode, up to 400 kbit/s in the Fast-mode, and

    up to 3.4 Mbit/s in the High-speed mode

  • 7/30/2019 Inter-Integrated Circuit(IC)Bus

    8/31

    I2C- Signals

  • 7/30/2019 Inter-Integrated Circuit(IC)Bus

    9/31

    I2C- Pull up Resistor

  • 7/30/2019 Inter-Integrated Circuit(IC)Bus

    10/31

    I2C- Elements

    Building Blocks of I2C

    S= Start P= Stop R= Restart A= Ack

    sS P R Data A

  • 7/30/2019 Inter-Integrated Circuit(IC)Bus

    11/31

    I2C Elements Start Condition

  • 7/30/2019 Inter-Integrated Circuit(IC)Bus

    12/31

    I2C Elements Stop Condition

  • 7/30/2019 Inter-Integrated Circuit(IC)Bus

    13/31

    I2C Elements -Restart Condition

  • 7/30/2019 Inter-Integrated Circuit(IC)Bus

    14/31

    I2C Elements- Data

  • 7/30/2019 Inter-Integrated Circuit(IC)Bus

    15/31

    I2C Elements- Data

  • 7/30/2019 Inter-Integrated Circuit(IC)Bus

    16/31

    I2C Elements- ACK

  • 7/30/2019 Inter-Integrated Circuit(IC)Bus

    17/31

    I2C Elements- Nack

  • 7/30/2019 Inter-Integrated Circuit(IC)Bus

    18/31

    I2C Addressing

  • 7/30/2019 Inter-Integrated Circuit(IC)Bus

    19/31

    I2C Interfacing

  • 7/30/2019 Inter-Integrated Circuit(IC)Bus

    20/31

    I2C Arbitration

    If two or more masters try to put informationto the bus, the first to produce a one when

    the other produces a zero will lose the

    arbitration. Arbitration can continue for manybits. Its first stage is comparison of the

    address If the masters are each trying to

    address the same device arbitration continues

    with comparison of the data. Because address

    and data information on the I2C-bus is used

    for arbitration, no information is lost during

    this process.

  • 7/30/2019 Inter-Integrated Circuit(IC)Bus

    21/31

    Writing to a I2C EEPROM

  • 7/30/2019 Inter-Integrated Circuit(IC)Bus

    22/31

    Reading from an I2C EEPROM

  • 7/30/2019 Inter-Integrated Circuit(IC)Bus

    23/31

    Writing to a Larger EEPROM

  • 7/30/2019 Inter-Integrated Circuit(IC)Bus

    24/31

    I2C in the PIC micro MCU

    Registers control the function I2C in the PIC

    micro microcontroller

    The values to be placed in the registers will

    often depend on the application

  • 7/30/2019 Inter-Integrated Circuit(IC)Bus

    25/31

    SSPCON Register

    SSPCON Register:

    WCOL Write Collision

    SSPOV Overflow SSPEN Enable

    SSPM3:SSPM0 (4 bits) Function Control

    CKP is also in SSPCON but is not used for

    master mode I2C.

  • 7/30/2019 Inter-Integrated Circuit(IC)Bus

    26/31

    SSPCON2 Register

    GCEN General Call Enable

    ACKSTAT ACK Bit Status

    ACKDT ACK Transmit Data

    ACKEN ACK Transmit Enable

    RCEN Receive Enable

    PEN Stop Condition Enable

    RSEN Restart Condition Enable

    SEN Start Condition Enable

  • 7/30/2019 Inter-Integrated Circuit(IC)Bus

    27/31

    SSPSTAT Register

    SMP Slew Rate Control

    CKE Signal Level Control

    BF Buffer full

  • 7/30/2019 Inter-Integrated Circuit(IC)Bus

    28/31

    SSPADD Register

    The SSPADD register controls the speed of

    the I2C bus transmissions. It controls the baud

    rate generator.

  • 7/30/2019 Inter-Integrated Circuit(IC)Bus

    29/31

    I2C -- Code Example -Write

  • 7/30/2019 Inter-Integrated Circuit(IC)Bus

    30/31

    I2C -- Code Example - Read

  • 7/30/2019 Inter-Integrated Circuit(IC)Bus

    31/31

    Reference

    Application NotesAN734, AN735 and AN578

    from Microchip