SlideShare a Scribd company logo
The I2
C BUS Interface
Corrado Santoro
ARSLAB - Autonomous and Robotic Systems Laboratory
Dipartimento di Matematica e Informatica - Universit`a di Catania, Italy
santoro@dmi.unict.it
L.A.P. 1 Course
Corrado Santoro The I2C BUS Interface
What is I2
C?
I2
C Bus or IIC Bus is the acronym for Inter-Integrated Circuit Bus.
It is a standard digital communication bus designed to interconnect
integrated circuits belonging to the same board.
It has been introduced by Philips to interconnect integrated circuits in
TV-sets in the ’80s in the transition from discrete transistors to
integrated-circuits.
The bus has been initially used in TV-sets and VCRs, and then widely
adopted in any integrated device which needs data communication.
Corrado Santoro The I2C BUS Interface
I2
C BUS: Phylisophy and Connections
I2
C has a two wires bus which interconnect all devices
Devices in a I2
C network has a role:
Master, is the “head” of the bus and has the responsibility of starting a
communication; only one master can be present in a I2C network and is -
in general - a MCU;
Slave, all the other devices which “respond” to master solicitations.
Corrado Santoro The I2C BUS Interface
I2
C BUS: Phylisophy and Connections
The I2
C wires have the following meaning:
SDA: Serial DAta, bidirectional; here data bits flow serially (one bit at time)
SCL: Serial CLock, undirectional from master to slaves; it holds the timing
of the transmission
Therefore I2
C is a synchronous interface which (according to
standards) can reach the max speed of 400 Kbps
Corrado Santoro The I2C BUS Interface
I2
C BUS: Electrical Consideration
I2
C wires use a pull-up resistor, outputs of the devices are open-drain
This is required to avoid electrical collisions:
When output MOS are off, the line is at VCC through the pull-up resistor,
so it is at logic 1
If one or more output MOS are on, the line is connected at ground
(through the MOS), so it is at logic 0
Therefore ...
Sending 0 implies to turn-on the output MOS
Sending 1 implies to turn-off the output MOS
Software handles 1 and 0, electrical translation is performed in hardware.
Corrado Santoro The I2C BUS Interface
I2
C Addressing
Each slave device in I2
C has a well-know address
The standard specifies two types of addresses:
7-bit, widely used
10-bit, used only in some special cases
Each slave device has also a register map
Each register is identified by a 8-bit address and a 8-bit value
Each register is used to:
Configure the device
Send commands to the device
Hold a sensed data
etc.
Each register can be read or written from the master through proper
transaction protocols.
Corrado Santoro The I2C BUS Interface
I2
C: Timing and Bus States
BUS IDLE, both SDA and SCL lines are in 1 state.
START CONDITION (S)
A transition high-to-low in SDA, while SCL is high, is a Start Condition
It is used to start communication on the bus
It is always initiated by the Master
Corrado Santoro The I2C BUS Interface
I2
C: Data Transfer
Data transfer occurs serially MSB-first:
1 The bit value is set on the SDA line
2 A pulse low-to-high-to-low occurs on the SCL line
3 The next bit is sent ...
After transmission of all the 8 bits, an acknowledge (ACK) is expected:
1 The master generates a 9th clock pulse
2 The receiving device holds the SDA line low to signal that it has
understood the byte sent
Corrado Santoro The I2C BUS Interface
I2
C: Stop Condition
When communication is over, a STOP CONDITION (P) is generated:
A transition low-to-high in SDA, while SCL is high, is a start condition
It is used to stop any communication on the bus
It is always made by the Master
After a Stop Condition, the bus goes in the Idle state.
Corrado Santoro The I2C BUS Interface
Sending Data to a Slave Device
First the Master initiates communication with a Start Condition
The Master sends the Write Command, a 8-bit data, composed of:
The 7-bit address of the Slave device
The R/W bit at 0, which means write-to-slave
The addressed Slave acks, by holding SDA line low in the 9th
clock
pulse
If no Slave exists at that address, the SDA line will remain to high, thus
indicating a NACK; this situation is recognised by the Master which
stops communication.
Corrado Santoro The I2C BUS Interface
Sending Data to a Slave Device
After the address, the Master sends a 8-bit data which has the meaning
of register number
The addressed Slave acks data, by holding SDA line low in the 9th
clock pulse
Then the Master sends a 8-bit data which has the meaning of register
value
The addressed Slave acks data, by holding SDA line low in the 9th
clock pulse
The Master closes the transmission by sending a Stop Condition
Corrado Santoro The I2C BUS Interface
Receiving Data from a Slave Device
First the Master initiates communication with a Start Condition
The Master sends the Write Command, a 8-bit data, composed of:
The 7-bit address of the Slave device
The R/W bit at 0, which means write-to-slave
The addressed Slave acks, by holding SDA line low in the 9th
clock
pulse
Corrado Santoro The I2C BUS Interface
Receiving Data from a Slave Device
After the address, the Master sends a 8-bit data which has the meaning
of register number
The addressed Slave acks data, by holding SDA line low in the 9th
clock pulse
The Master sends a new Start Condition.
The Master sends the Read Command, a 8-bit data, composed of:
The 7-bit address of the Slave device
The R/W bit at 1, which means read-from-slave
The addressed Slave acks, by holding SDA line low in the 9th
clock
pulse
Corrado Santoro The I2C BUS Interface
Receiving Data from a Slave Device
Slave device is now ready to send bytes
The Slave sends a 8 bit data value
The Master acks, by holding SDA line low in the 9th
clock pulse
The Slave sends the next 8 bit data value (next register value)
The Master acks, by holding SDA line low in the 9th
clock pulse
When the Master is no more interested to data, it closes the
communication by sending a NACK (holding SDA line high in the 9th
clock pulse) and then a Stop Condition.
Corrado Santoro The I2C BUS Interface
I2
C and the PIC18F25K22
The PIC18F25K22 has a peripheral performing I2
C communication
It is called MSSP, Master Synchronous Serial Port and handles:
SPI communication
I2C communication
It can be programmed to work either in Master or Slave mode
It has some configuration registers:
SSPxCON1, sets-up the working mode of the peripheral, i.e. SPI/I2C,
Master/Slave;
SSPxCON2, in master mode, it generates events like Start Cond, Stop
Cond, Ack, NAck;
SSPxCON3, specifies the events which can trigger the interrupt;
SSPxSTAT, indicates the occurrence of events (start, stop, data received,
data sent, ack, etc.);
Baud Rate Register, to set the communication speed (master mode);
Data Register, holds the data read/to write.
Corrado Santoro The I2C BUS Interface
SSP Control Register
ACKSTAT, acknowledge status bit
ACKDT, acknowledge data bit
ACKEN, sends the acknowledge data bit
RCEN, enables the receiver
PEN, initiates a stop condition
RSEN, initiates a repeated start condition
SEN, initiates a start condition
The xxEN bits are automatically cleared by hardware when the operation is
completed
Corrado Santoro The I2C BUS Interface
SSP Status Register
D/A, indicates data or address
P, indicates a detected stop condition
S, indicates a detected start condition
BF, indicates a buffer full condition
During reception: 1 = reception complete
During transmission: 1 = transmission in progress
Corrado Santoro The I2C BUS Interface
Writing a Register through I2
C
✞
int register_write(int dev_address, int reg_number, int reg_value)
{
SSP1CON2bits.SEN = 1; // send a START
while (SSP1CON2bits.SEN == 1) {} // wait for completion
PIR1bits.SSP1IF = 0;
SSP1BUF = dev_address << 1; // shift left in order to include the ‘‘0’’ write bit
while (PIR1bits.SSP1IF == 0) {} // wait for transmission and ack reception
if (SSP1CON2bits.ACKSTAT == 1) { // a NACK is recevied, abort transmission
SSP1CON2bits.PEN = 1; // send a STOP
return 0;
}
PIR1bits.SSP1IF = 0;
SSP1BUF = reg_number;
while (PIR1bits.SSP1IF == 0) {} // wait for transmission and ack reception
if (SSP1CON2bits.ACKSTAT == 1) { // a NACK is recevied, abort transmission
SSP1CON2bits.PEN = 1; // send a STOP
return 0;
}
PIR1bits.SSP1IF = 0;
SSP1BUF = reg_value;
while (PIR1bits.SSP1IF == 0) {} // wait for transmission and ack reception
SSP1CON2bits.PEN = 1; // send a STOP
while (SSP1CON2bits.PEN == 1) {} // wait for STOP completion
return 1;
}
✡✝ ✆
Corrado Santoro The I2C BUS Interface
The I2
C BUS Interface
Corrado Santoro
ARSLAB - Autonomous and Robotic Systems Laboratory
Dipartimento di Matematica e Informatica - Universit`a di Catania, Italy
santoro@dmi.unict.it
L.A.P. 1 Course
Corrado Santoro The I2C BUS Interface

More Related Content

What's hot (20)

I2 c protocol
I2 c protocolI2 c protocol
I2 c protocol
 
I2C Protocol
I2C ProtocolI2C Protocol
I2C Protocol
 
I2C And SPI Part-23
I2C And  SPI Part-23I2C And  SPI Part-23
I2C And SPI Part-23
 
I2C BUS PROTOCOL
I2C BUS PROTOCOLI2C BUS PROTOCOL
I2C BUS PROTOCOL
 
SPI Bus Protocol
SPI Bus ProtocolSPI Bus Protocol
SPI Bus Protocol
 
I2C Bus (Inter-Integrated Circuit)
I2C Bus (Inter-Integrated Circuit)I2C Bus (Inter-Integrated Circuit)
I2C Bus (Inter-Integrated Circuit)
 
I2C-Bus Design and Verification Specs
I2C-Bus Design and Verification SpecsI2C-Bus Design and Verification Specs
I2C-Bus Design and Verification Specs
 
Ambha axi
Ambha axiAmbha axi
Ambha axi
 
Serial Peripheral Interface(SPI)
Serial Peripheral Interface(SPI)Serial Peripheral Interface(SPI)
Serial Peripheral Interface(SPI)
 
UART
UARTUART
UART
 
I2C Protocol
I2C ProtocolI2C Protocol
I2C Protocol
 
SPI Protocol
SPI ProtocolSPI Protocol
SPI Protocol
 
AXI Protocol.pptx
AXI Protocol.pptxAXI Protocol.pptx
AXI Protocol.pptx
 
I2 c bus
I2 c busI2 c bus
I2 c bus
 
Introduction about APB Protocol
Introduction about APB ProtocolIntroduction about APB Protocol
Introduction about APB Protocol
 
Serial Peripheral Interface
Serial Peripheral InterfaceSerial Peripheral Interface
Serial Peripheral Interface
 
Axi
AxiAxi
Axi
 
dual-port RAM (DPRAM)
dual-port RAM (DPRAM)dual-port RAM (DPRAM)
dual-port RAM (DPRAM)
 
Axi
AxiAxi
Axi
 
AMBA 3 APB Protocol
AMBA 3 APB ProtocolAMBA 3 APB Protocol
AMBA 3 APB Protocol
 

Viewers also liked

How does a Quadrotor fly? A journey from physics, mathematics, control system...
How does a Quadrotor fly? A journey from physics, mathematics, control system...How does a Quadrotor fly? A journey from physics, mathematics, control system...
How does a Quadrotor fly? A journey from physics, mathematics, control system...Corrado Santoro
 
Using Timer2 in Microchip MCUs
Using Timer2 in Microchip MCUsUsing Timer2 in Microchip MCUs
Using Timer2 in Microchip MCUsCorrado Santoro
 
Pulse Width Modulation Signal Generation with MCUs
Pulse Width Modulation Signal Generation with MCUsPulse Width Modulation Signal Generation with MCUs
Pulse Width Modulation Signal Generation with MCUsCorrado Santoro
 
I2C BUS
I2C BUSI2C BUS
I2C BUSp_ayal
 
Serial peripheral interface
Serial peripheral interfaceSerial peripheral interface
Serial peripheral interfaceAbhijeet kapse
 
Quadrotor
QuadrotorQuadrotor
Quadrotorchenke2
 
Serial peripheral Interface - Embedded System Protocol
Serial peripheral Interface - Embedded System ProtocolSerial peripheral Interface - Embedded System Protocol
Serial peripheral Interface - Embedded System ProtocolAditya Porwal
 
2009 development and implementation of a control system for a quadrotor uav
2009 development and implementation of a control system for a quadrotor uav2009 development and implementation of a control system for a quadrotor uav
2009 development and implementation of a control system for a quadrotor uavjaeaj
 
Lecture 1: Quadrotor
Lecture 1: QuadrotorLecture 1: Quadrotor
Lecture 1: QuadrotorWong Kiong
 
Spi in arm7(lpc2148)
Spi in arm7(lpc2148)Spi in arm7(lpc2148)
Spi in arm7(lpc2148)Aarav Soni
 
BIG IoT Project Overview
BIG IoT Project OverviewBIG IoT Project Overview
BIG IoT Project OverviewBIG IoT Project
 
Design and Implementation of a Quadrotor Helicopter
Design and Implementation of a Quadrotor HelicopterDesign and Implementation of a Quadrotor Helicopter
Design and Implementation of a Quadrotor HelicopterHicham Berkouk
 

Viewers also liked (19)

How does a Quadrotor fly? A journey from physics, mathematics, control system...
How does a Quadrotor fly? A journey from physics, mathematics, control system...How does a Quadrotor fly? A journey from physics, mathematics, control system...
How does a Quadrotor fly? A journey from physics, mathematics, control system...
 
Quadcopter Technology
Quadcopter TechnologyQuadcopter Technology
Quadcopter Technology
 
Using Timer2 in Microchip MCUs
Using Timer2 in Microchip MCUsUsing Timer2 in Microchip MCUs
Using Timer2 in Microchip MCUs
 
Pulse Width Modulation Signal Generation with MCUs
Pulse Width Modulation Signal Generation with MCUsPulse Width Modulation Signal Generation with MCUs
Pulse Width Modulation Signal Generation with MCUs
 
Using Timer1 and CCP
Using Timer1 and CCPUsing Timer1 and CCP
Using Timer1 and CCP
 
I2C BUS
I2C BUSI2C BUS
I2C BUS
 
Serial peripheral interface
Serial peripheral interfaceSerial peripheral interface
Serial peripheral interface
 
Quadrotor
QuadrotorQuadrotor
Quadrotor
 
Quadrotor
QuadrotorQuadrotor
Quadrotor
 
10067038
1006703810067038
10067038
 
Smart world
Smart worldSmart world
Smart world
 
Serial peripheral Interface - Embedded System Protocol
Serial peripheral Interface - Embedded System ProtocolSerial peripheral Interface - Embedded System Protocol
Serial peripheral Interface - Embedded System Protocol
 
2009 development and implementation of a control system for a quadrotor uav
2009 development and implementation of a control system for a quadrotor uav2009 development and implementation of a control system for a quadrotor uav
2009 development and implementation of a control system for a quadrotor uav
 
Quadcopter
QuadcopterQuadcopter
Quadcopter
 
Lecture 1: Quadrotor
Lecture 1: QuadrotorLecture 1: Quadrotor
Lecture 1: Quadrotor
 
Spi in arm7(lpc2148)
Spi in arm7(lpc2148)Spi in arm7(lpc2148)
Spi in arm7(lpc2148)
 
BIG IoT Project Overview
BIG IoT Project OverviewBIG IoT Project Overview
BIG IoT Project Overview
 
Iot for smart world
Iot for smart worldIot for smart world
Iot for smart world
 
Design and Implementation of a Quadrotor Helicopter
Design and Implementation of a Quadrotor HelicopterDesign and Implementation of a Quadrotor Helicopter
Design and Implementation of a Quadrotor Helicopter
 

Similar to The I2C Interface

Implementation of I2C Master Bus Protocol on FPGA
Implementation of I2C Master Bus Protocol on FPGAImplementation of I2C Master Bus Protocol on FPGA
Implementation of I2C Master Bus Protocol on FPGAIJERA Editor
 
communication interfaces-Embedded real time systems
communication interfaces-Embedded real time systemscommunication interfaces-Embedded real time systems
communication interfaces-Embedded real time systemsRaghunath reddy
 
Part-2: Mastering microcontroller with embedded driver development
Part-2: Mastering microcontroller with embedded driver developmentPart-2: Mastering microcontroller with embedded driver development
Part-2: Mastering microcontroller with embedded driver developmentFastBit Embedded Brain Academy
 
I2c interfacing raspberry pi to arduino
I2c interfacing raspberry pi to arduinoI2c interfacing raspberry pi to arduino
I2c interfacing raspberry pi to arduinoMike Ochtman
 
An Implementation of I2C Slave Interface using Verilog HDL
An Implementation of I2C Slave Interface using Verilog HDLAn Implementation of I2C Slave Interface using Verilog HDL
An Implementation of I2C Slave Interface using Verilog HDLIJMER
 
Internet of things laboratory
Internet of things laboratoryInternet of things laboratory
Internet of things laboratorySoumee Maschatak
 
Peripherals and interfacing
Peripherals  and interfacingPeripherals  and interfacing
Peripherals and interfacingRAMPRAKASHT1
 
UNI T 6- SPI_I2C_Lecture8.pptx
UNI                    T 6- SPI_I2C_Lecture8.pptxUNI                    T 6- SPI_I2C_Lecture8.pptx
UNI T 6- SPI_I2C_Lecture8.pptxnaveen088888
 
Raspberry Pi - Lecture 3 Embedded Communication Protocols
Raspberry Pi - Lecture 3 Embedded Communication ProtocolsRaspberry Pi - Lecture 3 Embedded Communication Protocols
Raspberry Pi - Lecture 3 Embedded Communication ProtocolsMohamed Abdallah
 
I2C protocol and DS1307 RTC interfacing
I2C protocol and DS1307 RTC interfacingI2C protocol and DS1307 RTC interfacing
I2C protocol and DS1307 RTC interfacingBhargav Kakadiya
 
ARDUINO AND ITS PIN CONFIGURATION
 ARDUINO AND ITS PIN  CONFIGURATION ARDUINO AND ITS PIN  CONFIGURATION
ARDUINO AND ITS PIN CONFIGURATIONsoma saikiran
 

Similar to The I2C Interface (20)

Implementation of I2C Master Bus Protocol on FPGA
Implementation of I2C Master Bus Protocol on FPGAImplementation of I2C Master Bus Protocol on FPGA
Implementation of I2C Master Bus Protocol on FPGA
 
I2C PRESENTATION.PPT
I2C PRESENTATION.PPTI2C PRESENTATION.PPT
I2C PRESENTATION.PPT
 
communication interfaces-Embedded real time systems
communication interfaces-Embedded real time systemscommunication interfaces-Embedded real time systems
communication interfaces-Embedded real time systems
 
Part-2: Mastering microcontroller with embedded driver development
Part-2: Mastering microcontroller with embedded driver developmentPart-2: Mastering microcontroller with embedded driver development
Part-2: Mastering microcontroller with embedded driver development
 
I2c interfacing raspberry pi to arduino
I2c interfacing raspberry pi to arduinoI2c interfacing raspberry pi to arduino
I2c interfacing raspberry pi to arduino
 
An Implementation of I2C Slave Interface using Verilog HDL
An Implementation of I2C Slave Interface using Verilog HDLAn Implementation of I2C Slave Interface using Verilog HDL
An Implementation of I2C Slave Interface using Verilog HDL
 
COM_BASIC.pptx
COM_BASIC.pptxCOM_BASIC.pptx
COM_BASIC.pptx
 
Internet of things laboratory
Internet of things laboratoryInternet of things laboratory
Internet of things laboratory
 
Peripherals and interfacing
Peripherals  and interfacingPeripherals  and interfacing
Peripherals and interfacing
 
Assembler4
Assembler4Assembler4
Assembler4
 
UNI T 6- SPI_I2C_Lecture8.pptx
UNI                    T 6- SPI_I2C_Lecture8.pptxUNI                    T 6- SPI_I2C_Lecture8.pptx
UNI T 6- SPI_I2C_Lecture8.pptx
 
Raspberry Pi - Lecture 3 Embedded Communication Protocols
Raspberry Pi - Lecture 3 Embedded Communication ProtocolsRaspberry Pi - Lecture 3 Embedded Communication Protocols
Raspberry Pi - Lecture 3 Embedded Communication Protocols
 
I2 c
I2 cI2 c
I2 c
 
project 3 full report
project 3 full reportproject 3 full report
project 3 full report
 
I2C protocol and DS1307 RTC interfacing
I2C protocol and DS1307 RTC interfacingI2C protocol and DS1307 RTC interfacing
I2C protocol and DS1307 RTC interfacing
 
An hemmanur
An hemmanurAn hemmanur
An hemmanur
 
ARDUINO AND ITS PIN CONFIGURATION
 ARDUINO AND ITS PIN  CONFIGURATION ARDUINO AND ITS PIN  CONFIGURATION
ARDUINO AND ITS PIN CONFIGURATION
 
Arm i2 c eeprom
Arm i2 c eepromArm i2 c eeprom
Arm i2 c eeprom
 
Pin out lpc2129
Pin out lpc2129Pin out lpc2129
Pin out lpc2129
 
Lpc2148 i2c
Lpc2148 i2cLpc2148 i2c
Lpc2148 i2c
 

More from Corrado Santoro

Physical Flying Agents: Ummanned Aerial Vehicles Control, Coordination and Em...
Physical Flying Agents: Ummanned Aerial Vehicles Control, Coordination and Em...Physical Flying Agents: Ummanned Aerial Vehicles Control, Coordination and Em...
Physical Flying Agents: Ummanned Aerial Vehicles Control, Coordination and Em...Corrado Santoro
 
Handling Asynchronous Events in MCUs
Handling Asynchronous Events in MCUsHandling Asynchronous Events in MCUs
Handling Asynchronous Events in MCUsCorrado Santoro
 
Presentation @ Miniscuola WOA 2015
Presentation @ Miniscuola WOA 2015Presentation @ Miniscuola WOA 2015
Presentation @ Miniscuola WOA 2015Corrado Santoro
 
Presentation @ WOA 2015
Presentation @ WOA 2015 Presentation @ WOA 2015
Presentation @ WOA 2015 Corrado Santoro
 
Using Ready-for-PIC and SDR Libraries
Using Ready-for-PIC and SDR LibrariesUsing Ready-for-PIC and SDR Libraries
Using Ready-for-PIC and SDR LibrariesCorrado Santoro
 
Introduction to shell scripting
Introduction to shell scriptingIntroduction to shell scripting
Introduction to shell scriptingCorrado Santoro
 
Analog to digital converter
Analog to digital converterAnalog to digital converter
Analog to digital converterCorrado Santoro
 
Exercises with timers and UART
Exercises with timers and UARTExercises with timers and UART
Exercises with timers and UARTCorrado Santoro
 
Handling Interrupts in Microchip MCUs
Handling Interrupts in Microchip MCUsHandling Interrupts in Microchip MCUs
Handling Interrupts in Microchip MCUsCorrado Santoro
 
Using Timers in PIC18F Microcontrollers
Using Timers in PIC18F MicrocontrollersUsing Timers in PIC18F Microcontrollers
Using Timers in PIC18F MicrocontrollersCorrado Santoro
 
Programming the Digital I/O Interface of a PIC microcontroller
Programming the Digital I/O Interface of a PIC microcontrollerProgramming the Digital I/O Interface of a PIC microcontroller
Programming the Digital I/O Interface of a PIC microcontrollerCorrado Santoro
 
Introduction to microcontrollers
Introduction to microcontrollersIntroduction to microcontrollers
Introduction to microcontrollersCorrado Santoro
 
Integrating Cloud Services in Behaviour Programming for Autonomous Robots
Integrating Cloud Services in Behaviour  Programming for Autonomous RobotsIntegrating Cloud Services in Behaviour  Programming for Autonomous Robots
Integrating Cloud Services in Behaviour Programming for Autonomous RobotsCorrado Santoro
 
Reactive Autonomous System Programming using the PROFETA tool
Reactive Autonomous System Programming using the PROFETA toolReactive Autonomous System Programming using the PROFETA tool
Reactive Autonomous System Programming using the PROFETA toolCorrado Santoro
 

More from Corrado Santoro (18)

Physical Flying Agents: Ummanned Aerial Vehicles Control, Coordination and Em...
Physical Flying Agents: Ummanned Aerial Vehicles Control, Coordination and Em...Physical Flying Agents: Ummanned Aerial Vehicles Control, Coordination and Em...
Physical Flying Agents: Ummanned Aerial Vehicles Control, Coordination and Em...
 
Handling Asynchronous Events in MCUs
Handling Asynchronous Events in MCUsHandling Asynchronous Events in MCUs
Handling Asynchronous Events in MCUs
 
Presentation @ Miniscuola WOA 2015
Presentation @ Miniscuola WOA 2015Presentation @ Miniscuola WOA 2015
Presentation @ Miniscuola WOA 2015
 
Presentation @ WOA 2015
Presentation @ WOA 2015 Presentation @ WOA 2015
Presentation @ WOA 2015
 
Soc
SocSoc
Soc
 
Using Ready-for-PIC and SDR Libraries
Using Ready-for-PIC and SDR LibrariesUsing Ready-for-PIC and SDR Libraries
Using Ready-for-PIC and SDR Libraries
 
Introduction to Erlang
Introduction to ErlangIntroduction to Erlang
Introduction to Erlang
 
Introduction to shell scripting
Introduction to shell scriptingIntroduction to shell scripting
Introduction to shell scripting
 
Pillole di C++
Pillole di C++Pillole di C++
Pillole di C++
 
Analog to digital converter
Analog to digital converterAnalog to digital converter
Analog to digital converter
 
Exercises with timers and UART
Exercises with timers and UARTExercises with timers and UART
Exercises with timers and UART
 
UART MCU
UART MCUUART MCU
UART MCU
 
Handling Interrupts in Microchip MCUs
Handling Interrupts in Microchip MCUsHandling Interrupts in Microchip MCUs
Handling Interrupts in Microchip MCUs
 
Using Timers in PIC18F Microcontrollers
Using Timers in PIC18F MicrocontrollersUsing Timers in PIC18F Microcontrollers
Using Timers in PIC18F Microcontrollers
 
Programming the Digital I/O Interface of a PIC microcontroller
Programming the Digital I/O Interface of a PIC microcontrollerProgramming the Digital I/O Interface of a PIC microcontroller
Programming the Digital I/O Interface of a PIC microcontroller
 
Introduction to microcontrollers
Introduction to microcontrollersIntroduction to microcontrollers
Introduction to microcontrollers
 
Integrating Cloud Services in Behaviour Programming for Autonomous Robots
Integrating Cloud Services in Behaviour  Programming for Autonomous RobotsIntegrating Cloud Services in Behaviour  Programming for Autonomous Robots
Integrating Cloud Services in Behaviour Programming for Autonomous Robots
 
Reactive Autonomous System Programming using the PROFETA tool
Reactive Autonomous System Programming using the PROFETA toolReactive Autonomous System Programming using the PROFETA tool
Reactive Autonomous System Programming using the PROFETA tool
 

Recently uploaded

KIT-601 Lecture Notes-UNIT-5.pdf Frame Works and Visualization
KIT-601 Lecture Notes-UNIT-5.pdf Frame Works and VisualizationKIT-601 Lecture Notes-UNIT-5.pdf Frame Works and Visualization
KIT-601 Lecture Notes-UNIT-5.pdf Frame Works and VisualizationDr. Radhey Shyam
 
retail automation billing system ppt.pptx
retail automation billing system ppt.pptxretail automation billing system ppt.pptx
retail automation billing system ppt.pptxfaamieahmd
 
NO1 Pandit Amil Baba In Bahawalpur, Sargodha, Sialkot, Sheikhupura, Rahim Yar...
NO1 Pandit Amil Baba In Bahawalpur, Sargodha, Sialkot, Sheikhupura, Rahim Yar...NO1 Pandit Amil Baba In Bahawalpur, Sargodha, Sialkot, Sheikhupura, Rahim Yar...
NO1 Pandit Amil Baba In Bahawalpur, Sargodha, Sialkot, Sheikhupura, Rahim Yar...Amil baba
 
Fruit shop management system project report.pdf
Fruit shop management system project report.pdfFruit shop management system project report.pdf
Fruit shop management system project report.pdfKamal Acharya
 
Electrostatic field in a coaxial transmission line
Electrostatic field in a coaxial transmission lineElectrostatic field in a coaxial transmission line
Electrostatic field in a coaxial transmission lineJulioCesarSalazarHer1
 
Courier management system project report.pdf
Courier management system project report.pdfCourier management system project report.pdf
Courier management system project report.pdfKamal Acharya
 
İTÜ CAD and Reverse Engineering Workshop
İTÜ CAD and Reverse Engineering WorkshopİTÜ CAD and Reverse Engineering Workshop
İTÜ CAD and Reverse Engineering WorkshopEmre Günaydın
 
Natalia Rutkowska - BIM School Course in Kraków
Natalia Rutkowska - BIM School Course in KrakówNatalia Rutkowska - BIM School Course in Kraków
Natalia Rutkowska - BIM School Course in Krakówbim.edu.pl
 
ONLINE CAR SERVICING SYSTEM PROJECT REPORT.pdf
ONLINE CAR SERVICING SYSTEM PROJECT REPORT.pdfONLINE CAR SERVICING SYSTEM PROJECT REPORT.pdf
ONLINE CAR SERVICING SYSTEM PROJECT REPORT.pdfKamal Acharya
 
Event Management System Vb Net Project Report.pdf
Event Management System Vb Net  Project Report.pdfEvent Management System Vb Net  Project Report.pdf
Event Management System Vb Net Project Report.pdfKamal Acharya
 
RS Khurmi Machine Design Clutch and Brake Exercise Numerical Solutions
RS Khurmi Machine Design Clutch and Brake Exercise Numerical SolutionsRS Khurmi Machine Design Clutch and Brake Exercise Numerical Solutions
RS Khurmi Machine Design Clutch and Brake Exercise Numerical SolutionsAtif Razi
 
Digital Signal Processing Lecture notes n.pdf
Digital Signal Processing Lecture notes n.pdfDigital Signal Processing Lecture notes n.pdf
Digital Signal Processing Lecture notes n.pdfAbrahamGadissa
 
KIT-601 Lecture Notes-UNIT-4.pdf Frequent Itemsets and Clustering
KIT-601 Lecture Notes-UNIT-4.pdf Frequent Itemsets and ClusteringKIT-601 Lecture Notes-UNIT-4.pdf Frequent Itemsets and Clustering
KIT-601 Lecture Notes-UNIT-4.pdf Frequent Itemsets and ClusteringDr. Radhey Shyam
 
Construction method of steel structure space frame .pptx
Construction method of steel structure space frame .pptxConstruction method of steel structure space frame .pptx
Construction method of steel structure space frame .pptxwendy cai
 
Cloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptx
Cloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptxCloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptx
Cloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptxMd. Shahidul Islam Prodhan
 
Democratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek AryaDemocratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek Aryaabh.arya
 
Introduction to Casting Processes in Manufacturing
Introduction to Casting Processes in ManufacturingIntroduction to Casting Processes in Manufacturing
Introduction to Casting Processes in Manufacturingssuser0811ec
 
Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.PrashantGoswami42
 
AI for workflow automation Use cases applications benefits and development.pdf
AI for workflow automation Use cases applications benefits and development.pdfAI for workflow automation Use cases applications benefits and development.pdf
AI for workflow automation Use cases applications benefits and development.pdfmahaffeycheryld
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdfAhmedHussein950959
 

Recently uploaded (20)

KIT-601 Lecture Notes-UNIT-5.pdf Frame Works and Visualization
KIT-601 Lecture Notes-UNIT-5.pdf Frame Works and VisualizationKIT-601 Lecture Notes-UNIT-5.pdf Frame Works and Visualization
KIT-601 Lecture Notes-UNIT-5.pdf Frame Works and Visualization
 
retail automation billing system ppt.pptx
retail automation billing system ppt.pptxretail automation billing system ppt.pptx
retail automation billing system ppt.pptx
 
NO1 Pandit Amil Baba In Bahawalpur, Sargodha, Sialkot, Sheikhupura, Rahim Yar...
NO1 Pandit Amil Baba In Bahawalpur, Sargodha, Sialkot, Sheikhupura, Rahim Yar...NO1 Pandit Amil Baba In Bahawalpur, Sargodha, Sialkot, Sheikhupura, Rahim Yar...
NO1 Pandit Amil Baba In Bahawalpur, Sargodha, Sialkot, Sheikhupura, Rahim Yar...
 
Fruit shop management system project report.pdf
Fruit shop management system project report.pdfFruit shop management system project report.pdf
Fruit shop management system project report.pdf
 
Electrostatic field in a coaxial transmission line
Electrostatic field in a coaxial transmission lineElectrostatic field in a coaxial transmission line
Electrostatic field in a coaxial transmission line
 
Courier management system project report.pdf
Courier management system project report.pdfCourier management system project report.pdf
Courier management system project report.pdf
 
İTÜ CAD and Reverse Engineering Workshop
İTÜ CAD and Reverse Engineering WorkshopİTÜ CAD and Reverse Engineering Workshop
İTÜ CAD and Reverse Engineering Workshop
 
Natalia Rutkowska - BIM School Course in Kraków
Natalia Rutkowska - BIM School Course in KrakówNatalia Rutkowska - BIM School Course in Kraków
Natalia Rutkowska - BIM School Course in Kraków
 
ONLINE CAR SERVICING SYSTEM PROJECT REPORT.pdf
ONLINE CAR SERVICING SYSTEM PROJECT REPORT.pdfONLINE CAR SERVICING SYSTEM PROJECT REPORT.pdf
ONLINE CAR SERVICING SYSTEM PROJECT REPORT.pdf
 
Event Management System Vb Net Project Report.pdf
Event Management System Vb Net  Project Report.pdfEvent Management System Vb Net  Project Report.pdf
Event Management System Vb Net Project Report.pdf
 
RS Khurmi Machine Design Clutch and Brake Exercise Numerical Solutions
RS Khurmi Machine Design Clutch and Brake Exercise Numerical SolutionsRS Khurmi Machine Design Clutch and Brake Exercise Numerical Solutions
RS Khurmi Machine Design Clutch and Brake Exercise Numerical Solutions
 
Digital Signal Processing Lecture notes n.pdf
Digital Signal Processing Lecture notes n.pdfDigital Signal Processing Lecture notes n.pdf
Digital Signal Processing Lecture notes n.pdf
 
KIT-601 Lecture Notes-UNIT-4.pdf Frequent Itemsets and Clustering
KIT-601 Lecture Notes-UNIT-4.pdf Frequent Itemsets and ClusteringKIT-601 Lecture Notes-UNIT-4.pdf Frequent Itemsets and Clustering
KIT-601 Lecture Notes-UNIT-4.pdf Frequent Itemsets and Clustering
 
Construction method of steel structure space frame .pptx
Construction method of steel structure space frame .pptxConstruction method of steel structure space frame .pptx
Construction method of steel structure space frame .pptx
 
Cloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptx
Cloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptxCloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptx
Cloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptx
 
Democratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek AryaDemocratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek Arya
 
Introduction to Casting Processes in Manufacturing
Introduction to Casting Processes in ManufacturingIntroduction to Casting Processes in Manufacturing
Introduction to Casting Processes in Manufacturing
 
Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.
 
AI for workflow automation Use cases applications benefits and development.pdf
AI for workflow automation Use cases applications benefits and development.pdfAI for workflow automation Use cases applications benefits and development.pdf
AI for workflow automation Use cases applications benefits and development.pdf
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
 

The I2C Interface

  • 1. The I2 C BUS Interface Corrado Santoro ARSLAB - Autonomous and Robotic Systems Laboratory Dipartimento di Matematica e Informatica - Universit`a di Catania, Italy santoro@dmi.unict.it L.A.P. 1 Course Corrado Santoro The I2C BUS Interface
  • 2. What is I2 C? I2 C Bus or IIC Bus is the acronym for Inter-Integrated Circuit Bus. It is a standard digital communication bus designed to interconnect integrated circuits belonging to the same board. It has been introduced by Philips to interconnect integrated circuits in TV-sets in the ’80s in the transition from discrete transistors to integrated-circuits. The bus has been initially used in TV-sets and VCRs, and then widely adopted in any integrated device which needs data communication. Corrado Santoro The I2C BUS Interface
  • 3. I2 C BUS: Phylisophy and Connections I2 C has a two wires bus which interconnect all devices Devices in a I2 C network has a role: Master, is the “head” of the bus and has the responsibility of starting a communication; only one master can be present in a I2C network and is - in general - a MCU; Slave, all the other devices which “respond” to master solicitations. Corrado Santoro The I2C BUS Interface
  • 4. I2 C BUS: Phylisophy and Connections The I2 C wires have the following meaning: SDA: Serial DAta, bidirectional; here data bits flow serially (one bit at time) SCL: Serial CLock, undirectional from master to slaves; it holds the timing of the transmission Therefore I2 C is a synchronous interface which (according to standards) can reach the max speed of 400 Kbps Corrado Santoro The I2C BUS Interface
  • 5. I2 C BUS: Electrical Consideration I2 C wires use a pull-up resistor, outputs of the devices are open-drain This is required to avoid electrical collisions: When output MOS are off, the line is at VCC through the pull-up resistor, so it is at logic 1 If one or more output MOS are on, the line is connected at ground (through the MOS), so it is at logic 0 Therefore ... Sending 0 implies to turn-on the output MOS Sending 1 implies to turn-off the output MOS Software handles 1 and 0, electrical translation is performed in hardware. Corrado Santoro The I2C BUS Interface
  • 6. I2 C Addressing Each slave device in I2 C has a well-know address The standard specifies two types of addresses: 7-bit, widely used 10-bit, used only in some special cases Each slave device has also a register map Each register is identified by a 8-bit address and a 8-bit value Each register is used to: Configure the device Send commands to the device Hold a sensed data etc. Each register can be read or written from the master through proper transaction protocols. Corrado Santoro The I2C BUS Interface
  • 7. I2 C: Timing and Bus States BUS IDLE, both SDA and SCL lines are in 1 state. START CONDITION (S) A transition high-to-low in SDA, while SCL is high, is a Start Condition It is used to start communication on the bus It is always initiated by the Master Corrado Santoro The I2C BUS Interface
  • 8. I2 C: Data Transfer Data transfer occurs serially MSB-first: 1 The bit value is set on the SDA line 2 A pulse low-to-high-to-low occurs on the SCL line 3 The next bit is sent ... After transmission of all the 8 bits, an acknowledge (ACK) is expected: 1 The master generates a 9th clock pulse 2 The receiving device holds the SDA line low to signal that it has understood the byte sent Corrado Santoro The I2C BUS Interface
  • 9. I2 C: Stop Condition When communication is over, a STOP CONDITION (P) is generated: A transition low-to-high in SDA, while SCL is high, is a start condition It is used to stop any communication on the bus It is always made by the Master After a Stop Condition, the bus goes in the Idle state. Corrado Santoro The I2C BUS Interface
  • 10. Sending Data to a Slave Device First the Master initiates communication with a Start Condition The Master sends the Write Command, a 8-bit data, composed of: The 7-bit address of the Slave device The R/W bit at 0, which means write-to-slave The addressed Slave acks, by holding SDA line low in the 9th clock pulse If no Slave exists at that address, the SDA line will remain to high, thus indicating a NACK; this situation is recognised by the Master which stops communication. Corrado Santoro The I2C BUS Interface
  • 11. Sending Data to a Slave Device After the address, the Master sends a 8-bit data which has the meaning of register number The addressed Slave acks data, by holding SDA line low in the 9th clock pulse Then the Master sends a 8-bit data which has the meaning of register value The addressed Slave acks data, by holding SDA line low in the 9th clock pulse The Master closes the transmission by sending a Stop Condition Corrado Santoro The I2C BUS Interface
  • 12. Receiving Data from a Slave Device First the Master initiates communication with a Start Condition The Master sends the Write Command, a 8-bit data, composed of: The 7-bit address of the Slave device The R/W bit at 0, which means write-to-slave The addressed Slave acks, by holding SDA line low in the 9th clock pulse Corrado Santoro The I2C BUS Interface
  • 13. Receiving Data from a Slave Device After the address, the Master sends a 8-bit data which has the meaning of register number The addressed Slave acks data, by holding SDA line low in the 9th clock pulse The Master sends a new Start Condition. The Master sends the Read Command, a 8-bit data, composed of: The 7-bit address of the Slave device The R/W bit at 1, which means read-from-slave The addressed Slave acks, by holding SDA line low in the 9th clock pulse Corrado Santoro The I2C BUS Interface
  • 14. Receiving Data from a Slave Device Slave device is now ready to send bytes The Slave sends a 8 bit data value The Master acks, by holding SDA line low in the 9th clock pulse The Slave sends the next 8 bit data value (next register value) The Master acks, by holding SDA line low in the 9th clock pulse When the Master is no more interested to data, it closes the communication by sending a NACK (holding SDA line high in the 9th clock pulse) and then a Stop Condition. Corrado Santoro The I2C BUS Interface
  • 15. I2 C and the PIC18F25K22 The PIC18F25K22 has a peripheral performing I2 C communication It is called MSSP, Master Synchronous Serial Port and handles: SPI communication I2C communication It can be programmed to work either in Master or Slave mode It has some configuration registers: SSPxCON1, sets-up the working mode of the peripheral, i.e. SPI/I2C, Master/Slave; SSPxCON2, in master mode, it generates events like Start Cond, Stop Cond, Ack, NAck; SSPxCON3, specifies the events which can trigger the interrupt; SSPxSTAT, indicates the occurrence of events (start, stop, data received, data sent, ack, etc.); Baud Rate Register, to set the communication speed (master mode); Data Register, holds the data read/to write. Corrado Santoro The I2C BUS Interface
  • 16. SSP Control Register ACKSTAT, acknowledge status bit ACKDT, acknowledge data bit ACKEN, sends the acknowledge data bit RCEN, enables the receiver PEN, initiates a stop condition RSEN, initiates a repeated start condition SEN, initiates a start condition The xxEN bits are automatically cleared by hardware when the operation is completed Corrado Santoro The I2C BUS Interface
  • 17. SSP Status Register D/A, indicates data or address P, indicates a detected stop condition S, indicates a detected start condition BF, indicates a buffer full condition During reception: 1 = reception complete During transmission: 1 = transmission in progress Corrado Santoro The I2C BUS Interface
  • 18. Writing a Register through I2 C ✞ int register_write(int dev_address, int reg_number, int reg_value) { SSP1CON2bits.SEN = 1; // send a START while (SSP1CON2bits.SEN == 1) {} // wait for completion PIR1bits.SSP1IF = 0; SSP1BUF = dev_address << 1; // shift left in order to include the ‘‘0’’ write bit while (PIR1bits.SSP1IF == 0) {} // wait for transmission and ack reception if (SSP1CON2bits.ACKSTAT == 1) { // a NACK is recevied, abort transmission SSP1CON2bits.PEN = 1; // send a STOP return 0; } PIR1bits.SSP1IF = 0; SSP1BUF = reg_number; while (PIR1bits.SSP1IF == 0) {} // wait for transmission and ack reception if (SSP1CON2bits.ACKSTAT == 1) { // a NACK is recevied, abort transmission SSP1CON2bits.PEN = 1; // send a STOP return 0; } PIR1bits.SSP1IF = 0; SSP1BUF = reg_value; while (PIR1bits.SSP1IF == 0) {} // wait for transmission and ack reception SSP1CON2bits.PEN = 1; // send a STOP while (SSP1CON2bits.PEN == 1) {} // wait for STOP completion return 1; } ✡✝ ✆ Corrado Santoro The I2C BUS Interface
  • 19. The I2 C BUS Interface Corrado Santoro ARSLAB - Autonomous and Robotic Systems Laboratory Dipartimento di Matematica e Informatica - Universit`a di Catania, Italy santoro@dmi.unict.it L.A.P. 1 Course Corrado Santoro The I2C BUS Interface