0:00
[MUSIC]
Now we're going to look
at a different library.
The I2C library, actually it's called the wire library.
But it supports what's called I2C communication.
So one of the things that you often want to do in a system when you have
a micro controller.
You want to connect it to another integrated circuit.
Some other chip, right.
Maybe it's a memory chip, maybe it's a digital analog converter,
whatever it is right?
You want to connect your micro controller to other chips.
So you can talk to those chips and tell them what to do,
grab data from them and so forth.
So these chips, when they communicate there are several different protocols.
Communication protocols which they can use.
The one we're gonna talk about right here is called I2C.
I2C communication protocol is a serial protocol and it's a synchronous protocol.
So serial means it sends data over only one wire.
Data is only traveling over one wire.
This is good, serial protocols are good because they save bits,
they save pins rather.
You don't need many pins, you just need the one or
in this case you need two total pins, but data is only going across one.
So you need very few pins.
The downside of that is that since it's serial it's sending one bit at a time.
So it takes longer, it's slower.
If you send eight bits in parallel that's a lot quicker than sending one at a time.
So, it's a serial protocol.
Which saves pins, which are important.
Also, it's a synchronous protocol.
What that means is that if there are two communicating entities,
two integrated circuits, talking about I2C, they need to share the same clock.
So they need to get the same clock.
1:37
They need to share it so they can synchronize with each other.
So, based on the clock,
the receiver knows when the sender's gonna be sending data, right?
So they need to share the same clock so they can be timed correctly.
So the receiver knows when to read the bus through, sender knows when to write.
1:58
And multiple masters and multiple slaves.
So we're gonna talk about this concept of master and slave.
But basically, the master is the one who starts all the communications and
the slave is the one who waits for communications, roughly.
And you can have multiple masters and
multiple slaves in this particular bus protocol.
2:14
Bitwidth is fixed.
So when I say bitwidth is fixed, the number of bits
Traveling between these two, between any number of devices on an I2C bus is fixed.
It's always two.
There is the data signal and the clock signal, just two.
2:28
And it's independent of the number of slaves.
There are other protocols where every slave you have to add more bits.
But I2C you can have as many slaves as you want, or
up to the limit that they enforce.
And you can, and it's the same number of bits, two bits.
So two wires SDA and SCL.
These are the common names.
SDA is the data, that's the line where the data's gonna travel.
And SCL's a clock that's used to synchronize all the devices.
3:06
And so what happens is they're pulled up high by default.
That means if let's say there are lots of different I2C
communicating entities on this bus.
They're wired to the SDA and SCL lines.
But nobody is talking on the bus.
So none of these components are driving those two wires high or low.
Because they're connected to power through a big resistor,
they will automatically go high.
They will be high.
Now, if any one of these communicating entities wanna force a zero into the line,
they can.
They can pull it down to a zero ,because it's a very big resistor.
So it's a, it's a weak pull up.
So you can pull it down, but if nobody's talking on the bus,
the state of the bus is still defined.
You always know that it's gonna be high by default.
And that's actually useful in the protocol to know,
that the state is always either zero or one.
It's not some random intermediate value.
3:57
So some of the terms we're gonna be talking about is Bus Protocol.
One is the master, master and slave.
So a master is a node on the bus that initiates and
terminates transmission, okay?
So when transmission starts the master starts it.
When it stops the master stops it.
Also it generates the clock SCL, so the clock is generated by the master.
4:20
Now the Slave is addressed by the Master.
So the Slave basically waits until the Master starts communication and
until the Master stops communication.
And does whatever the Master says.
So these transmissions are either write transmissions or read.
Sending to or from.
And the slave just essentially obeys the master.
If the master says I'm doing a write then the slave knows okay I better listen.
I better read.
I better read whatever's on the bus.
And so forth.
So there's master and there's slave.
4:48
Now, in addition to that, there's also transmitter and
receiver which are orthogonal to master and slave.
So the transmitter is whatever node is putting data onto the bus.
And the receiver is whatever date known as receiving data from the boss.
Now the master can be the transmitter,
it can be the master that starts transmissions and puts data on the bus.
Cuz they're doing a write.
They want to send data to the slave, but the master can be the receiver.
The master can start a transmission and
say, okay slave, this is a reinteract, a retransmission.
So it effectively orders the slave to give it information.
So the master can also be the receiver, and the slave can be the transmitter or
receiver also.
So every node is either a master or a slave, and can also be either
a receiver or a transmitter, and they can be mixed and matched.
So a master can be transmitter, receiver.
Slave can also be transmitter or receiver.
5:39
This is a picture of what the bus network will typically look like.
Each one of those blue blocks is labelled master, slave.
Think of that as probably an integrated circuit, or
some component that is talking on this bus.
And they're labelled master and slave to say what their roles are on the bus.
And there are a couple of masters and three slaves.
You can mix and match.
Each one of those connect to the same set of two lines SDA and SCL.
So SDA and SCL are common to all the masters and slaves,
all the nodes on the bus.
And they share it, and they're bidirectional.
So you can talk in two directions, you can talk,
data can go either way along those wires.
From left to right, right to left, whatever.
Also notice that the two lines SDA and SCL are wired to Vcc,
meaning power through big resistors.
Those resistors aren't labeled, but they are presumably big.
10k ohms or something like that.
So this is what the typical I2C network looks like.
We'll be talking about networks with just two nodes,
one master and one slave, but you can have much larger networks.
Like the one we're seeing here.
Thank you.
[MUSIC]