0:10
hello and welcome to controllers tech
0:13
this is another video covering the f
0:15
deacon peripheral of the stm32 and today
0:19
we will use the normal mode
0:21
i have already made a video on the
0:23
loopback mode you can see it in the top
0:27
you must watch that video first as i am
0:30
not going to cover everything in this
0:32
video even the code is going to be the
0:34
same as the previous one
0:36
this video will only cover the normal
0:38
mode and the ram management in the fd
0:41
can as we talked about in the previous
0:45
i don't have two separate ft can devices
0:47
but my controller has two fd can
0:49
peripherals with two separate
0:51
transceivers so i am going to transfer
0:55
both the peripherals are using the
0:57
similar transceiver so we can use the
1:00
similar configuration in both
1:03
the connection is pretty simple
1:04
connecting the can high with can high
1:07
and can low with can low
1:09
you can see it in this picture the can
1:11
high and low pins for the fd can 1 and
1:16
here i have connected them to each other
1:21
let's start the cube id and create a new
1:31
give some name to the project and click
1:38
let me clear the pin out first
1:41
just like the previous video we will use
1:44
the internal clock in this one too
1:48
here you can see the internal clock of
1:53
go to the connectivity section and
1:55
enable the fd can one
2:02
let's fix the clock configuration first
2:09
here you can see the f d can clock is 50
2:11
megahertz this is the same as we had in
2:16
let's configure the f d can one
2:19
most of it will be similar to the
2:21
previous video so not much of the
2:23
explanation is needed for that part
2:26
we will not be using the bit rate
2:30
the mode will be the normal mode
2:33
auto transmission is enabled and the
2:38
now regarding these values as i have
2:40
already mentioned that we are using the
2:42
same configuration as the previous video
2:45
we can use the same values
2:48
so i am just going to input the same
2:50
values that i used in the previous
2:54
i already mentioned in the beginning
2:55
that i am not going to explain the
2:57
entire thing again so you should watch
3:00
the previous video for it
3:02
the link can be found in the description
3:06
yes we will talk about the message ram
3:08
here since i am using both the ft can
3:11
peripherals the ram needs to be divided
3:15
but since there is a lot to cover in
3:17
that perspective we will do it after
3:19
configuring the rest of the parameters
3:22
for now we will keep it zero
3:25
we will use 1 standard filter to filter
3:30
1 r x fifo zero element to store the 12
3:34
bytes of data which gets passed through
3:37
notice this carefully that i am using
3:40
the fifo zero for f d can one
3:43
we will skip the rest and use one t-x
3:45
fifoq element which will be used to
3:48
transmit 12 bytes of data to the can bus
3:51
the rest of the configuration will be
3:53
again similar to that of the previous
4:00
here you can see the bit rate of 500 000
4:04
we also need to make sure the pins have
4:07
been configured properly
4:09
here the pin pb9 is configured as the tx
4:12
pin but in the schematics it is pin ph
4:17
so i am changing it to p-h-13
4:24
at last enable the interrupt zero that's
4:28
it for the fd can one now we will
4:37
the pins configured for the fd can 2 are
4:40
also wrong so let's correct them
4:53
the rest of the configuration will be
4:55
the same as that of the fdcon1 since it
4:58
also uses the same clock we don't need
5:00
to modify anything much here
5:03
we will talk about that message ram in a
5:07
note here that i am not using the rx
5:12
we have already used the rx fifo zero
5:15
for the fd can one and it's not like if
5:17
we use it here it will not work
5:21
it will obviously work but in the
5:23
callback function we will have to use
5:25
more conditions to check if the received
5:27
data is coming from f d can 1 or can 2.
5:31
since we do have the option to use
5:33
another fifo we can use the fifo 1 for
5:38
and the rest of the configuration is now
5:40
similar to f d can 1.
5:46
enable the f d con 2 interrupt zero
5:49
alright the configuration is almost
5:51
complete so now we will talk about the
5:59
we will use the same reference document
6:04
that we used last time
6:07
so as i mentioned the fd can peripherals
6:10
share a common ram which is
6:12
2560 words in total which translates to
6:18
this ram accounts for the filters you
6:20
are using the tx and rx fifo and some
6:25
unlike regular can we can use multiple
6:28
filters and multiple fifo in the fd can
6:32
as you can see here we can use up to
6:35
128 elements of the standard filters
6:39
this in total would occupy
6:41
128 words from the ram
6:44
so this means one standard filter
6:49
similarly we can use up to 64 elements
6:52
of the extended filters which in total
6:58
so each extended filter occupies two
7:03
the fifo buffer have a little more
7:07
we can use up to 64 elements and the
7:10
total ram occupation can be 1152
7:14
words but it depends on other factors as
7:18
well for example how big is the data
7:21
as shown in this table if the data size
7:24
is up to 8 bytes each element would
7:29
and similarly if the data size is 64
7:31
bytes each element will occupy 18 words
7:36
so the maximum you can use is 64 bytes
7:38
data so maximum space by each element
7:41
would be 18 words and maximum number of
7:44
elements we can use is 64. this makes
7:46
the maximum occupancy of 1152
7:52
but remember here that we are using 12
7:54
bytes of data so each element is going
7:59
whatever space our configuration is
8:01
occupying we just have to keep adding it
8:05
the t x event fifo occupies two words
8:10
the t x fifo or t-x buffer uses the same
8:13
logic as the r-x buffers but here we can
8:15
use the maximum of 32 elements
8:19
and at last we have the trigger memory
8:21
which occupies 2 words per element
8:25
just to make it clear the elements are
8:27
basically how many numbers of things you
8:32
128 elements in the standard filter
8:37
128 different standard filters
8:40
the configuration of each filter gets
8:42
saved in each element
8:45
or 64 rx buffers means that we can use
8:48
64 different buffers with each buffer
8:51
capable of storing 64 bytes of data
8:54
which data or filter configuration will
8:57
be stored in which element is something
8:59
we configure later in the code
9:02
let's see this ram occupation as
9:04
according to our configuration
9:08
the f d can one offset is set to zero so
9:11
the ram occupation will begin at the
9:13
start of the message ram
9:16
here we have one standard filter so one
9:20
then we have one rx fifo element with 12
9:23
bytes of data so 5 words
9:26
next is one t-x fifo element with 12
9:29
bytes of data so another 5 words
9:33
that's it the total ram used by the fd
9:36
can one is eleven words
9:38
so for ft can two we can set the offset
9:44
fd can two will also occupy another
9:46
eleven words but that's not our worry as
9:49
the rest of the ram is allocated to it
9:52
since there are only two ft can
9:54
peripherals i could simply divide half
9:56
the ram to each peripheral setting an
10:03
but i wanted to explain this division
10:05
and this is why we will go with the
10:09
that is it for the configuration click
10:12
save to generate the project
10:17
let's build the code once
10:23
as i mentioned we will use the same code
10:25
that we created in the previous video
10:27
about the loopback mode here is the main
10:30
file from that project
10:32
we will start with the filter
10:34
configuration of the can peripherals
10:40
and we will paste it in the fdcon1 init
10:47
the id of the f p can 1 will be 11 hexa
10:50
and that of the f d can 2 will be 22
10:54
so the f d can one should filter the
10:56
messages coming from the 22 hexa the id
11:02
also note that it will filter the
11:03
messages to r-x-fifo zero
11:07
let's configure the filters for the
11:11
the f-d can 2 peripheral should filter
11:13
the messages coming from the 11 hexa the
11:16
id of the fd can one
11:19
also the f d can two should filter the
11:21
messages to r x fifo 1.
11:24
change this to f d can 2.
11:26
all right that completes the filter
11:35
let's copy this part now
11:40
here we have some definitions for
11:44
we will define them separately for both
11:50
so i am using the one to indicate the
11:52
defines for the fd can 1 and 2 for the
12:02
next comes the callback
12:04
this callback is basically called
12:06
whenever there is new data received in
12:11
we will write another callback for the
12:14
the changes will be that instead of fifo
12:17
zero it will be fifo 1.
12:20
basically it's a callback for the new
12:25
the same change needs to be made here
12:29
if the callback is triggered due to the
12:31
new message in rx501 we will first copy
12:35
the data from the rx-501
12:38
get rx message is the function for the
12:42
it will copy the data from rx fifo 1 and
12:45
save the header information in rx header
12:47
2 and data in rx data 2.
12:50
after copying the data we will activate
12:53
the notification again so that the
12:55
interrupt can trigger again when the new
12:59
i forgot to change them in ft can one
13:03
all right let's go inside the main
13:20
here we have the function to start the f
13:24
we will write a similar one for the f d
13:29
then this function activates the
13:30
notification for the new data in the rx
13:35
this is basically enabling the interrupt
13:37
for the new data which triggers our
13:41
we will do the similar activation for fd
13:43
can 2 for the new data arriving in the
13:48
next is the t x header configuration for
13:52
let me put one for the f t can one
13:55
so the id of the f d can one is eleven
13:59
we are using standard id only we will be
14:02
transmitting data frame
14:04
the data length is going to be 12 bytes
14:08
the error state indicator is enabled the
14:10
bit rate switching is off
14:13
we are using the fd can not the regular
14:17
and the tx fifo event and message
14:19
markers are disabled
14:22
we will use the similar configuration
14:24
for the tx header of the fd can 2.
14:27
just the id will be 22 hexa
14:30
the rest of the configuration will be
14:34
now finally the time to transmit the
14:44
add message to t x fifo q can be used to
14:47
add the message to the t x fifo which
14:49
will be then sent to the can bus
14:52
the message is the tx data buffer which
14:54
will be this string indicating that it
14:56
is transmitted by the fd can one along
14:59
with an incremented value of the index
15:03
so inside the while loop the fd can one
15:06
will keep transmitting this message
15:10
once the message is transmitted on the
15:12
can bus all the other devices will
15:14
receive this message though in this case
15:17
there is only one more device
15:19
the id of the transmitter is 11 hexa and
15:22
since we have programmed the filter of
15:24
the ft can two device to accept the
15:26
messages from this id the message will
15:28
filter through to the rx fifo 1.
15:31
on receiving a new message in the rx
15:34
5501 the callback will be triggered
15:37
here we will copy the information from
15:41
and store them in rx header 2 and rx
15:45
after enabling the notification again we
15:48
will transmit similar data to the can
15:52
accept this change to identify that it
15:54
is transmitted by the fd can 2.
15:58
once the data is transmitted on the can
16:00
bus the ft can one will receive this
16:02
data and here we will just store the
16:04
information in the rx data 1 and r x
16:09
again after 1 second the fd can one will
16:12
re-transmit modified data and ft can 2
16:15
will transmit another response
16:18
this cycle will keep going forever
16:21
let's build this code now
16:26
we have some warnings about the s printf
16:30
let me typecast this to a character
16:33
also include the header file for the s
16:40
all right everything is clear now let's
16:45
i have added the t-x headers and data's
16:49
since the transmission is done by the fd
16:52
can one let's put a break point inside
16:54
the callback of the ft can 2.
16:57
let's run the code now
17:00
we have hit the break point
17:04
you can see the data is stored in the
17:12
let's step over these functions
17:15
once the get r x message function is
17:18
called the same data is now stored in
17:20
the rx data 2 buffer
17:23
now here we are going to transmit some
17:25
data on the can bus and once the data is
17:28
received by the fd can one this callback
17:37
if you notice the tx data 2 here you can
17:40
see the new data with the new value of
17:50
here we have hit the break point
17:53
let's see if we get the same data in the
18:04
so we have received the data which was
18:06
transmitted by the t-x data 2.
18:09
let's remove the break points and let
18:12
freely we will only check the receive
18:17
keep an eye on the values of the index
18:23
as you can see the data transmission is
18:25
continuous and it is different in each
18:29
so we saw how to use the normal mode in
18:34
though i have used the same controller
18:36
you can use different devices too
18:39
the connection will be the same
18:41
connecting can high together and can
18:45
this is it for the video
18:47
i hope you understood the concept
18:50
you can download the code from the link
18:54
leave comments in case of any doubt
18:58
keep watching and have a nice day ahead