0:12
welcome to another video of controllers
0:15
this is yet another video in the can
0:17
series and today we will see how to use
0:20
multiple devices in can
0:22
i thought i have explained the filter
0:24
configuration properly
0:25
but apparently some of you still have
0:27
problems with multiple ids
0:30
so in this video i will try to clarify
0:33
that issue using the three different can
0:37
i am not going to explain everything
0:39
here and for that you must watch the
0:41
previous videos about can
0:43
this one will typically focus on using
0:47
and that's it so before we jump into the
0:51
let me show you what i am trying to
0:54
here is the picture of the connection
0:57
you can see there are three modules
0:59
and they are connected to three
1:02
also note that there are 120 ohms
1:05
resistors connected at each node
1:07
just like it was in the previous video
1:10
let's assume that the nucleo is master
1:13
and the other two are slaves
1:15
the can protocol don't have master and
1:19
but for now we can treat the nuclear as
1:21
master as it is going to request the
1:23
data from the other two
1:26
the nucleo will request the data from
1:29
and after receiving the data it will
1:33
so it will be easier for us to see which
1:36
slave is sending the data
1:38
let's see the code now
1:46
this is the main file for nucleo our
1:54
here the initial defines are same as the
1:59
i have added these variables to check
2:01
which slave has sent the data
2:06
now in the pending callback first we
2:08
will receive the message from the fifo
2:14
then we will further check the id of the
2:18
these ids are allocated to the other
2:22
and you will see them in their main
2:25
based on which slave sent the data we
2:28
will set the respective flag
2:30
so this whole process is like an
2:34
on top of the hardware filters we
2:40
i will explain this fail-safe in a while
2:48
then we do our usual process we start
2:53
and configure the t-x header note here
2:57
is 4 as i am going to send 4 data bytes
3:02
and this is the id assigned to the
3:09
then we will load this particular string
3:17
now if you remember we set some flags in
3:21
callback basically if the data is
3:25
received from the f103
3:27
then this flag will set and if the data
3:30
is received from f750
3:32
then this one will set in the while loop
3:36
we will check if the either of these
3:40
if they are that means some data has
3:43
and we will send the data to the uart
3:51
and if the data was received from f 1 0
3:54
then we will request the next data from
4:01
this way the communication will be
4:03
continuous and we don't need to
4:12
now let's see the fail safe
4:18
i have defined a value for fail safe
4:24
and in the interrupt file it keep on
4:26
decreasing every 1 millisecond
4:49
if this value goes less than zero we
4:51
will transmit the data again
4:54
this is kind of precaution in case of
4:56
communication failure
5:01
also we need to keep updating this value
5:04
so that it doesn't reach zero
5:06
and we do that whenever we receive data
5:16
this is it for the master now let's see
5:19
the code for the f103
5:21
the first slave device
5:37
here also the things are same in the
5:40
in the callback function we will receive
5:43
the data from the fifo
5:45
as you know there are multiple devices
5:47
connected to the same can bus
5:49
so we want this slave to respond only
5:52
when the master requests the data from
5:55
to do that we need one additional filter
5:58
and here it is we will check the
6:01
received data from the master
6:04
if the data is f 1 0 3 we will set this
6:09
this will serve as a confirmation that
6:11
the data is requested from
6:26
now if the flag is set we will turn on
6:33
then send this data to the master
6:41
now remember one thing that all the
6:43
transactions are taking place on the
6:47
so which data will be received by which
6:51
this will be decided by the filter
6:59
here the filter is configured to pass
7:01
through the data from the f446
7:04
that is from the master only
7:07
so when the second slave send the data
7:10
our first slave which is f103
7:14
will not let the data in
7:25
all right now we have reached the second
7:28
slave everything is same here
7:31
except that the check will be performed
7:40
by the way this is the id for the second
7:45
i forgot to show it for the blue pill
7:51
i have chosen these ids for some
7:55
and you will see that in a while
8:03
and similar to the first slave if the
8:06
data is requested from this one
8:08
we will send some data to the master
8:19
note here the filter is also configured
8:21
to pass the message from the master only
8:24
okay so we saw the filter configurations
8:28
and now we will see for the master
8:42
the master is supposed to receive data
8:44
from the 2 different slaves
8:46
so let's see how the filter is
8:48
configured for the same
8:50
as you already know we have 2 important
8:54
id register and mask register
8:57
those are the ids of the f750
9:00
and f103 and we want the message from
9:04
both of them to pass through
9:07
to do so we can just check for the
9:09
common bits in both the ids
9:12
like both the ids have one at these
9:16
let's fill the zeros in the rest
9:33
now my mask register will be something
9:36
if you remember from the first tutorial
9:39
i have explained this
9:41
when the bit of the mask register is set
9:43
to 1 the id register will be compared
9:48
the mask register is 1 here so this bit
9:51
of the id register will be compared with
9:53
the bits of the incoming ids
9:56
again it is 1 here and that means this
9:58
bit will be compared with the incoming
10:02
it is zero here so this bit will not be
10:06
so wherever the mask register is set to
10:08
1 only those bits of the id register are
10:13
and if all the comparing bits match with
10:16
the message will pass through we can
10:19
make it easier for this particular case
10:21
and only compare these particular bits
10:30
so now only this bit and this bit
10:33
and this will be compared because the
10:36
mask register is only set at these
10:45
so basically these other bits of the id
10:47
registers are don't care bits now
10:50
they match or don't match it doesn't
10:54
since the mask bits are 0 there so they
10:56
are not compared anyway
10:59
so i will set 2 0 1 for the id and the
11:09
now everything has been explained so
11:12
let's see the working
11:29
here is the logic analyzer and this is
11:32
connected to one of the the receive line
11:38
i am also opening a serial port to see
11:40
the data sent by master
11:51
we are receiving some data
11:59
here you can see the transactions taking
12:02
x line and you can also see the data
12:05
from both the slaves
12:08
let's see what's happening on the rx
12:23
here you can see the id of the sender
12:26
and this is the data from the second
12:31
if we check the next transaction here
12:33
the data is sent by the master
12:42
notice that the data here is f 1 0
12:45
3. so the master received the data from
12:49
the second slave in the previous
12:51
and now it's requesting from first slave
12:59
the gap here is around 2.5 seconds
13:03
this means that there was some
13:06
and here the master sends the same data
13:24
this happened because of the failsafe
13:29
now the first slave sent the data
13:32
after receiving the data from the first
13:34
slave the master requests from the
13:42
and here is the data sent by the second
13:46
so this process will keep repeating
14:02
you see the transactions taking place on
14:06
and when there is a big gap that means
14:09
and the master requests the data again
14:20
here you can see the data is updating
14:28
so this is it for this video i hope you
14:31
understood how to use multiple devices
14:34
especially the part where we configured
14:38
i haven't explained every other thing
14:40
since they were already covered in the
14:44
so if you didn't understood anything
14:46
watch the first two videos in the can
14:50
this is it for today you can download
14:53
the files from the link in the
14:56
keep watching be safe and have a nice