0:09
hello and welcome to controllers Tech
0:12
this is part two of the video covering
0:14
the U peripheral on the ESB 32 using the
0:17
ESB IDF in the previous video we saw how
0:21
to use the uart to communicate with the
0:24
computer we simply use the es32 to
0:27
transmit and receive the data from the
0:29
computer to using the uart in today's
0:32
video we will see how to make use of the
0:35
received data to perform some action on
0:38
MCU basically we will control a LED
0:41
connected to the es32 using the commands
0:44
sent by the computer via the art we will
0:47
continue where we left the previous
0:50
project let's open the expressive ID and
0:53
import the previous project to it browse
0:57
the project folder and click finish
1:02
here the project has been loaded into
1:04
the ID let's build it once all right the
1:09
successfully let's rename the project to
1:14
two we need to build it one more time
1:17
now in the last project we created two
1:21
tasks the TX task was responsible for
1:24
sending the data every 1 second while
1:26
the RX task was looking for the data
1:30
now let's assume that I don't want the
1:32
TX task to send the data
1:35
periodically instead it should only send
1:37
data when a particular condition is met
1:40
in this case that condition is if the
1:43
MCU receives some data from the computer
1:47
I will show this in detail let's change
1:50
the buffer size to 100
1:53
bytes here I am changing the data string
1:55
to be sent by the TX task basically we
1:59
will send back the data received by the
2:01
MCU from the computer along with some
2:05
modification the RX data is a local
2:07
array so we will have to Define it
2:12
globally after the modified data has
2:15
been stored in the data buffer the uart
2:17
WR bytes function will transmit the data
2:20
now instead of giving a delay here we
2:23
will suspend the task itself the task
2:26
suspend can be used to suspend any task
2:29
and pass the null parameter suspends the
2:31
task from which this function is being
2:33
called let's delete this num variable as
2:36
we don't need it the task suspension and
2:40
resume is not enabled by default so you
2:43
need to enable it in the free RT OS
2:46
header file hold the control button and
2:49
click on the free RT header file now
2:53
scroll down to include vask suspend and
2:56
set T to one now save the file and close
3:00
it so this TX task will send the data
3:03
once and then it will be suspended until
3:06
it is resumed again we will resume the
3:09
suspended TX task in the RX task we have
3:13
defined the RX data as a global array so
3:16
let's delete this array allocation here
3:19
also change the data buffer to RX data
3:22
buffer we want the TX task to transmit
3:25
data only if the RX task has received
3:28
some data so we will resume the TX task
3:32
only if the RX bytes is greater than
3:34
zero which means if there is some data
3:38
MCU the vtask resume function is used to
3:41
resume any suspended task the parameter
3:45
of this function is the task handle
3:48
which we want to resume the task handle
3:51
is allocated to a task when it is
3:53
created here you can see the last
3:56
parameter of the X task created is the
3:58
pointer to the task handle but by
4:00
default a null is being passed here in
4:03
order to set a specific task handle for
4:05
the TX task we will first Define a task
4:08
handle globally and then pass the
4:11
address of the task handle as the last
4:13
parameter of the X task create function
4:16
this will assign the TX task handle as
4:18
the official task handle of the TX task
4:22
now we can use this task handle to
4:24
control the TX task anywhere in the
4:26
entire code so to resume the TX X task
4:30
we will pass the TX task handle as the
4:32
function parameter so if the RX task
4:36
receives some data from the uart it will
4:39
resume the TX task the TX task will
4:42
modify the received data and send it
4:44
back to the uart after sending the data
4:48
it will go back to suspension and wait
4:50
for the RX task to resume it again we
4:53
have an error in the RX data definition
4:57
let's pass the number directly here all
5:00
right there is another error in the S
5:02
print F function let me set this to 150
5:06
as the RX data itself is 129 bytes in
5:10
size the error is due to this quotation
5:14
mark let's change this to a single
5:17
quotation all right the code builds fine
5:20
now let's flash it to the
5:24
board let's open the terminal so that we
5:27
can see the received data
5:30
I am using another serial terminal on
5:32
the computer and the configuration is
5:34
the same as what we used in the previous
5:37
project let's send the string hello you
5:41
can see the ID terminal shows the data
5:43
it has received and we also got the
5:45
modified data on the serial monitor so
5:49
everything is working fine the TX task
5:52
only sends the data when the RX data
5:55
receives something from the computer
5:58
just like this you can set some other
6:01
condition in the code which will resume
6:03
the TX task there is still one issue
6:06
with the current setup though if we
6:09
reset the MCU the TX task will still run
6:12
once and we will receive something in
6:14
the output this is because when the TX
6:17
task is created it will run once before
6:20
going into suspension we can still
6:23
prevent it by defining this RX bytes as
6:25
a global variable and then writing an if
6:28
condition inside the TX task or create a
6:31
new TX task inside the RX task and then
6:34
terminate the task again after it runs
6:37
once there are a lot of possibilities
6:40
and I will leave it up to you now we
6:43
will control a LED using the command
6:45
received from the computer I am not
6:48
going to use the onboard LED as it is
6:51
connected to the same pin which is used
6:53
by the U zero instead I have connected
6:56
an external led to the board here is how
7:00
the final connection looks like the uart
7:03
connection has already been explained in
7:05
the previous video so I will skip that I
7:09
have connected the LED to pin 13 of the
7:11
sb32 dev board the positive pin of the
7:15
LED is connected to this pin 13 while
7:18
the negative pin is connected to the
7:20
ground there is also a 100 ohms resistor
7:23
connected between the ground and the LED
7:26
to reduce the voltage supplied to the
7:28
LED let's define the LED pin in as
7:33
gp13 now write a new function to
7:37
LED inside this function we will first
7:40
reset the LED pin and then set the gpio
7:45
direction for the LED pin's output
7:48
inside the main function call this led
7:50
configuration function we just defined
7:54
the LED will be controlled based on the
7:56
commands sent by the computer via the
8:00
so we will write our rest of the code
8:02
inside the RX task Define a variable to
8:05
keep track of the LED state if the MCU
8:09
has received some data the RX bytes will
8:12
be greater than zero inside this
8:15
condition we will compare the received
8:18
data with the string on if the received
8:21
data matches with the string the string
8:23
compare function will return zero and we
8:26
will set the LED State variable to one
8:30
we will perform a similar check with
8:31
another string off and if it matches we
8:34
will reset the LED state to zero note
8:38
that both the strings are in uppercase
8:40
so if the computer sends the command in
8:43
lowercase it won't be accepted Now call
8:46
the function LED set level and pass the
8:49
LED State variable to it that is all we
8:53
need let's build and Flash the project
8:57
board I will start by by sending hello
9:01
you can see the modified data is
9:03
transmitted back to the serial monitor
9:06
also the LED is still off now I am
9:10
sending the command on the LED is now
9:13
turned on and sending the command off
9:16
turns off the LED if I send the command
9:20
in lowercase there is no change in LED
9:30
even if you type an extra space after
9:32
the command the LED will not respond it
9:36
needs to be exactly the same as what we
9:38
defined in the string compare function
9:41
so the LED is responding well and we can
9:44
control it using the commands sent from
9:46
the computer you can use such commands
9:49
from the computer to control different
9:52
MCU this is it for the video we will
9:56
cover more art related topics in future
9:58
videos which includes art interrupts
10:01
events Etc but for now I will move to
10:05
some other peripheral in the next video
10:08
I want to First cover the basic
10:10
functioning of the widely used
10:11
peripherals and once they all are
10:13
covered we will see their complex
10:15
functions one by one so in the next
10:18
video we will look into the i2c
10:25
today you can download the project from
10:28
the link in the descript
10:29
description leave comments in case of
10:32
any doubt or if you have any
10:35
suggestions keep watching and have a