0% found this document useful (0 votes)
49 views26 pages

Communication

The document discusses the communication interface in embedded systems, detailing both onboard and external communication interfaces. It explains the I2C protocol, including its modes of operation, data transfer process, and configuration steps for I2C pins. The document also provides specific programming instructions for enabling and configuring I2C communication on microcontrollers.

Uploaded by

sourav paul
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)
49 views26 pages

Communication

The document discusses the communication interface in embedded systems, detailing both onboard and external communication interfaces. It explains the I2C protocol, including its modes of operation, data transfer process, and configuration steps for I2C pins. The document also provides specific programming instructions for enabling and configuring I2C communication on microcontrollers.

Uploaded by

sourav paul
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/ 26

COMMUNICATION INTERFACE

Communication Interface:

• Communication interface is essential for communicating with various


subsystems of the embedded system and with the external world

• The communication interface can be viewed in two different perspectives;


namely;

1. Device/board level communication interface (Onboard Communication


Interface)
2. Product level communication interface (External Communication Interface)
1. Device/board level communication interface (Onboard Communication Interface):
On board communication interface refers to different communicating channels
for interconnecting various integrated circuits and other peripherals within the
embedded system
 Examples: Serial interfaces like I2C, SPI, UART, 1-Wire etc and Parallel bus interface

2. Product level communication interface (External Communication Interface): The


“Product level communication interface” (External Communication Interface) is
responsible for data transfer between the embedded system and other devices or
modules. The external communication interface can be either wired media or wireless
media and it can be a serial or parallel interface.
 Examples for wireless communication interface: Infrared (IR), Bluetooth (BT),
Wireless LAN (Wi-Fi), Radio Frequency waves (RF), GPRS etc.
 Examples for wired interfaces: RS-232C/RS-422/RS 485, USB, Ethernet (TCP-IP), IEEE
1394 port, Parallel port etc.
What is I2C (Inter Integrated Circuit)?
I2C is a serial data communication protocol used to communicate between Integrated Circuits(ICs). This
protocol was originally created by Philips Semiconductors (now NXP) back in 1982. It is a synchronous,
half-duplex, multi-master, multi-slave, packet-switched, single-ended, serial data communication
protocol.

I2C signals and Modes of operation


I2C is a 2-wire protocol and they are called SDA and SCL. Both SDA and SCL are bidirectional lines
connected to a positive voltage supply via pull-up resistors. Both the SDA and SCL lines are held high
when the bus is free.
The output stages of devices must have an open-drain or open-collector configuration. The bus
capacitance limits the number of interfaces connected to the bus.
I2C Operation Mode

There are four different I2C modes and they are Standard-mode, Fast-mode,
Fast-mode Plus, and High-speed mode. All the modes are downward-compatible
means any device may be operated at a lower bus speed but Ultra Fast-mode devices
are not compatible with previous versions because the bus is unidirectional.

Standard Mode (SM): Data rate up to 100 Kbits/sec,


Fast Mode (FM): Data rate up to 400 Kbits/sec
Fast mode plus (FM+): Data rate up to 1 Mbits/sec
High-Speed Mode (HS-Mode): Data rate up to 3.4 Mbits/sec
Understanding I2C protocol

• The transactions are initiated and completed by the Master.


• All messages have an Address Frame and a Data Frame
• Data is placed on the SDA line after SCL goes Low, and is sampled after the SCL line goes High

In I2C, data transfer is always initiated by the master on the SDA line. Master first produces a start
condition and after the start condition address phase follows. The address phase contains 8 bits, First 7
bits are the address of the slave, and the remaining bit decide the read or write operation.
If the Read/Write bit is 0 that indicates the master will write the data to the slave and if the bit is 1 that
indicates the master will read data from the slave.
After sending the addressed slave will compare the data with its own address. If the address match slave
will send an Acknowledge bit to the master and the master receive the Acknowledge bit.
Once the master receives the Acknowledge bit, master will start the read or write operation to the
slave according to the read/write bit sent by the master earlier in the address phase. If the slave
receives data it will send the Acknowledgement again or if the master receives the data then the
master will send the Acknowledgement.
If the master wants to send or receive more data, it can send or receive more data. If the master
wants to end communication, it will generate a stop bit to close the communication.
Once The Protocol Start and Stop Conditions

• All the transactions begin with Start and are terminated by Stop
• A High to Low transition on the SDA line while SCL is High defines a Start condition
• A Low to High transition on the SDA line while SCL is High defines a Stop condition
• Start and Stop conditions are always generated by the Master
• The bus is considered to be free again a certain time after the Stop condition.
• The bus stays busy if a repeated Start is generated instead of a Stop Condition
• Any information on the SDA line must be 8 Bits long
• The number of bytes that can be transmitted per transfer is unrestricted
• Each byte must be followed by an Acknowledge (ACK) bit
• Data is transferred with the most significant bit first.
• The Address Frame is first in any new communication sequence
• For a 7-bit address, the Address is sent out significant bit first, followed by a R/W bit indicating
whether this is a read (1) or write (0) operation
/**** STEPS FOLLOWED ************
1. Enable the I2C CLOCK and GPIO CLOCK
2. Configure the I2C PINs for ALternate Functions
a) Select Alternate Function in MODER Register
b) Select Open Drain Output
c) Select High SPEED for the PINs
d) Select Pull-up for both the Pins
e) Configure the Alternate Function in AFR Register
3. Reset the I2C
4. Program the peripheral input clock in I2C_CR2 Register in order to generate
correct timings
5. Configure the clock control registers
6. Configure the rise time register
7. Program the I2C_CR1 register to enable the peripheral
Configure the I2C PINs for Alternate Functions

1. Enable the I2C and GPIO CLOCKS


I2C CLOCK can be enabled in the RCC_APB1ENR Register

RCC->APB1ENR |= (1<<21); // enable I2C CLOCK


Similarly we will enable the GPIO clock also. I2C1 is connected to pins PB8 and PB9 and
therefore we will enable the GPIOB clock in RCC_AHB1ENR Register

RCC->AHB1ENR |= (1<<1); // Enable GPIOB


CLOCK
2. Configure the Pins for I2C
Select Alternate Function in MODER Register
The MODER Register can be used to configure the pins in different modes

GPIOB->MODER |= (2<<16) | (2<<18); // Bits (17:16) for Pin PB8; Bits (19:18) Alternate
Function for Pin PB9
Select Open Drain Output

The OTYPER Register can be used to select the output type

GPIOB->OTYPER |= (1<<8) | (1<<9); // Bit8=1, Bit9=1 output open drain


Select High SPEED for the PINs
The speed selection can be done using OSPEEDR Register

GPIOB->OSPEEDR |= (3<<16) | (3<<18);


Select Pull-up for both the Pins

GPIOB->PUPDR |= (1<<16) | (1<<18);


(Table 8. STM32F411xC/xE pin definitions)
Configure the Alternate Function in AFR Register
GPIOB->AFR[1] |= (4<<0) | (4<<4); // Bits (3:2:1:0) = 0:1:0:0 --> AF4 for pin PB8; Bits (7:6:5:4) = 0:1:0:0 --> AF4
for pin PB9
I2C Config

3. Reset the I2C

we need to modify the I2C Control Register 1 (I2C_CR1)

I2C1->CR1 |= (1<<15); // reset the I2C


I2C1->CR1 &= ~(1<<15); // Normal operation
4. Set the I2C clock
I2C1->CR2 |= 0x10; // PCLK1 FREQUENCY for 16 kHz
I2C1->CCR = 80
4. Enable the I2C

I2C1->CR1 |= (1<<0); // Enable I2C


Select Open Drain Output
The OTYPER Register can be used to select the output
type
To select the Pin as the output drain we need to write a ‘1’
in the 8th and 9th bits (PB8, PB9)

GPIOB->OTYPER |= (1<<8) | (1<<9); // Bit8=1, Bit9=1


output open drain

You might also like