0:09
hello and welcome to controllers Tech
0:12
this is the sixth video in the AVR
0:14
series with explained mini development
0:16
board from microchip and today we will
0:19
continue with where we left in the
0:21
previous one we will continue with the
0:24
i2c master series and connect and
0:27
control an actual slave device to the
0:30
bus I am going to use the pcf8574 as the
0:34
slave device which will receive the data
0:37
from the MCU and will control some LEDs
0:41
output let's check the data sheet of the
0:44
device this is basically a 8bit IO
0:47
expander for the i2c bus we will only
0:51
cover the important details in this data
0:53
sheet it supports the standard i2c
0:56
communication with 100 khz frequency
1:01
here is the block diagram of the device
1:04
it has the three input pins a0 to A2
1:08
which can be used to modify the address
1:11
device we have the clock and data pins
1:14
which will connect to the respective
1:17
MCU there are eight outputs available on
1:20
this device where we will connect the
1:22
LEDs to here is the address of the
1:26
device the 7bit slave address has the
1:29
four fixed bits and the bits a0 to A2
1:32
can be modified to modify the slave
1:35
address here you can see the seven bit
1:38
address for different
1:39
bits the PCF module has all three bits
1:43
connected to the vdd by default so the
1:46
default address is 27
1:48
hex here is the connection of the module
1:54
pcf8574 module is generally used to
1:57
connect to the LCD and therefore change
1:59
changes the pin requirement from 16 pins
2:03
pins as I mentioned the pins a 0 to A2
2:07
are connected to the vdd by default and
2:10
beside them is the connection to the
2:12
ground the address can be modified by
2:15
connecting the respective to the
2:17
ground here you can see the output pins
2:22
P2 we do not have access to the pin
2:26
P3 then we have the pins P4 to p7
2:31
I have connected the LEDs to all the
2:33
pins which then connects to a common
2:38
resistance the data and clock pins are
2:40
connected to the pin pa1 and pa2
2:45
respectively for the device to work
2:47
properly both the pins must be pulled up
2:49
to the VCC with 4.7 kiloohms
2:53
resistance the module is powered with 5
3:01
we will continue with the previous
3:04
project last time we commented out the
3:07
part where the master waits for the
3:08
acknowledgement from the slave
3:10
device since we have an actual slave
3:13
device this time let's include it
3:20
now also this statement was wrong as we
3:23
need to check for the RX acknowledgement
3:28
bit so the master sends the slave
3:31
address to the bus when the address
3:34
matches with a slave device it sends an
3:38
response on receiving the
3:40
acknowledgement the master continues to
3:43
send data once all the data is
3:46
transmitted the master sends the stock
3:49
condition and returns
3:50
zero if the slave does not acknowledge
3:53
the address the master sends the stock
3:56
condition and returns one let's write
3:58
the main file now we need to control the
4:02
LEDs connected to the pins shown in this
4:05
connection diagram to turn the LED on we
4:09
will simply write a one to the
4:10
respective pin let's define an array to
4:13
store the data for the
4:15
LEDs these btes will set the respective
4:18
pin high in the output of the slave
4:20
device we have the bite for the p 0 P1
4:24
P2 P4 P5 P6 and p7 the i2c is
4:31
initialized in the main function in the
4:34
while loop we will send one bite at a
4:36
time so let's send the data in the F
4:39
Loop the slave address is 27 hex and we
4:43
will send one bite of the array at a
4:45
time let's build the code
4:49
now there are no errors so let's put a
4:52
break point to this statement and debug
5:02
we have hit the brake point you can
5:05
check the LEDs connected to the module
5:08
right now all the LEDs are off let's run
5:11
the debugger now we hit the breake point
5:14
again and the first led is on now the
5:21
on all the LEDs are turning on one at a
5:30
let's remove the break point and let the
5:32
code run freely you can see the LEDs are
5:35
turning on after a delay of 1 second let
5:38
me change the delay to 100 milliseconds
5:49
code you can see the result of 100
5:52
milliseconds delay we will also see the
5:55
output on the logic analyzer so let me
5:58
change back the delay to 1 second and
6:15
again the data is being transmitted
6:17
every 1 second let's check one of these
6:27
frames here the master sends the St
6:30
condition and then the address 27 hex
6:32
with the right bit the slave
6:35
acknowledges the address and we can see
6:37
the AK response on the bus the master
6:41
then sends the data one hex and the
6:44
slave acknowledges the data received
6:47
then the master sends the stop condition
6:50
after one second the master again sends
6:52
the start followed by the slave address
6:55
and a new data to write so I i2c master
6:59
is working fine so far I will continue
7:02
with it and in the next video we will
7:05
see how to interface the LCD display via
7:08
i2c after that we will also write the
7:11
functions to receive the data from the
7:14
device this is it for this video I hope
7:17
you understood how to communicate to a
7:19
slave device using the
7:21
i2c you can download the code from the
7:24
link in the description leave comments
7:29
keep watching and have a nice day ahead