0% found this document useful (0 votes)
23 views13 pages

I2C Presentation

Uploaded by

snapper.games03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views13 pages

I2C Presentation

Uploaded by

snapper.games03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

I2C

The Inter-Integrated Circuit (I2C), (IIC) or (I2C) Protocol is a protocol


intended to allow multiple "peripheral" digital integrated circuits ("chips") to
communicate with one or more "controller" chips. Like the Serial Peripheral
Interface (SPI), it is only intended for short-distance communications within
a single device. Like Asynchronous Serial Interfaces (such as RS-232 or
UARTs), it only requires two signal wires to exchange information.

How It Works
Messages are broken up into two types of frames: an address frame,
where the controller indicates the peripheral to which the message is being
sent, and one or more data frames, which are 8-bit data messages passed
from the controller to the peripheral or vice versa. Data is placed on the
SDA line after SCL goes low, and is sampled after the SCL line goes high.

● Start Condition
To initiate the address frame, the controller device leaves SCL high
and pulls SDA low. This puts all peripheral devices on notice that a
transmission is about to start. If two controllers wish to take
ownership of the bus at one time, whichever device pulls SDA low
first wins the race and gains control of the bus. It is possible to issue
repeated starts, initiating a new communication sequence without
relinquishing control of the bus to other controllers; we'll talk about
that later.
● Address Frame
The address frame is always first in any new communication
sequence. For a 7-bit address, the address is clocked out most
significant bit (MSB) first, followed by an R/W bit indicating whether
this is a read (1) or write (0) operation.
The 9th bit of the frame is the NACK/ACK bit. This is the case for all
frames (data or address). Once the first 8 bits of the frame are sent,
the receiving device is given control over SDA. If the receiving device
does not pull the SDA line low before the 9th clock pulse, it can be
inferred that the receiving device either did not receive the data or did
not know how to parse the message. In that case, the exchange
halts, and it's up to the controller of the system to decide how to
proceed.
● Data Frames
After the address frame has been sent, data can begin being
transmitted. The controller will simply continue generating clock
pulses at a regular interval, and the data will be placed on SDA by
either the controller or the peripheral, depending on whether the R/W
bit indicates a read or write operation. The number of data frames is
arbitrary, and most peripheral devices will auto-increment the internal
register, meaning that subsequent reads or writes will come from the
next register in line.
● Stop condition
Once all the data frames have been sent, the controller will generate
a stop condition. Stop conditions are defined by a 0->1 (low to high)
transition on SDA after a 0->1 transition on SCL, with SCL remaining
high. During normal data writing operation, the value on SDA should
not change when SCL is high, to avoid false stop conditions.

I2C Module
The I2C module soldered on the back of the LCD is crucial for this
system, as it simplifies the wiring of the pins of the LCD. It converts serial
data from the Arduino, into parallel bits that can only be read by the LCD,
as it cannot read serial data.
Pins
● SDA - SDA (Serial Data) is the data signal where data is sent.
● SCL - SCL (Serial Clock) is the clock signal SCL is used to
synchronously clock data in or out of the target device.
● VCC and GND - are used to power the device.
Operation
An I²C-to-parallel converter like the PCF8574 works by receiving
serial data over the I²C bus, storing it in internal registers, and then setting
the states of its GPIO pins according to the received data. This allows a
microcontroller to control devices that require multiple parallel inputs using
a simple two-wire I²C interface, greatly reducing the number of GPIO pins
needed on the microcontroller.

How To Convert Serial Data Into Parallel


As shown before, the LCD has data pins from D0 to D7, representing
the 8-bit data bus width of the LCD. The PCF8574 is an I/O expander that
increases the I/O pins of the microcontroller, hence the SDA and SCK pins
of the I2C module.
The conversion is as follows:
1. I²C Communication:
The microcontroller initiates communication by sending a start
condition followed by the I²C address of the converter.
The microcontroller sends data bytes to the converter, which are
received serially over the SDA line, synchronized by the SCL line.
2. Data Reception and Storage:
The serial data received over I²C is temporarily stored in an internal
shift register.
Once a complete byte is received, it is transferred to the appropriate
internal data register.
3. Parallel Output Update:
The internal control logic takes the byte stored in the data register
and sets the corresponding GPIO pins to high or low states.
Each bit of the byte controls the state of one GPIO pin (e.g., the most
significant bit (MSB) controls GPIO7, the next bit controls GPIO6, and so
on, down to the least significant bit (LSB) controlling GPIO0).

Why Use I2C Instead of Other Protocols?


Choosing between I2C (Inter-Integrated Circuit), UART (Universal
Asynchronous Receiver-Transmitter), and SPI (Serial Peripheral Interface)
depends largely on the specific requirements of your application. Here are
some reasons why I2C might be preferred over UART and SPI in certain
scenarios:

1. Bus Capability: I2C supports a multi-master configuration, allowing


multiple devices (masters and slaves) to share the same bus. This can
simplify communication in systems where several devices need to
exchange data.
2. Number of Pins: I2C typically requires fewer pins compared to UART
and SPI. UART requires separate transmit (TX) and receive (RX) lines per
device, while SPI usually needs separate data in, data out, clock, and
possibly chip select lines. I2C uses just two wires (plus ground), making it
more suitable for applications where pin count or board space is limited.

3. Addressing: I2C uses a built-in addressing scheme, allowing multiple


devices to be connected to the same bus without additional chip select
lines. This simplifies the hardware design and reduces the number of
control lines needed on the microcontroller.

4. Speed: In some cases, I2C can operate at higher speeds than UART,
especially for shorter distances and when using devices that support higher
I2C clock frequencies. However, SPI generally offers higher maximum
speeds compared to both I2C and UART.

5. Complexity: I2C protocol is generally simpler to implement and


understand than SPI, which involves more intricate timing and signaling
requirements. UART is also straightforward but lacks some of the
addressing and multi-device capabilities of I2C.

However, there are also scenarios where UART or SPI might be preferred:

● Speed: SPI can achieve higher data rates than I2C, making it
suitable for applications that require fast data transfer because it uses
full-duplex transmission, while I2C only uses half-duplex, it does not
use addressing unlike I2C, can operate at higher frequencies, and it
is a simpler protocol to implement.

● Point-to-Point Communication: UART is well-suited for simple


point-to-point communication between two devices because there are
only two devices, the transmitter and the receiver. This makes it
simpler to use than I2C as it can be used with different Controllers
and Peripherals, making it hard to select the proper device using
addresses.

● Device Compatibility: Some devices (especially older ones) might


only support UART or SPI interfaces, limiting your choice.

Implementation of I2C
A 20x4 LCD is used with an I2C module to simplify connections to the
Arduino board. It is used as an output for the Electromyography (EMG)
Sensor that detects muscle contractions, sends it into the Arduino for
conversion, and sends it into the LCD to visually display the readings.
The EMG sensors, which are these pads, sense muscle contractions
through a piezo element, and convert it into voltage through the module.
There is an LED on the module to indicate the changes in contractions. The
OUTPUT pin of the module is connected to the A0 pin of the Arduino as it
outputs different voltage levels, unlike sensors that can sometimes only
output 5V or 0V, which are digital.
The Arduino then converts the corresponding voltages, into serial
data, to be sent to the LCD, which outputs the changes in the heart rate of
the person. The LCD can be also used to map if the value goes up, or
down or if there are no changes.
Code
The operation of the code is simple, but the construction is not.
We start by including the libraries for the LCD with an I2C module, then set
the A0 pin for the EMG sensor as INPUT.
Here, we can use to map where we will put the text on the display,
and state the corresponding symbols if there are changes in the heart rate.

You might also like