

Master-Slave Communication Protocol -> I2C - "Inter-Integrated Circuit&q...
source link: https://blog.knoldus.com/i2c-communication-protocol/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Master-Slave Communication Protocol -> I2C – “Inter-Integrated Circuit”
I2C Communication Protocol. So we have already read about Serial communication. Serial Communication is considered simple and better in comparison to other protocols like Bluetooth and USB. But it also has a downside in exchanging data like reading a digital sensor which requires another protocol to carry out this operation.
Don’t worry as we have plenty of protocols for a digital sensor.
Now as we already know that the board we have studied (STM 32 DISCOVERY BOARD) contains multiple sensors like an accelerometer, magnetometer, and gyroscope.
The accelerometer and magnetometer are packed in a single component which is accessible by an I2C bus.
What is I2C ??
I2C stands for Inter-Integrated Circuit which is used for exchanging data bit by bit along a single wire (the SDA line).
I2C works on the Synchronous Serial Communication protocol. What is this now ???
Synchronous Serial Communication
Synchronous Serial Communication describes a serial communication protocol in which data is sent in a continuous stream at a constant rate.
It requires that the clocks in the transmitting and receiving devices are synchronized – running at the same rate – so the receiver can sample the signal at the same time intervals used by the transmitter. No start or stop bits are required
This type of communication takes place in the I2C protocol which uses two-way or lines to exchange data.
- A data line (SDA)
- A clock line (SCL)
**Clock line is used to synchronize the communication.
How I2C Works?
With the I2C communication protocol, data is transfer in form of messages. Messages are broken up into frames of data. Each message has an address frame that contains the binary address of the slave, and one or more data frames that contain the data being transmitted. The message also includes start and stop conditions, read/write bits between each data frame:
Start Condition: The SDA line switches from a high voltage level to a low voltage level before the SCL line switches from high to low.
Stop Condition: The SDA line switches from a low voltage level to a high voltage level after the SCL line switches from low to high.
Let’s know more about it
Each slave has its own unique 7 to 10-bit address which the master uses to identify them. Whenever the master wants to send data it first generates a request which has the particular address of that slave. The slave whose address get match responds to the master.
**I2C communication protocol has the ability to support communication between several devices.
Every message initiates with a start condition and ends with a stop condition. A single message can hold multiple data bytes, each having an acknowledge (ACK) or negative acknowledge (NACK) bit in between them.
Once the communication gets starts between the master and the slave, the bus status is set to busy and no other device can use the bus until the data is exchanged or the communication stops by the master.
What does the clock line (SCL) do here ??
The clock line determines the rate at which the data get exchange between the device (master) and sensor (slave).
Let’s go through the Master-Slave communication process step by step
*Master -> Slave
When the master SENDS data to the slave.
- Master: Broadcast START
- Master: Broadcast slave address (7 bits) + the R/W (8th) bit set to WRITE
- Slave: Responds ACK (ACKnowledgement)
- Master: Send one byte
- Slave: Responds ACK
- Repeat steps 4 and 5 zero or more times
- Master: Broadcast STOP OR (broadcast RESTART and go back to (2))
**As we discussed before the address here can be 10 bits also.
The second operation can be when the Master wants to read the data from the slave.
*Master <- Slave
Here the only difference is the bit in the second step would be set to READ which tells that the master is in the reading mode now.
- Master: Broadcast START
- Master: Broadcast slave address (7 bits) + the R/W (8th) bit set to READ
- Slave: Responds ACK (ACKnowledgement)
- Master: Send one byte
- Slave: Responds ACK
- Repeat steps 4 and 5 zero or more times
- Master: Broadcast STOP OR (broadcast RESTART and go back to (2))
Use of I2C in DISCOVERY Board
Two sensors the magnetometer and accelerometer of the DISCOVERY BOARD are present in a component, the component is LSM303DLHC.
So, here onboard these two sensors behave like the slave of a master, to access these sensors we use the I2C protocol.
Whatever data they get from sensing the environment is stored in their own memory so our task is simple to just read that memory and get the result.
A point to note here is that their memory is modeled as byte-addressable registers but they are not mapped into the microcontroller’s memory.
Therefore I2C access their registers.
The difference between the SPI (Serial Peripheral Interface) and I2C (Inter-Integrated Circuit)
- I2C protocol can support multiple slave devices but unlike SPI, which only supports one master device, I2C can support multiple master devices as well
- Every device sends/receives data using only one wire which is SDA. SCL maintains sync between devices through a common clock which is provided by the active master
- I2C is slower than SPI
- In I2C communication we get the acknowledgment bit after each byte but not in SPI
- SPI Costly as compared to I2C
- I2C is the address base bus protocol, you have to send the address of the slave for the communication whereas, in SPI, you have to select the slave using the slave select pin for the communication
The last point will be, what are the advantages and disadvantages of using I2C over SPI
Advantages:
- Multiple masters and multiple slaves can be interfaced together.
- By using two wires only we can make the communication.
Disadvantages:
- It is slower as compared to SPI because this protocol does a lot of frameworks.
- It consumes more power than other serial communication busses due to open-drain topology.
If you want to see the practical example of this theory then you can click here.
If you want to read more content like this? Subscribe to Rust Times Newsletter and receive insights and latest updates, bi-weekly, straight into your inbox. Subscribe to Rust Times Newsletter: https://bit.ly/2Vdlld7.
Recommend
-
18
A few years ago, Karla Monterroso was at an airport when she noticed a glitch in a computer monitor that would normally display flight information. Instead, the screen showed the text “Master/Slave,” rep...
-
8
Why I am not using Masochism for my master-slave setups and why monkey-patching isn’t the only solution I got a message this morning from Gregg at Ruby5 asking why...
-
5
Inter-Process CommunicationIn many ways, the story of Apple has been about fusing together technologies through happy accidents of history to create something better than before: OS X as a hybrid of MacOS & NeXTSTEP. Objective-C as the co...
-
8
Examining JavaScript Inter-Process Communication in Firefox Frederik Braun Apri...
-
7
Set Up MySQL 8 Master-Slave Replication on Ubuntu 20.04 S...
-
9
redis master, slave, sentinel通信 发表于 2018-12-21...
-
11
MySQL 主从复制(Master-Slave) 发表于 ...
-
6
What is the Inter-Blockchain Communication Protocol (IBC)?NotificationsHappy Weekend, enjoy these top stories from this week, Deglorifying CEOs, Spawn of the Stars, and more 💚...
-
4
科技入侵,Slave or Master? (非HR技术宅慎入!) 2017-01-1137991 本文摘自北森市场副总裁高燕女士在人大人力资源沙...
-
10
How to Configure MariaDB Master-Slave Replication on AlmaLinuxLearn How to Configure MariaDB Master-Slave Replication on an AlmaLinux Platform
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK