0:09
hello and welcome to controllers Tech
0:12
this is the fourth video in the
0:15
stm32i2c slave series and we will again
0:18
continue to look at yet another method
0:20
of receiving the data
0:21
this is probably going to be the last
0:23
method we are covering just to receive
0:26
the data and so far it is the most
0:28
Dependable method for the same
0:31
since it is the continuation from the
0:33
previous video this is going to be a
0:35
very small video covering one specific
0:39
in this method the master will send the
0:41
data which consists of the information
0:43
about how many bytes it is going to send
0:48
so let's start where we left the
0:50
previous video that is part three
0:53
Define a variable to keep track of
0:56
whether the first byte has been received
0:59
inside the address callback function
1:02
let's put our code inside the condition
1:04
if the first byte hasn't been received
1:07
here we will receive the first byte of
1:10
data using the option of the first frame
1:13
this first byte is actually the number
1:15
of data bytes the master is going to
1:19
once the first byte is received the
1:22
receive complete callback is called
1:25
here again we will first check if the
1:27
variable is set to 1 or not
1:30
if not then set the variable to 1
1:33
indicating that we have received the
1:35
first byte of the data
1:37
increment the RX count variable so that
1:40
the data can be stored at the updated
1:42
location in the buffer
1:44
and finally receive the data at the
1:46
updated position in the RX buffer
1:49
the number of data bytes the slave will
1:52
receive is the same as the first byte
1:56
we will call the function with the
1:58
option of the last frame since we are
2:00
not receiving more data
2:02
once the final data byte is received the
2:05
Callback will be called again but this
2:07
time the variable is set to 1.
2:10
this means the reception is complete and
2:13
finally we can process the data
2:16
so update the RX count variable with the
2:19
total number of bytes received
2:22
reset the first byte received variable
2:24
so that the entire process can start
2:28
and finally call the process data
2:32
this idea is very simple let's assume
2:35
that the master wants to send 8 bytes of
2:38
so it can simply send the first bytes as
2:41
the number eight followed by the actual
2:45
thus it has to send a total of nine
2:49
we will see this in working now
2:52
let's build and debug the code
2:55
we will check the RX buffer in the
2:59
you can use the simple transmit function
3:02
for the master to send the data
3:05
let me put a breakpoint inside the
3:10
let's assume the master wants to send
3:12
two bytes of data so it has to send the
3:15
first byte as to informing the slave
3:17
about how many bytes of data it is
3:21
and then send the two data bytes
3:24
the actual data will start storing from
3:27
the second byte of the RX buffer
3:30
the RX count represents the total number
3:32
of bytes received by the slave
3:35
this includes the first information byte
3:39
also note that the error counter does
3:41
not increment in this case
3:44
actually if you send the data properly
3:46
informing how many bytes are coming next
3:49
the slave will never encounter any error
3:52
let's assume that you want to extract
3:55
the actual data from it
3:57
I am using the mem copy function to do
4:01
the actual data start from the offset of
4:03
1 and the total data bytes are equal to
4:06
the RX count minus 1.
4:09
this is because the RX count also
4:11
includes the information byte so we
4:13
remove it for the data bytes
4:16
let's try to send three data bytes
4:22
we have received the three main data
4:24
bytes along with an information byte
4:28
so our slave driver is working well so
4:31
keep in mind that the master should send
4:34
the number of data bytes as mentioned in
4:36
the information byte or else there might
4:39
that is it for the video
4:42
I hope you understood different ways in
4:44
which the slave can receive the data
4:47
you can use either of the methods we
4:49
cover depending on how much control you
4:53
in the next video we will Define some
4:56
memory for the slave and the master will
4:59
write the data to a specific memory
5:02
it is equivalent to the slave having the
5:04
registers to store some data and later
5:07
can be read by the master
5:12
leave comments in case of any doubt
5:15
the link to download the code is in the
5:19
keep watching and have a nice day ahead