0:07
hello everyone welcome to controllers
0:11
tech today in this tutorial we are going
0:15
to see how to manage multiple you arts
0:18
using head and tail method both the you
0:21
arts would be able to receive and
0:23
transmit data of unknown length and
0:26
after this video you will be able to use
0:29
all those sensors that require serial
0:31
transmission to work the serial
0:34
communication based sensors for example
0:37
esp8266 GPS GSM etc need to have one
0:43
dedicated you are --court to communicate
0:45
with the center and another uart port
0:48
should be connected to the computer
0:50
that's why I am using to you arts in
0:52
this video let's start the cube ID and
0:56
create the stm32 project I am using f4
1:06
give some name to this project and click
1:34
Here I am enabling the external crystal
1:38
next I am selecting usart one you can
1:42
see the baud rate by default is 11 5 200
1:45
I am going to keep all settings as it is
1:48
and enable the interrupt for you Sark 1
1:51
along with that I am using usart 2 with
2:04
let's first take a look at the
2:08
you can see how the devices are
2:10
connected so the u r2 is connected to
2:13
the computer and UART one is connected
2:16
to the serial device I am using esp8266
2:20
for this purpose in both the connections
2:24
the TX pin of the controller must be
2:26
connected to the Rx of the device and rx
2:29
to TX of device let's go to the clock
2:34
HSE means I want to take clock from
2:37
external crystal which is of 8 megahertz
2:41
check the PLL clock and I am typing in
2:45
the maximum frequency possible and hit
2:48
enter now the setup is done so just
2:51
click Save and the project will be
3:03
this is our main dot C file now first of
3:11
all include the libraries for the UART
3:14
ring buffer multi you will get these
3:17
files in the source and the include
3:18
folders after you download the code
3:21
exactly where I am placing them let's
3:24
open the header file first here I have
3:28
written the description for all the
3:30
functions available here you can change
3:33
the default size of the buffer then we
3:42
have UART read UART write send string
3:45
functions same as the previous ring
3:48
buffer tutorial I did note that all
3:51
these functions now take UART as a
3:53
parameter this is to make sure that we
3:57
send the data to the respective UART
4:11
so we have all the previous functions
4:15
except this one get after this one here
4:19
saves the entered number of characters
4:21
into the provided buffer after some
4:24
particular string is matched I will show
4:27
you how to use it in a while let's see
4:30
what changes have I made in the UART
4:32
ring buffer dot C file
4:44
here you can define the names for the to
4:52
before proceeding any further let's copy
4:55
this in the interrupt file
5:25
so basically we are redirecting the
5:28
interrupt to use the code written by us
5:30
and not the default one let's go back to
5:33
the ring buffer dot C file
5:45
notice here that I have defined
5:48
everything twice for the two you arts I
6:04
let's see the UART read function the
6:08
parameter is the UART type if the UART
6:11
is the UART one which we have defined up
6:14
here in the beginning every operation
6:23
will be corresponding to the rx buffer
6:32
and in case the UART is UART to the
6:36
operations will be corresponding to the
6:38
rx buffer - same things for the UART
7:00
get position function gives the position
7:03
of the string and the incoming data and
7:05
the given UART I will show you how to
7:24
and we have all these regular functions
7:27
available let's go to the main dot C
7:30
file and start programming this
7:43
first of all include the header file for
7:46
the UART ring buffer I am defining some
7:54
new names to the you arts so it would be
7:56
easier to remember them as I mentioned
7:59
UART 2 is connected to the computer and
8:01
UART 1 is connected to the Wi-Fi that's
8:05
why I am naming them PC you are and
8:07
Wi-Fi UART inside the main function
8:15
first of all we need to initialize the
8:17
ring buffer and then in the wild loop I
8:24
am writing the condition that if the
8:26
data is sent from computer receive it
8:28
and then write to the Wi-Fi
8:43
and if it is sent from the Wi-Fi then
8:47
write it to the computer
9:00
this is pretty much for now let's build
9:04
this there are no errors in this let me
9:08
connect my controller before debugging
9:11
ok it's connected let's debug the code
9:17
select the stm32 application here
9:35
so the debugger is connected you can add
9:38
these buffers to the live expression I
9:45
will use real term for the serial
9:56
the controller is connected to the port
9:58
5 let's start the session I am sending
10:11
the 80 command and the response is as
10:18
expected you can check all these buffers
10:21
to verify data so basically the computer
10:24
sends the data which is received by
10:26
microcontroller which send it to the
10:29
Wi-Fi then Wi-Fi sends the response back
10:33
which is received by controller and then
10:35
sent to the computer again that is the
10:38
response that you see on the terminal I
10:40
am typing another command and you can
10:43
see the data sent by the Wi-Fi is being
10:45
displayed on the terminal
10:55
this is the reset command and that's the
10:59
response from the Wi-Fi I am NOT going
11:02
to show you how to interface the esp8266
11:05
in this video this is just to test if
11:09
the multiple you arts are working
11:11
alright or not so everything seems to be
11:15
working good till now now the important
11:18
part in all these situations either you
11:21
use the Wi-Fi GPS or GSM devices we need
11:26
some particular data from the incoming
11:28
stream and we don't know when that data
11:31
is going to show up for example suppose
11:35
I want to know the SDK version as shown
11:37
on the terminal here all I need to know
11:40
is that it is going to be after SDK
11:43
version and it's five characters in
11:45
length to get those values I am going to
11:49
use the get after function
12:10
first I am defining a buffer which can
12:13
hold those five characters as this data
12:19
is sent from the Wi-Fi I am writing this
12:21
inside the Wi-Fi part string is that
12:24
string that you want to wait up to there
12:33
are five characters I want to store them
12:36
in the buffer and they are being
12:38
received from the Wi-Fi you are this
12:41
must be put in the if loop once the
12:44
characters are received the function
12:46
will return one and we can proceed with
12:49
our code here I am writing the program
12:52
to send the string to the computer and
12:54
after that it will send the characters
12:57
that are stored in the buffer
13:06
let's build this and run
13:23
I am sending the reset command first and
13:26
as you can see nothing is being
13:28
displayed on the terminal this is
13:31
because the get after function is
13:33
working in the blocking mode and it is
13:35
waiting for the characters
13:36
I will try sending a T command and
13:39
nothing again although we don't see
13:42
anything printed here but the data is
13:44
still being saved in the rx buffer you
13:47
can see the response from the Wi-Fi for
13:50
the a T command now once I send the GMR
14:00
command you can see some data printed on
14:02
the terminal this is same what we would
14:05
expect the string in the stored
14:07
characters this number printed here is
14:10
the position of the string in the rx
14:12
buffer I was doing some debugging so I
14:15
guess I forgot to remove the function
14:27
let's test the function now
14:55
it's working good now I will try to look
14:59
for another string now
15:11
this time I will print the 80 version
15:18
the version number is of 8 characters so
15:27
I am changing number of characters to 8
15:29
also I am looking for a TV on in the
15:33
data and edit buffer so it can store at
15:36
least 8 characters as you can see it is
15:46
displaying the version number as we were
15:48
expecting it to display this is it for
15:52
I hope you understood it and you will
15:55
apply this in your projects I will just
16:01
add an example here so that you guys
16:04
remember about the usage this function
16:10
is very important in terms of using any
16:12
serial based sensor as the data length
16:15
is unknown and what we want can come at
16:30
you can get the header file in the C
16:32
file inside the source and include
16:34
folders after you download the code
16:36
leave any comments in case you have
16:39
doubts keep watching